// David Fritz
// Assignment - Test C
// 12/09/12
//---------------------------------------------------------------
import java.util.Scanner; //needed for input
public class TestC
{
static double notGreen[] = new double[12]; //stores the monthly energy bills without a rooftop garden
static double goneGreen[] = new double[12]; //stores the monthly energy bills with a rooftop garden
static double actualSavings[] = new double [12];
static double projectedSavings = 0; //stores what the business hopes to save
static String businessName
= " " ; // stores the business name static double totalSavings = 0;
"February", "March", "April", "May", "June",
"July", "August", "September", "October",
"November", "December" };
static double negCheck;
static int negative;
public static void main
(String[] args
) {
Scanner stdin
= new Scanner
(System.
in); // needed for input String anotherCourse
= "yes"; // variable to control running program again
do
{
getBusinessInfo();
getNotGreen();
getGoneGreen();
determineEfficency();
displayTable(); // This code ends the do while to run again
System.
out.
print("\n\nEnter yes if you want to run again or press enter to quit: "); anotherCourse = stdin.next();
stdin.nextLine(); // causes skipping issue to fix
} while (anotherCourse.equalsIgnoreCase("yes"));
}
public static void getBusinessInfo()
{
Scanner stdin
= new Scanner
(System.
in); // needed for input System.
out.
println("What is the name of your business?"); businessName = stdin.next();
System.
out.
println("How much money do you expect to save?"); negCheck = stdin.nextDouble();
negative = 0;
while(negative == 0)
{
if (negCheck >= 0)
{
projectedSavings = negCheck;
negative = 1;
}
else
{
System.
out.
println("You may not enter a negative savings amount, please try again."); }
}
}
public static void getNotGreen()
{
System.
out.
println("For the months before your company went green:"); Scanner stdin
= new Scanner
(System.
in); // needed for input for (int i = 0; i < notGreen.length; i++)
{
while (notGreen[i] <= i)
{
System.
out.
println("What was your energy bill for " + months
[i
] + "?"); int a = stdin.nextInt();
negative = 0;
while(negative == 0)
{
if (a >= 0)
{
projectedSavings = a;
negative = 1;
}
else
{
System.
out.
println("You may not enter a negative energy bill, please try again."); }
}
notGreen[i] = a;
}
}
}
public static void getGoneGreen()
{
System.
out.
println("For the months after your company went green:"); Scanner stdin
= new Scanner
(System.
in); // needed for input for (int i = 0; i < goneGreen.length; i++)
{
while (goneGreen[i] <= i)
{
System.
out.
println("For the months after your company went green:"); System.
out.
println("What was your energy bill for " + months
[i
] + "?"); int a = stdin.nextInt();
negative = 0;
while(negative == 0)
{
if (a >= 0)
{
projectedSavings = a;
negative = 1;
}
else
{
System.
out.
println("You may not enter a negative energy bill, please try again."); }
}
goneGreen[i] = a;
}
}
}
public static void determineEfficency()
{
for (int i = 0; i < actualSavings.length; i++)
{
while (actualSavings[i] <= i)
{
actualSavings[i] = (notGreen [i] - goneGreen[i]);
}
}
}
public static void displayTable()
{
System.
out.
println("Efficiency Report for" + businessName
); System.
out.
println("Months.........Before Going Green..........After Going Green"); for (int i = 0; i < actualSavings.length; i++)
{
while (actualSavings[i] <= i)
{
System.
out.
println(months
[i
] + "..." + notGreen
[i
] + "....." + goneGreen
); }
}
System.
out.
println("Your savings per month were:"); for (int i = 0; i < actualSavings.length; i++)
{
while (actualSavings[i] <= i)
{
System.
out.
println(months
[i
] + "..." + actualSavings
[i
]); }
}
for (int i = 0; i < actualSavings.length; i++)
{
while (actualSavings[i] <= i)
{
totalSavings =+ actualSavings[i];
}
}
if (totalSavings < 0)
{
System.
out.
println("Your total losses were $" + totalSavings
); }
else
{
System.
out.
println("Your total savings were $" + totalSavings
); }
if (projectedSavings > totalSavings)
{
System.
out.
println("You saved " + (totalSavings
- projectedSavings
) + " more than expected!"); }
else if (projectedSavings < totalSavings)
{
System.
out.
println("You saved " + (projectedSavings
- totalSavings
) + " less than expected!"); }
else if (projectedSavings == totalSavings)
{
System.
out.
println("You saved exactly what you expected!"); }
}
} // end of class