Skip to content

Instantly share code, notes, and snippets.

Created November 24, 2012 16:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/4140419 to your computer and use it in GitHub Desktop.
Save anonymous/4140419 to your computer and use it in GitHub Desktop.
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