Created
November 24, 2012 16:36
-
-
Save anonymous/4140419 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner; | |
public class SalesReport{ | |
int salespeople; | |
int sum; | |
int sales[]; | |
Scanner scan = new Scanner(System.in); | |
public SalesReport(int howMany){ | |
this.salespeople = howMany; | |
this.sales = new int[salespeople]; | |
} | |
public SalesReport(){ | |
System.out.print("Enter the number of salespersons: "); | |
this.salespeople = scan.nextInt(); | |
this.sales = new int[salespeople]; | |
} | |
public void testMe(){ | |
getSalesInput(); | |
provideSalesOutput(); | |
findMax(); | |
findMin(); | |
newValue(); | |
} | |
public void getSalesInput(){ | |
Scanner scan = new Scanner(System.in); | |
for (int i=0; i < sales.length; i++) | |
{ | |
System.out.print("Enter sales for salesperson " + (i+1) + ": "); | |
sales[i] = scan.nextInt(); | |
} | |
} | |
public void provideSalesOutput(){ | |
System.out.println("\nSalesperson Sales"); | |
System.out.println("--------------------"); | |
sum = 0; | |
for (int i=0; i < sales.length; i++) | |
{ | |
System.out.println(" " + (i+1) + " " + sales[i]); | |
sum = sum + sales[i]; | |
} | |
System.out.println("\nTotal sales: " + sum); | |
} | |
public void findMin(){ | |
int min = sales[0]; | |
int who = 0; | |
for (int i=0; i < sales.length; i++) | |
{ | |
if (min > sales[i]) | |
{ | |
min = sales[i]; | |
who = i; | |
} | |
} | |
System.out.println("\nSalesperson " + (who+1) + " had the lowest sale with $" + min ); | |
} | |
public void findMax(){ | |
int max = sales[0]; | |
int who = 0; | |
for (int i=0; i < sales.length; i++) | |
{ | |
if (max < sales[i]) | |
{ | |
max = sales[i]; | |
who = i; | |
} | |
} | |
System.out.println("\nSalesperson " + (who+1) + " had the highest sale with $" + max ); | |
} | |
public void newValue() { | |
System.out.print("Please enter a new value: "); | |
int valueToCompareAgainst = scan.nextInt(); | |
findLargerSales(valueToCompareAgainst); | |
} | |
public void findLargerSales(int valueToCompareAgainst) { | |
for (int i=0; i < sales.length; i++) | |
{ | |
if (sales[i] > valueToCompareAgainst) | |
{ | |
salespeople = sales[i]; | |
System.out.println("\nSalesperson " + (i + 1) + " exceeded the new value of " + valueToCompareAgainst + " with value: $" + this.sales[i]); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment