Hi All,
I am trying to write a program that basically determines the max amount of units sold and displays it in a dialog box. Also, the program will display the winning sales associate out of 10. I have wrote the program successfully so far and I can see the maximum number of units sold displayed in the dialog box, but I cannot seem to link the winning sales person.
Here is the code I have typed so far.
//Program to find maximum of three number
import javax.swing.JOptionPane;
import java.util.Scanner;
public class Sales
{
public static void main (String[] args)
{
//Declare variables
int num1, num2, num3, num4, num5, num6, num7, num8, num9, num10;
int large;
int winner;
//Create scanner object to receive user input
Scanner input = new Scanner(System.in);
//Prompt the user for input numbers
System.out.print("Enter units sold by sales person # 1 : ");
num1 = input.nextInt();
System.out.print("Enter units sold by sales person # 2 : ");
num2 = input.nextInt();
System.out.print("Enter units sold by sales person # 3 : ");
num3 = input.nextInt();
System.out.print("Enter units sold by sales person # 4 : ");
num4 = input.nextInt();
System.out.print("Enter units sold by sales person # 5 : ");
num5 = input.nextInt();
System.out.print("Enter units sold by sales person # 6 : ");
num6 = input.nextInt();
System.out.print("Enter units sold by sales person # 7 : ");
num7 = input.nextInt();
System.out.print("Enter units sold by sales person # 8 : ");
num8 = input.nextInt();
System.out.print("Enter units sold by sales person # 9 : ");
num9 = input.nextInt();
System.out.print("Enter units sold by sales person # 10 : ");
num10 = input.nextInt();
//Initialize large number
large = num1;
winner = num1;
//Compare other numbers with large and reassign
if (num2 > large)
large = num2; //assign num2 to large
if (num2 > winner)
winner = num2;
if (num3 > large)
large = num3; //assign num3 to large
if (num3 > winner)
winner = num3;
if (num4 > large)
large = num4; //assign num4 to large
if (num4 > winner)
winner = num4;
if (num5 > large)
large = num5; //assign num5 to large
if (num5 > winner)
winner = num5;
if (num6 > large)
large = num6; //assign num6 to large
if (num6 > winner)
winner = num6;
if (num7 > large)
large = num7; //assign num7 to large
if (num7 > winner)
winner = num7;
if (num8 > large)
large = num8; //assign num8 to large
if (num8 > winner)
winner = num8;
if (num9 > large)
large = num9; //assign num9 to large
if (num9 > winner)
winner = num9;
if (num10 > large)
large = num10; //assign num10 to large
if (num10 > winner)
winner = num10;
//Extra line
System.out.println();
//Print the largest number
//System.out.printf("Maximum units sold: %d \n", large);
String message = "";
message = message + String.format("Maximum units sold: %d \n", large);
message = message + String.format("Winning sales person: %d", winner);
JOptionPane.showMessageDialog (null, message);
}//End main method
}//End class