How JustAnswer Works:

  • Ask an Expert
    Experts are full of valuable knowledge and are ready to help with any question. Credentials confirmed by a Fortune 500 verification firm.
  • Get a Professional Answer
    Via email, text message, or notification as you wait on our site.
    Ask follow up questions if you need to.
  • 100% Satisfaction Guarantee
    Rate the answer you receive.

Ask Partha Your Own Question

Partha
Partha, Software Engineer
Category: Programming
Satisfied Customers: 14
Experience:  Masters degree with Web/Java programming experience.
13376922
Type Your Programming Question Here...
Partha is online now
A new question is answered every 9 seconds

Write a Java program that will read integers and find the total

Resolved Question:

Write a Java program that will read integers and find the total and average of the input values, not counting zeros.



Your program must end with the input zero.

Display the average as a floating point number.

The program must also find the largest and smallest value. It also must find the count of how many entries were entered by the user not including the zero to exit the programs.



If input is 50, 55, 60, 0, your output should be:


the total is 165

the average is 55.0

the largest value is 60

the smallest value is 50

the number of entries is 3


Important Notes:The input and output must use JOptionPane dialog and display boxes.
Submitted: 5 years ago.
Category: Programming
Expert:  ehabtutor replied 5 years ago.
The input and output must use JOptionPane dialog and display boxes. Do you have a sample program that uses the JOptionPane?
Customer: replied 5 years ago.

yes, here is a completed program, that I'm also working on.

 

import javax.swing.*;

public class CountEven {

/* This program reads a positive integer from the user.
It checks if the number is XXXXX or true also checks the number the user entered
is between 1 and 1000
*/

public static void main(String[] args) {

String ans;

//user enters number
ans = JOptionPane.showInputDialog(null, "Enter a number");
int input= Integer.parseInt(ans);
input = input % 2;
String answer = "False";
if(input == 0){
answer = "True";
}//end if
JOptionPane.showMessageDialog(null, answer);
String ans2;
ans2 = JOptionPane.showInputDialog(null, "Is This Number Between 1 and 1000?");
int num= Integer.parseInt(ans);
num = num % 2;
if(num == 0);
if(num <1000);
String Ans2 = "true";
if(num >1001);
ans2 = "False";
{
}//end if
JOptionPane.showMessageDialog(null, answer);
} // end main()

} // end class CountDivisors

Customer: replied 5 years ago.
Still waiting for response, please reply any progress
Expert:  Partha replied 5 years ago.
Is any one working on solution for this question or do you want to get answer?
Customer: replied 5 years ago.
no one , and yes I would like an answer
Customer: replied 5 years ago.
no one , and yes I would like an answer
Expert:  Partha replied 5 years ago.
import javax.swing.JOptionPane;


public class CountNumbers {

public static void main(String[] args) {

String ans;
int total=0,small=0,large=0;
int numEntries=0;
float average=0.0f;

// user enters number
String message="";
do{
ans = JOptionPane.showInputDialog(null, "Enter a number between 1 and 1000");
if(ans==null || ans.trim().equals("")){
continue;
}
if("0".equals(ans)){
break;
}
int input = Integer.parseInt(ans);
if(input>=1 && input <=1000){
total = total + input;
if(input<small || numEntries==0){
small=input;
}
if(input>large || numEntries==0){
large=input;
}
numEntries++;
average = total/numEntries;
}else{
message = "Enter number between 1 and 1000 only";
JOptionPane.showMessageDialog(null, message);
}
}while(true);
message = "The total is " + total + "\n";
message = message + "The average is " + average + "\n";
message = message + "The largest value is " + large + "\n";
message = message + "The smallest value is " + small + "\n";
message = message + "The number of entries is " + numEntries;

JOptionPane.showMessageDialog(null, message);
} // end main()
}
Partha, Software Engineer
Category: Programming
Satisfied Customers: 14
Experience: Masters degree with Web/Java programming experience.
Partha and 7 other Programming Specialists are ready to help you
Customer: replied 5 years ago.
I've compile and tested first option window in loop will not continue to next option, used jGRASP to test
Expert:  Partha replied 5 years ago.
1) Do you want the result at the end or for each entry?
2) What do you expect in the next entry?
Customer: replied 5 years ago.

