How do i create this in java? Design and implement a Java program that will gath
ID: 3646788 • Letter: H
Question
How do i create this in java?
Design and implement a Java program that will gather floating point numbers and determine the sum and average of the data entered.
Declare all necessary identifiers.
Inside a while loop:
Accept decimal numbers using a Dialog Input box.
Sum the decimal numbers as they are entered.
When the sum of the entered decimal numbers divided by the total of 100 for the first time:
Display a message with a Message Dialog informing the user that the total number is over 100.
In addition to the warning also display in the Message Dialog the actual total sum at that point.
Do not show this message again for any additional entries above 100.
Keep a counter for the number of times a new decimal number is entered. Have a prompt asking the user when to end entering decimal numbers.
Use a sentinel to end the loop in combination with a prompt.
After the loop, call a calculation method that will return the average from the sum and counter. [An example of the construction of a method with its
Explanation / Answer
import java.util.ArrayList; import java.util.List; import javax.swing.JOptionPane; public class Float { public static void main(String[] args) { String firstNumber; int i=0,size,j=0; float average=0,sum=0; float m; List a=new ArrayList(); while((m=Float.parseFloat (JOptionPane.showInputDialog ( "Enter the values (-1) to exit" )))!= -1) a.add(m); float min=a.get(0),max=a.get(0); for(i=0 ;i100)&&(j==0)) { JOptionPane.showMessageDialog(null,"Sum is above 100:"+sum); j++; } if(a.get(i)max) max=a.get(i); } average=(sum/a.size()); JOptionPane.showMessageDialog (null,"result: sum"+sum +" min:"+min+" max:"+max +" average:"+average); } private static float parseFloat(String showInputDialog) { throw new UnsupportedOperationException("Not yet implemented"); } }Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.