1 / 4

Modularized Java Phone Calc Solution

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;

smithashley
Download Presentation

Modularized Java Phone Calc Solution

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 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(); }

  2. 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(); }

  3. 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); } }

  4. Modularized Java Phone Calc Test

More Related