Guest

Untitled

By: a guest on Feb 12th, 2012  |  syntax: None  |  size: 1.66 KB  |  hits: 27  |  expires: Never
download  |  raw  |  embed  |  report abuse
Copied
  1. //By Jonathan Slotter
  2.  
  3. import java.util.Scanner;
  4. public class Lab11_Ex2
  5.  
  6. {
  7.   public static void main(String [] args)
  8.   {
  9.         Scanner input = new Scanner(System.in);
  10.     Scanner keyboard = new Scanner (System.in);
  11.        
  12.         final int NUMBERS = 3; //Max number of salesman
  13.         String[] salesMenList = new String[NUMBERS];
  14.         double [] saleAmountList = new double[NUMBERS];
  15.         int index;
  16.         String salesMen;
  17.         double saleAmount;
  18.        
  19.        
  20.         System.out.println("Enter the name of 3 Salesmen, and the amount each one sold.");
  21.        
  22.         for(index = 0; index < NUMBERS; index++)
  23.         {
  24.                 System.out.print("Enter a salesman's name: ");
  25.                 salesMen = keyboard.next();
  26.                 salesMenList[index] = salesMen;
  27.                
  28.                 System.out.print("Enter in the sales amount for that salesman: ");
  29.                 saleAmount = keyboard.nextDouble();
  30.                 saleAmountList[index] = saleAmount;
  31.         }
  32.        
  33.         for(int i = 0; i < NUMBERS; i++)
  34.         {
  35.                 System.out.println(salesMenList[i] + " sold " + saleAmountList[i] + " for the quarter of the year.");
  36.         }
  37.        
  38.         double highest = saleAmountList[0];
  39.         int highestIndex = 0;
  40.         for(int i = 1; i < saleAmountList.length; i++) // i starts at 1 since highest already is x[0]
  41.         {
  42.                 if(saleAmountList[i] > highest)
  43.                 {
  44.                         highest = saleAmountList[i];
  45.                         highestIndex = i;
  46.                 }
  47.         }
  48.         double lowest = saleAmountList[0];
  49.         int lowestIndex = 0;
  50.         for(int i = 1; i > saleAmountList.length; i++)
  51.         {
  52.                 if(saleAmountList[i] < lowest)
  53.                 {
  54.                         lowest = saleAmountList[i];
  55.                         lowestIndex = i;
  56.                 }
  57.         }
  58.        
  59.        
  60.         System.out.println("1) " + salesMenList[highestIndex] + ": " + saleAmountList[highestIndex]);
  61.        
  62.         System.out.println("3) " + salesMenList[lowestIndex] + ": " + saleAmountList[lowestIndex]);
  63.        
  64.         System.exit(0);
  65.        
  66.         }
  67. }