
Untitled
By: a guest on Feb 12th, 2012 | syntax:
None | size: 1.66 KB | hits: 27 | expires: Never
//By Jonathan Slotter
import java.util.Scanner;
public class Lab11_Ex2
{
public static void main(String [] args)
{
Scanner input = new Scanner(System.in);
Scanner keyboard = new Scanner (System.in);
final int NUMBERS = 3; //Max number of salesman
String[] salesMenList = new String[NUMBERS];
double [] saleAmountList = new double[NUMBERS];
int index;
String salesMen;
double saleAmount;
System.out.println("Enter the name of 3 Salesmen, and the amount each one sold.");
for(index = 0; index < NUMBERS; index++)
{
System.out.print("Enter a salesman's name: ");
salesMen = keyboard.next();
salesMenList[index] = salesMen;
System.out.print("Enter in the sales amount for that salesman: ");
saleAmount = keyboard.nextDouble();
saleAmountList[index] = saleAmount;
}
for(int i = 0; i < NUMBERS; i++)
{
System.out.println(salesMenList[i] + " sold " + saleAmountList[i] + " for the quarter of the year.");
}
double highest = saleAmountList[0];
int highestIndex = 0;
for(int i = 1; i < saleAmountList.length; i++) // i starts at 1 since highest already is x[0]
{
if(saleAmountList[i] > highest)
{
highest = saleAmountList[i];
highestIndex = i;
}
}
double lowest = saleAmountList[0];
int lowestIndex = 0;
for(int i = 1; i > saleAmountList.length; i++)
{
if(saleAmountList[i] < lowest)
{
lowest = saleAmountList[i];
lowestIndex = i;
}
}
System.out.println("1) " + salesMenList[highestIndex] + ": " + saleAmountList[highestIndex]);
System.out.println("3) " + salesMenList[lowestIndex] + ": " + saleAmountList[lowestIndex]);
System.exit(0);
}
}