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

This answer was rated:

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.
The input and output must use JOptionPane dialog and display boxes. Do you have a sample program that uses the JOptionPane?
Customer: replied 8 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 8 years ago.
Still waiting for response, please reply any progress
Is any one working on solution for this question or do you want to get answer?
Customer: replied 8 years ago.
no one , and yes I would like an answer
Customer: replied 8 years ago.
no one , and yes I would like an answer
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 other Programming Specialists are ready to help you
Customer: replied 8 years ago.
I've compile and tested first option window in loop will not continue to next option, used jGRASP to test
1) Do you want the result at the end or for each entry?
2) What do you expect in the next entry?
Customer: replied 8 years ago.

recompiled recieved correct response,

 

 

thanks, XXXXX XXXXX

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?
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 other Programming Specialists are ready to help you
Customer: replied 8 years ago.

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

Customer: replied 8 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.

 

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 8 years ago.

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

I think you would have been billed for 40 dollars only but with two accepts
Customer: replied 8 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 -
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 8 years ago.

Partha ,My brother all is well Thanks

 

 

Reyes