recompiled recieved correct response,

 

 

thanks, XXXXX XXXXX

Expert:  Partha replied 5 years ago.
Status is saying "Waiting for Expert".
But it seems that you accpeted the solution?
Do I need to do anything else for you regarding this question?
Expert:  Partha replied 5 years ago.
Can you provide bonus too. It posted me only 20 dollars.
Partha, Software Engineer
Category: Programming
Satisfied Customers: 14
Experience: Masters degree with Web/Java programming experience.
Partha and 7 other Programming Specialists are ready to help you
Customer: replied 5 years ago.

included $20 bonus, it should have posted $40 ,but I added bonus anyway

Customer: replied 5 years ago.

My account shows 2 accepts for the one question plus the $20 bonus I have one problem I can used help on

 

 

Write a Java program that meets the following requirements:

Declare a method to determine whether an integer is a prime number

Use the following method declarations:
public static Boolean isPrime (int num)


An integer greater than 1 is a prime number if its only divisor is 1 or itself. For example, isPrime (11) returns true, and isPrime (9) returns false.

Us the isPrime method to find the first thousand prime numbers and display every ten prime numbers in a row, as follows:

2 3 5 7 11 13 17 19 23 29
31 37 41 43 47 53 59 61 67 61
73 79 83 89 97 ...
...

Important Notes:
The input and output must use JOptionPane dialog and display boxes.

 

Expert:  Partha replied 5 years ago.
Did you spent 60 dollars or 40 dollars ?
Any how, answer for Prime numbers

import javax.swing.JOptionPane;


public class PrimeNumber {
public static void main(String[] args) {

String numStr;

do{
numStr = JOptionPane.showInputDialog(null, "Enter a number between 1 and 1000");
if(numStr==null || numStr.trim().equals("")){
continue;
}
if("0".equals(numStr)){
break;
}
int input = Integer.parseInt(numStr);
if(input>0){
if(isPrime(input)){
JOptionPane.showMessageDialog(null, input + " is prime");
}else{
JOptionPane.showMessageDialog(null, input + " is not a prime");
}
}else{
JOptionPane.showMessageDialog(null, "Enter number >0");
}
}while(true);
} // end main()
public static boolean isPrime ( int num )
{
boolean prime = true;
int limit = (int) Math.sqrt ( num );

for ( int i = 2; i <= limit; i++ )
{
if ( num % i == 0 )
{
prime = false;
break;
}
}

return prime;
}

}

Customer: replied 5 years ago.

the bill shows two accepts for $40 and the $20 bonus, thanks for help

Expert:  Partha replied 5 years ago.
I think you would have been billed for 40 dollars only but with two accepts
Customer: replied 5 years ago.
Accept Date Paid To Amount BonusQuestion
January 27 2009 at 4:54pm sarthy2008 $40 $20 Write a Java program that will read integers and find the total
January 27 2009 at 4:46pm sarthy2008 $40 $0 Write a Java program that will read integers and find the total
Accept Rate:2 Accepts/1 Questions
Amount Available to Spend:$0
This copy of my report -
Expert:  Partha replied 5 years ago.
I guess the reason is you should give bonus at the first time itself I think.
Since you went second time to give the bonus, it charged you second time also I guess.

I hope you are happy with my PrimeNumbers answer.

Best Regards
Partha

Customer: replied 5 years ago.

Partha ,My brother all is well Thanks

 

 

Reyes

JustAnswer in the News:

 
 
 
Ask-a-doc Web sites: If you've got a quick question, you can try to get an answer from sites that say they have various specialists on hand to give quick answers... Justanswer.com.
JustAnswer.com...has seen a spike since October in legal questions from readers about layoffs, unemployment and severance.
Web sites like justanswer.com/legal
...leave nothing to chance.
Traffic on JustAnswer rose 14 percent...and had nearly 400,000 page views in 30 days...inquiries related to stress, high blood pressure, drinking and heart pain jumped 33 percent.
Tory Johnson, GMA Workplace Contributor, discusses work-from-home jobs, such as JustAnswer in which verified Experts answer people’s questions.
I will tell you that...the things you have to go through to be an Expert are quite rigorous.
 
 
 

