Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- import java.util.GregorianCalendar;
- public class MenuProgram {
- private static void displayAsDollarsAndCents(int cents)
- {
- System.out.print("$" + (cents/100) + "." + (cents%100));
- }
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- for (int i = 0; i < 80; i++ ) {
- System.out.print("=");
- }
- System.out.println("\n FEDERATION UNIVERSITY PHONE BILL COMPARISING SYSTEM");
- System.out.println("\n Developed by Petar Petrov, student ID 30323980 for ITECH1000 Semester 1 2017 \n" );
- for (int i =0; i < 80; i++) {
- System.out.print("=");
- }
- Scanner s = new Scanner(System.in);
- int numOfCalls = 0;
- int exit = 0;
- int dataUsage = 0;
- int sms = 0;
- int callInSec = 0;
- int totalCallInSec = 0;
- int numCallsPrice = 0;
- int priceCallInSec = 0;
- int priceSms = 0;
- int priceData = 0;
- int totalCost = 0;
- int totalCost2 = 0;
- int totalCost3 =0;
- while(exit!=6){
- int exit2 =0;
- System.out.println("\n"
- +"MAIN MENU \n"
- +"Please select an option from the menu: \n"
- +"1. Enter Usage Details \n"
- +"2. Display Cost Under Plan A \n"
- +"3. Display Cost Under Plan B \n"
- +"4. Display Cost Under Plan C \n"
- +"5. Clear Usage Details \n"
- +"6. Exit System \n");
- int input = s.nextInt();
- if (input <1 || input >=7) {
- System.out.println("Value must be between 1 or 6. Please try again: ");
- input = s.nextInt();
- }
- switch (input){
- case 1:
- while (exit2!=4){
- System.out.println(g.getTime());
- System.out.println("ENTER USAGE DETAILS MENU\n"+
- "Please select an option from the menu:\n"+
- "1. Phone Call\n"+
- "2. SMS\n"+
- "3. Data Usage\n"+
- "4. Return to main menu\n");
- int usageInput =s.nextInt();
- switch(usageInput){
- case 1:
- System.out.println("Enter call length in seconds:");
- callInSec =s.nextInt();
- while (callInSec<0 && callInSec!=0) {
- System.out.println("Value must be positive. Please try again:");
- callInSec = s.nextInt();
- }
- numOfCalls = numOfCalls +1;
- totalCallInSec = callInSec + totalCallInSec;
- break;
- case 2:
- System.out.println("SMS: ");
- sms =s.nextInt();
- System.out.println("\nTotal number of messages so far = " +sms);
- break;
- case 3:
- System.out.println("Enter the amount of data in MB: ");
- dataUsage = s.nextInt();
- while (dataUsage<0 && dataUsage!=0) {
- System.out.println("Value must be positive. Please try again:");
- dataUsage = s.nextInt();
- }
- break;
- default:System.out.println("Return to main menu\n" +(exit2=4));
- break;
- }
- }
- break;
- case 2:
- System.out.println("Cost under Plan A");
- for (int i = 0; i < 38; i++ ) {
- System.out.print("=");
- }
- numCallsPrice = numOfCalls * 23;
- System.out.print("\n Number of calls = "+numOfCalls+" ");
- displayAsDollarsAndCents(numCallsPrice);
- priceCallInSec = totalCallInSec *2;
- System.out.print("\n Total call time (secs) = "+totalCallInSec+" ");
- displayAsDollarsAndCents(priceCallInSec);
- priceSms = sms *12;
- System.out.print("\n Number of SMS = "+sms+" ");
- displayAsDollarsAndCents(priceSms);
- priceData = dataUsage*3;
- System.out.print("\n Data usage (MB) = "+dataUsage+" ");
- displayAsDollarsAndCents(priceData);
- System.out.println("");
- for (int i = 0; i < 38; i++ ) {
- System.out.print("=");
- }
- totalCost = numCallsPrice + priceCallInSec + priceSms + priceData;
- System.out.print("\n TOTAL COST"+(" "));
- displayAsDollarsAndCents(totalCost);
- System.out.println("");
- break;
- case 3:
- System.out.println("Cost under Plan B");
- for (int i = 0; i < 38; i++ ) {
- System.out.print("=");
- }
- numCallsPrice = numOfCalls * 17;
- System.out.print("\n Number of calls = "+numOfCalls+" ");
- displayAsDollarsAndCents(numCallsPrice);
- priceCallInSec = totalCallInSec *3;
- System.out.print("\n Total call time (secs) = "+totalCallInSec+" ");
- displayAsDollarsAndCents(priceCallInSec);
- priceSms = sms *15;
- System.out.print("\n Number of SMS = "+sms+" ");
- displayAsDollarsAndCents(priceSms);
- priceData = dataUsage*2;
- System.out.print("\n Data usage (MB) = "+dataUsage+" ");
- displayAsDollarsAndCents(priceData);
- System.out.println("");
- for (int i = 0; i < 38; i++ ) {
- System.out.print("=");
- }
- totalCost2 = numCallsPrice + priceCallInSec + priceSms + priceData;
- System.out.print("\n TOTAL COST"+(" "));
- displayAsDollarsAndCents(totalCost2);
- System.out.println("");
- break;
- case 4:
- System.out.println("Cost under Plan C");
- for (int i = 0; i < 38; i++ ) {
- System.out.print("=");
- }
- numCallsPrice = numOfCalls * 11;
- System.out.print("\n Number of calls = "+numOfCalls+" ");
- displayAsDollarsAndCents(numCallsPrice);
- priceCallInSec = totalCallInSec *3;
- System.out.print("\n Total call time (secs) = "+totalCallInSec+" ");
- displayAsDollarsAndCents(priceCallInSec);
- priceSms = sms *9;
- System.out.print("\n Number of SMS = "+sms+" ");
- displayAsDollarsAndCents(priceSms);
- if (dataUsage <=100) {
- priceData = dataUsage*2;
- System.out.print("\n Data usage (MB) = "+dataUsage+" ");
- displayAsDollarsAndCents(priceData);
- }
- else {
- priceData = dataUsage*10;
- System.out.print("\n Data usage (MB) = "+dataUsage+" ");
- displayAsDollarsAndCents(priceData);
- }
- System.out.println("");
- for (int i = 0; i < 38; i++ ) {
- System.out.print("=");
- }
- totalCost = numCallsPrice + priceCallInSec + priceSms + priceData;
- System.out.print("\n TOTAL COST"+(" "));
- displayAsDollarsAndCents(totalCost);
- System.out.println("");
- case 5: System.out.println("Clear usage details");
- numOfCalls = 0;
- exit = 0;
- dataUsage = 0;
- sms = 0;
- callInSec = 0;
- totalCallInSec = 0;
- numCallsPrice = 0;
- priceCallInSec = 0;
- priceSms = 0;
- priceData = 0;
- totalCost = 0;
- totalCost2 = 0;
- totalCost3 =0;
- break;
- case 6:
- for (int i = 0; i < 65; i++ ) {
- System.out.print("=");
- }
- System.out.println("\nThank you for using this software. We hope you found it useful.");
- for (int i = 0; i < 65; i++ ) {
- System.out.print("=");
- }
- exit=6;
- break;
- default:System.out.println("The option selected is invalid, try again" );
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement