Hello All,
I am a newbie trying to learn thru doing exercises and reading from one study book.I have run into some troubles with one program that has me mentally stalled. Here is the problem I am working on.
The process of finding the largest value (i.e., the maximum of a group
of values) is used
frequently in computer applications.For example, a program that
determines the winner of
a sales contest would input the number of units sold by each
salesperson. The salesperson
who sell the most units wins the contest. Write a pseudocode program
and then a
Java application that inputs a series of 10 single-digit number as
characters and determines
and prints the largest of the number. Hint: Your program should use the
following three
variables:
a) counter: A counter to count to 10 (i.e., to keep track of how many
numbers
have been input and to determine when all 10 numbers been processed);
b) number: The current digit input to the program;
c) largest: The largest number found so far.
Here is what I have so far.
import javax.swing.JOptionPane;
public class Ch4_15 {
public static void main(
String args[])
{
String number;
double sales;
int counter;
double largest;
largest = 0;
counter = 0;
number = JOptionPane.showInputDialog("Please enter the sales amount of item sold by Employee");
sales = Double.parseDouble(number);
while( counter!= 10)
{
counter = counter + 1;
number = JOptionPane.showInputDialog("Please enter a single digit for the sales unit");
sales = Double.parseDouble(number);
}
JOptionPane.showMessageDialog(null," The largest number input was " + largest, "Paycheck", JOptionPane.INFORMATION_MESSAGE );
}
}
Now as you can see I don't have anything to calculate what the largest number is. THis is what my problem is. I can not think of a way to do this, because if I am reading this problem correct, it states to find the largest input from 10. The only way I can think of is if name those inputs number1, number2, number3,.....number10 and use if statements to find the largest, but I don't beleive this problem is asking for it to be calculated in that manner. Can someone please point me in the right direction?