What Customers are Saying:

 
 
 
  • My Expert answered my question promptly and he resolved the issue totally. This is a great service. I am so glad I found it I will definitely use the service again if needed. One Happy Customer New York
< Last | Next >
  • My Expert answered my question promptly and he resolved the issue totally. This is a great service. I am so glad I found it I will definitely use the service again if needed. One Happy Customer New York
  • Wonderful service, prompt, efficient, and accurate. Couldn't have asked for more. I cannot thank you enough for your help. Mary C. Freshfield, Liverpool, UK
  • This expert is wonderful. They truly know what they are talking about, and they actually care about you. They really helped put my nerves at ease. Thank you so much!!!! Alex Los Angeles, CA
  • Thank you for all your help. It is nice to know that this service is here for people like myself, who need answers fast and are not sure who to consult. GP Hesperia, CA
  • I couldn't be more satisfied! This is the site I will always come to when I need a second opinion. Justin Kernersville, NC
  • Just let me say that this encounter has been entirely professional and most helpful. I liked that I could ask additional questions and get answered in a very short turn around. Esther Woodstock, NY
  • Thank you so much for taking your time and knowledge to support my concerns. Not only did you answer my questions, you even took it a step further with replying with more pertinent information I needed to know. Robin Elkton, Maryland
 
 
 

Meet The Experts:

 
 
 
  • ATLPROG

    Computer Software Engineer

    Satisfied Customers:

    7463
    MS in IT.Several years of programming experience in Java C++ C C# Python VB Javascript HTML
< Last | Next >
  • http://ww2.justanswer.com/uploads/SP/spatlanta2010/2011-6-23_12450_photo.64x64.gif ATLPROG's Avatar

    ATLPROG

    Computer Software Engineer

    Satisfied Customers:

    7463
    MS in IT.Several years of programming experience in Java C++ C C# Python VB Javascript HTML
  • http://ww2.justanswer.com/uploads/ComputersGuru/2010-02-13_051118_Photo41.JPG LogicPro's Avatar

    LogicPro

    Computer Software Engineer

    Satisfied Customers:

    5603
    Expert in C, C++, Java, DOT NET, Python, HTML, Javascript, Design.
  • http://ww2.justanswer.com/uploads/unvadim/2010-11-15_210218_avatar.jpg unvadim's Avatar

    unvadim

    Computer Software Engineer

    Satisfied Customers:

    1158
    Good knowledge of OOP principles. 3+ years of programming experience with Java and C++. Sun Certified Java Programmer 5.0.
  • http://ww2.justanswer.com/uploads/lifesaver333/2010-10-17_191349_ls.jpeg lifesaver's Avatar

    lifesaver

    Computer Software Engineer

    Satisfied Customers:

    950
    Several years of intensive programming and application development experience in various platforms.
  • http://ww2.justanswer.com/uploads/EH/ehabtutor/2012-8-2_202016_1.64x64.jpg ehabtutor's Avatar

    ehabtutor

    Computer Software Engineer

    Satisfied Customers:

    864
    Bachelor of computer science, 5+ years experience in software development, software company owner
  • http://ww2.justanswer.com/uploads/RA/rajivsharma086/2012-6-6_17128_displaypic.64x64.jpg Raj's Avatar

    Raj

    Computer Engg.

    Satisfied Customers:

    860
    BE CS, 4+ Experience in Programming and Database (ERP)
  • http://ww2.justanswer.com/uploads/eljonis/2010-01-06_130406_eljon2.jpg Eljon's Avatar

    Eljon

    Consultant

    Satisfied Customers:

    590
    11 yrs of programming (PHP, WordPress, XSL, SQL, JavaScript)
 
 
 

Related Programming Questions

Chat Now With A Programmer
Partha
Partha
14 Satisfied Customers
Masters degree with Web/Java programming experience.