fork(2) download
  1. // David Fritz
  2. // Assignment - Test C
  3. // 12/09/12
  4. //---------------------------------------------------------------
  5.  
  6. import java.util.Scanner; //needed for input
  7.  
  8. public class TestC
  9. {
  10. static double notGreen[] = new double[12]; //stores the monthly energy bills without a rooftop garden
  11. static double goneGreen[] = new double[12]; //stores the monthly energy bills with a rooftop garden
  12. static double actualSavings[] = new double [12];
  13. static double projectedSavings = 0; //stores what the business hopes to save
  14. static String businessName = " " ; // stores the business name
  15. static double totalSavings = 0;
  16. static String months[] = new String[] { "January",
  17. "February", "March", "April", "May", "June",
  18. "July", "August", "September", "October",
  19. "November", "December" };
  20. static double negCheck;
  21. static int negative;
  22. public static void main(String[] args)
  23. {
  24. Scanner stdin = new Scanner(System.in); // needed for input
  25. String anotherCourse = "yes"; // variable to control running program again
  26.  
  27. do
  28. {
  29. getBusinessInfo();
  30. getNotGreen();
  31. getGoneGreen();
  32. determineEfficency();
  33. displayTable(); // This code ends the do while to run again
  34.  
  35. System.out.print("\n\nEnter yes if you want to run again or press enter to quit: ");
  36. anotherCourse = stdin.next();
  37. stdin.nextLine(); // causes skipping issue to fix
  38.  
  39. System.out.print("\n\n\n");
  40. } while (anotherCourse.equalsIgnoreCase("yes"));
  41. }
  42.  
  43. public static void getBusinessInfo()
  44. {
  45. Scanner stdin = new Scanner(System.in); // needed for input
  46. System.out.println("What is the name of your business?");
  47. businessName = stdin.next();
  48. System.out.println("How much money do you expect to save?");
  49. negCheck = stdin.nextDouble();
  50. negative = 0;
  51. while(negative == 0)
  52. {
  53. if (negCheck >= 0)
  54. {
  55. projectedSavings = negCheck;
  56. negative = 1;
  57. }
  58. else
  59. {
  60. System.out.println("You may not enter a negative savings amount, please try again.");
  61. }
  62. }
  63. }
  64.  
  65. public static void getNotGreen()
  66. {
  67. System.out.println("For the months before your company went green:");
  68. Scanner stdin = new Scanner(System.in); // needed for input
  69. for (int i = 0; i < notGreen.length; i++)
  70. {
  71. while (notGreen[i] <= i)
  72. {
  73.  
  74. System.out.println("What was your energy bill for " + months[i] + "?");
  75. int a = stdin.nextInt();
  76. negative = 0;
  77. while(negative == 0)
  78. {
  79. if (a >= 0)
  80. {
  81. projectedSavings = a;
  82. negative = 1;
  83. }
  84. else
  85. {
  86. System.out.println("You may not enter a negative energy bill, please try again.");
  87. }
  88. }
  89. notGreen[i] = a;
  90. }
  91. }
  92. }
  93.  
  94. public static void getGoneGreen()
  95. {
  96. System.out.println("For the months after your company went green:");
  97. Scanner stdin = new Scanner(System.in); // needed for input
  98. for (int i = 0; i < goneGreen.length; i++)
  99. {
  100. while (goneGreen[i] <= i)
  101. {
  102. System.out.println("For the months after your company went green:");
  103. System.out.println("What was your energy bill for " + months[i] + "?");
  104. int a = stdin.nextInt();
  105. negative = 0;
  106. while(negative == 0)
  107. {
  108. if (a >= 0)
  109. {
  110. projectedSavings = a;
  111. negative = 1;
  112. }
  113. else
  114. {
  115. System.out.println("You may not enter a negative energy bill, please try again.");
  116. }
  117. }
  118. goneGreen[i] = a;
  119. }
  120. }
  121. }
  122.  
  123. public static void determineEfficency()
  124. {
  125. for (int i = 0; i < actualSavings.length; i++)
  126. {
  127. while (actualSavings[i] <= i)
  128. {
  129. actualSavings[i] = (notGreen [i] - goneGreen[i]);
  130. }
  131. }
  132. }
  133.  
  134. public static void displayTable()
  135. {
  136.  
  137. System.out.println("Efficiency Report for" + businessName);
  138. System.out.println("Months.........Before Going Green..........After Going Green");
  139. for (int i = 0; i < actualSavings.length; i++)
  140. {
  141. while (actualSavings[i] <= i)
  142. {
  143. System.out.println(months[i] + "..." + notGreen[i] + "....." + goneGreen);
  144. }
  145. }
  146. System.out.println("Your savings per month were:");
  147. for (int i = 0; i < actualSavings.length; i++)
  148. {
  149. while (actualSavings[i] <= i)
  150. {
  151. System.out.println(months[i] + "..." + actualSavings[i]);
  152. }
  153.  
  154. }
  155. for (int i = 0; i < actualSavings.length; i++)
  156. {
  157. while (actualSavings[i] <= i)
  158. {
  159. totalSavings =+ actualSavings[i];
  160. }
  161. }
  162. if (totalSavings < 0)
  163. {
  164. System.out.println("Your total losses were $" + totalSavings);
  165. }
  166. else
  167. {
  168. System.out.println("Your total savings were $" + totalSavings);
  169. }
  170. if (projectedSavings > totalSavings)
  171. {
  172. System.out.println("You saved " + (totalSavings - projectedSavings) + " more than expected!");
  173. }
  174. else if (projectedSavings < totalSavings)
  175. {
  176. System.out.println("You saved " + (projectedSavings - totalSavings) + " less than expected!");
  177. }
  178. else if (projectedSavings == totalSavings)
  179. {
  180. System.out.println("You saved exactly what you expected!");
  181. }
  182. }
  183.  
  184. } // end of class
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:8: class TestC is public, should be declared in a file named TestC.java
public class TestC 
       ^
1 error
stdout
Standard output is empty