Skip to content

Instantly share code, notes, and snippets.

@eogas
Forked from anonymous/gist:4308810
Created December 16, 2012 16:07
Show Gist options
  • Save eogas/4308937 to your computer and use it in GitHub Desktop.
Save eogas/4308937 to your computer and use it in GitHub Desktop.
Make a new Eclipse project for this objective named java4_Objective1. Put a copy of our current SalesApp class in this new project. So that it has no errors, comment out the lines about the SalesInterface:
// SalesInterface myInterface;
// public void setInterface(SalesInterface myGUI){
// myInterface = myGUI;
// }
Save this--there should be no errors now in this current version.
package salesGUI;
public class SalesApp {
private int[] sales;
private int salesBar;
private int totalSales;
private double average;
private int minIndex = 0;
private int maxIndex = 0;
SalesUserInterface myUserInterface; //SalesInterface myInterface;
public void setMyUserInterface(SalesUserInterface myGUI){ // public void setInterface(Salesinterface myGUI) {
myUserInterface = myGUI; // myInterface = myGuI;
} //}
public void setSales(int[] sales) {
this.sales = sales;
for (int i = 0; i < sales.length; i++)
System.out.println(sales[i]);
setTotalSales();
}
public void setTotalSales() {
totalSales = 0;
for (int x = 0; x < sales.length; x++)
totalSales += sales[x];
setAverage();
}
public void setAverage() {
if (sales.length != 0)
average = (double) (totalSales / sales.length);
System.out.println("totalSales is " + totalSales + " and sales.length is "
+ sales.length + " making average "
+ ((double) totalSales / sales.length));
}
public void setSalesBar(int goal){
salesBar = goal;
}
public int[] getSales() {
return sales;
}
public double getAverage() {
if (sales.length != 0)
return ((double) totalSales / sales.length);
else
return average;
}
public int getBar() {
return salesBar;
}
public int getTotalSales() {
return totalSales;
}
public int getMin() {
return minIndex;
}
public int getMax() {
return maxIndex;
}
public void calculateMinMax() {
int minimum = sales[0];
int maximum = sales[0];
for (int x = 0; x < sales.length; x++) {
if (sales[x] > maximum) {
maximum = sales[x];
maxIndex = x;
}
else if (sales[x] < minimum)
{
minimum = sales[x];
minIndex = x;
}
}
System.out.println("Maximum value is at index " + maxIndex
+ " (Salesperson " + (maxIndex + 1) + ") with value " + maximum);
System.out.println("Minimum value is at index " + minIndex
+ " (Salesperson " + (minIndex + 1) + ") with value " + minimum);
setAverage();
}
public int[] determineTopSalesPeople() {
System.out.println("I'm here and salesBar is " + salesBar);
int[] performance = new int[sales.length];
for (int x = 0; x < sales.length; x++)
{
if (sales[x] > salesBar) {
performance[x] = 1;
}
else if (sales[x] == salesBar) {
performance[x] = 0;
}
else {
performance[x] = -1;
}
}
return performance;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment