Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.99 KB | None | 0 0
  1. import java.util.Scanner;
  2. import java.util.GregorianCalendar;
  3.  
  4. public class MenuProgram {
  5. private static void displayAsDollarsAndCents(int cents)
  6. {
  7. System.out.print("$" + (cents/100) + "." + (cents%100));
  8. }
  9. public static void main(String[] args) {
  10. // TODO Auto-generated method stub
  11.  
  12.  
  13. for (int i = 0; i < 80; i++ ) {
  14. System.out.print("=");
  15. }
  16. System.out.println("\n FEDERATION UNIVERSITY PHONE BILL COMPARISING SYSTEM");
  17. System.out.println("\n Developed by Petar Petrov, student ID 30323980 for ITECH1000 Semester 1 2017 \n" );
  18. for (int i =0; i < 80; i++) {
  19. System.out.print("=");
  20.  
  21. }
  22.  
  23.  
  24. Scanner s = new Scanner(System.in);
  25. int numOfCalls = 0;
  26. int exit = 0;
  27. int dataUsage = 0;
  28. int sms = 0;
  29. int callInSec = 0;
  30. int totalCallInSec = 0;
  31. int numCallsPrice = 0;
  32. int priceCallInSec = 0;
  33. int priceSms = 0;
  34. int priceData = 0;
  35. int totalCost = 0;
  36. int totalCost2 = 0;
  37. int totalCost3 =0;
  38.  
  39.  
  40. while(exit!=6){
  41. int exit2 =0;
  42. System.out.println("\n"
  43. +"MAIN MENU \n"
  44. +"Please select an option from the menu: \n"
  45. +"1. Enter Usage Details \n"
  46. +"2. Display Cost Under Plan A \n"
  47. +"3. Display Cost Under Plan B \n"
  48. +"4. Display Cost Under Plan C \n"
  49. +"5. Clear Usage Details \n"
  50. +"6. Exit System \n");
  51.  
  52. int input = s.nextInt();
  53. if (input <1 || input >=7) {
  54. System.out.println("Value must be between 1 or 6. Please try again: ");
  55. input = s.nextInt();
  56.  
  57. }
  58.  
  59.  
  60. switch (input){
  61.  
  62. case 1:
  63. while (exit2!=4){
  64. System.out.println(g.getTime());
  65.  
  66. System.out.println("ENTER USAGE DETAILS MENU\n"+
  67. "Please select an option from the menu:\n"+
  68. "1. Phone Call\n"+
  69. "2. SMS\n"+
  70. "3. Data Usage\n"+
  71. "4. Return to main menu\n");
  72.  
  73. int usageInput =s.nextInt();
  74.  
  75. switch(usageInput){
  76.  
  77. case 1:
  78. System.out.println("Enter call length in seconds:");
  79. callInSec =s.nextInt();
  80. while (callInSec<0 && callInSec!=0) {
  81. System.out.println("Value must be positive. Please try again:");
  82. callInSec = s.nextInt();
  83. }
  84. numOfCalls = numOfCalls +1;
  85. totalCallInSec = callInSec + totalCallInSec;
  86. break;
  87. case 2:
  88. System.out.println("SMS: ");
  89. sms =s.nextInt();
  90. System.out.println("\nTotal number of messages so far = " +sms);
  91. break;
  92. case 3:
  93. System.out.println("Enter the amount of data in MB: ");
  94. dataUsage = s.nextInt();
  95. while (dataUsage<0 && dataUsage!=0) {
  96. System.out.println("Value must be positive. Please try again:");
  97. dataUsage = s.nextInt();
  98. }
  99. break;
  100. default:System.out.println("Return to main menu\n" +(exit2=4));
  101.  
  102. break;
  103. }
  104. }
  105.  
  106. break;
  107.  
  108. case 2:
  109.  
  110. System.out.println("Cost under Plan A");
  111. for (int i = 0; i < 38; i++ ) {
  112. System.out.print("=");
  113. }
  114.  
  115. numCallsPrice = numOfCalls * 23;
  116. System.out.print("\n Number of calls = "+numOfCalls+" ");
  117. displayAsDollarsAndCents(numCallsPrice);
  118.  
  119. priceCallInSec = totalCallInSec *2;
  120. System.out.print("\n Total call time (secs) = "+totalCallInSec+" ");
  121. displayAsDollarsAndCents(priceCallInSec);
  122.  
  123. priceSms = sms *12;
  124. System.out.print("\n Number of SMS = "+sms+" ");
  125. displayAsDollarsAndCents(priceSms);
  126.  
  127. priceData = dataUsage*3;
  128. System.out.print("\n Data usage (MB) = "+dataUsage+" ");
  129. displayAsDollarsAndCents(priceData);
  130.  
  131. System.out.println("");
  132.  
  133. for (int i = 0; i < 38; i++ ) {
  134. System.out.print("=");
  135.  
  136. }
  137.  
  138. totalCost = numCallsPrice + priceCallInSec + priceSms + priceData;
  139. System.out.print("\n TOTAL COST"+(" "));
  140. displayAsDollarsAndCents(totalCost);
  141. System.out.println("");
  142. break;
  143. case 3:
  144.  
  145. System.out.println("Cost under Plan B");
  146. for (int i = 0; i < 38; i++ ) {
  147. System.out.print("=");
  148. }
  149.  
  150. numCallsPrice = numOfCalls * 17;
  151. System.out.print("\n Number of calls = "+numOfCalls+" ");
  152. displayAsDollarsAndCents(numCallsPrice);
  153.  
  154. priceCallInSec = totalCallInSec *3;
  155. System.out.print("\n Total call time (secs) = "+totalCallInSec+" ");
  156. displayAsDollarsAndCents(priceCallInSec);
  157.  
  158. priceSms = sms *15;
  159. System.out.print("\n Number of SMS = "+sms+" ");
  160. displayAsDollarsAndCents(priceSms);
  161.  
  162. priceData = dataUsage*2;
  163. System.out.print("\n Data usage (MB) = "+dataUsage+" ");
  164. displayAsDollarsAndCents(priceData);
  165.  
  166. System.out.println("");
  167.  
  168. for (int i = 0; i < 38; i++ ) {
  169. System.out.print("=");
  170.  
  171. }
  172.  
  173. totalCost2 = numCallsPrice + priceCallInSec + priceSms + priceData;
  174. System.out.print("\n TOTAL COST"+(" "));
  175. displayAsDollarsAndCents(totalCost2);
  176. System.out.println("");
  177. break;
  178.  
  179. case 4:
  180. System.out.println("Cost under Plan C");
  181. for (int i = 0; i < 38; i++ ) {
  182. System.out.print("=");
  183. }
  184.  
  185. numCallsPrice = numOfCalls * 11;
  186. System.out.print("\n Number of calls = "+numOfCalls+" ");
  187. displayAsDollarsAndCents(numCallsPrice);
  188.  
  189. priceCallInSec = totalCallInSec *3;
  190. System.out.print("\n Total call time (secs) = "+totalCallInSec+" ");
  191. displayAsDollarsAndCents(priceCallInSec);
  192.  
  193. priceSms = sms *9;
  194. System.out.print("\n Number of SMS = "+sms+" ");
  195. displayAsDollarsAndCents(priceSms);
  196. if (dataUsage <=100) {
  197. priceData = dataUsage*2;
  198. System.out.print("\n Data usage (MB) = "+dataUsage+" ");
  199. displayAsDollarsAndCents(priceData);
  200. }
  201. else {
  202. priceData = dataUsage*10;
  203. System.out.print("\n Data usage (MB) = "+dataUsage+" ");
  204. displayAsDollarsAndCents(priceData);
  205. }
  206. System.out.println("");
  207.  
  208. for (int i = 0; i < 38; i++ ) {
  209. System.out.print("=");
  210.  
  211. }
  212.  
  213. totalCost = numCallsPrice + priceCallInSec + priceSms + priceData;
  214. System.out.print("\n TOTAL COST"+(" "));
  215. displayAsDollarsAndCents(totalCost);
  216. System.out.println("");
  217.  
  218.  
  219.  
  220. case 5: System.out.println("Clear usage details");
  221. numOfCalls = 0;
  222. exit = 0;
  223. dataUsage = 0;
  224. sms = 0;
  225. callInSec = 0;
  226. totalCallInSec = 0;
  227. numCallsPrice = 0;
  228. priceCallInSec = 0;
  229. priceSms = 0;
  230. priceData = 0;
  231. totalCost = 0;
  232. totalCost2 = 0;
  233. totalCost3 =0;
  234.  
  235. break;
  236. case 6:
  237. for (int i = 0; i < 65; i++ ) {
  238. System.out.print("=");
  239.  
  240. }
  241. System.out.println("\nThank you for using this software. We hope you found it useful.");
  242. for (int i = 0; i < 65; i++ ) {
  243. System.out.print("=");
  244.  
  245. }
  246. exit=6;
  247. break;
  248. default:System.out.println("The option selected is invalid, try again" );
  249.  
  250. }
  251. }
  252. }
  253. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement