40 likes | 56 Views
Modularized Java Phone Calc Solution. import java.util.Scanner; public class PhoneCallCostModularized { static String custAreaCode = null; static String custPhoneNum = null; static String calledAreaCode = null; static String calledPhoneNum = null; static int minutes = 0;
E N D
Modularized Java Phone Calc Solution import java.util.Scanner; public class PhoneCallCostModularized { static String custAreaCode = null; static String custPhoneNum = null; static String calledAreaCode = null; static String calledPhoneNum = null; static int minutes = 0; static double price = 0; static final double LOW_RATE = 0.10; static final double HIGH_RATE = 0.13; static final int TIME_LIMIT = 20; static Scanner keyboard = new Scanner(System.in); public static void main(String[] args) { getCallInfo(); calcCallPrice(); displayCallInfo(); }
Modularized Java Phone Calc Solution public static void getCallInfo() { // Get the from phone number System.out.println("What is the area code you are calling from?"); custAreaCode = keyboard.next(); System.out.println("What is the phone number you are calling from?"); custPhoneNum = keyboard.next(); // Get the to phone number System.out.println("What is the area code you are calling?"); calledAreaCode = keyboard.next(); System.out.println("What is the phone number you are calling?"); calledPhoneNum = keyboard.next(); // Get the length of the phone call System.out.println("In minutes, how long is the call?"); minutes = keyboard.nextInt(); }
Modularized Java Phone Calc Solution public static void calcCallPrice() { // Calculate the price of call based on area code and length of call if (!(custAreaCode.equals(calledAreaCode)) && (minutes > TIME_LIMIT)) { price = minutes * LOW_RATE; } else { price = minutes * HIGH_RATE; } } public static void displayCallInfo() { // Display the call info System.out.println("The cost of calling from " + custAreaCode + "-" + custPhoneNum + " to " + calledAreaCode + "-" + calledPhoneNum + " for "); System.out.println(minutes + " minutes is $" + price); } }