brainfrz

Untitled

Oct 4th, 2015
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.98 KB | None | 0 0
  1. /**************************************************************************************************
  2.  *  Program Name:     Lab #5: Call Price
  3.  *  Author:           Terry Weiss
  4.  *  Date:             September 29, 2015
  5.  *  Course/Section:   CSC 111-003W
  6.  *  Program Description:
  7.  *     This program will calculate the cost of a phone call, where the cost is a flat rate of
  8.  *  $0.99 for the first 10 minutes and then $0.10/minute after.
  9.  **************************************************************************************************/
  10.  
  11. import java.util.Scanner;
  12. import java.text.NumberFormat;
  13.  
  14.  
  15. /*
  16.  *  This class will calculate and display the cost of a phone call, where the cost is a flat rate of
  17.  *  $0.99 for the first 10 minutes and then $0.10/minute after.
  18.  *
  19.  *  Algorithm:
  20.  *  Get the length of the call in minutes
  21.  *  Calculate cost of call
  22.  *  Display length and cost of call
  23.  */
  24. public class WeissLab5
  25. {
  26.  
  27.     /*
  28.      *  This method will ask for the length of the call in minutes, then calculate and display the
  29.      *  length of the call and cost as a currency. The cost is a flat rate of $0.99 for the first
  30.      *  10 minutes and then $0.10/minute after.
  31.      *
  32.      *  Algorithm:
  33.      *  Get the length of the call in minutes
  34.      *  IF minutes == 0 THEN
  35.      *      Display "No minutes were entered."
  36.      *  ELSE
  37.      *      Set the cost of the call to FLAT_RATE
  38.      *      IF call is longer than INTRO_TIME THEN
  39.      *          Add the MINUTE_RATE per number of minutes over to the current cost
  40.      *      END IF
  41.      *      Display the length of the call in minutes and the cost as a currency
  42.      *  END IF
  43.      */
  44.     public static void main( String[] args )
  45.     {
  46.         /*
  47.          *  This is the length of the call in minutes.
  48.          */
  49.         int minutes;
  50.        
  51.         /*
  52.          *  This is the total cost of the call.
  53.          */
  54.         double cost;
  55.        
  56.         /*
  57.          *  This is the number of minutes included in the original flat rate.
  58.          *  Currently 10 minutes
  59.          */
  60.         final int INTRO_TIME = 10;
  61.        
  62.         /*
  63.          *  This is the original flat rate price for the intro period.
  64.          *  Currently $0.99
  65.          */
  66.         final double FLAT_RATE = 0.99;
  67.        
  68.         /*
  69.          *  This is the cost per minute after the intro period.
  70.          *  Currently $0.10/minute
  71.          */
  72.         final double MINUTE_RATE = 0.1;
  73.        
  74.         /*
  75.          *  This object holds the currency format.
  76.          */
  77.         NumberFormat currency_format = NumberFormat.getCurrencyInstance();
  78.  
  79.         /*
  80.          *  This object is used to capture the user's input.
  81.          */
  82.         Scanner user_input = new Scanner(System.in);
  83.  
  84.        
  85.         System.out.print("How many minutes was your call? ");
  86.         minutes = user_input.nextInt();
  87.  
  88.         if (minutes == 0)
  89.         {
  90.             System.out.println("No minutes were entered.");
  91.         } //end if minutes == 0
  92.  
  93.         else
  94.         {
  95.             cost = FLAT_RATE;
  96.             if (minutes > INTRO_TIME)
  97.             {
  98.                 cost += (minutes - INTRO_TIME) * MINUTE_RATE;
  99.             } //end if minutes > INTRO_TIME
  100.            
  101.             System.out.println("Your " + minutes + "-minute call costs " +
  102.                 currency_format.format(cost) + ".");
  103.         } //end else minutes != 0
  104.     } //end main() method
  105. } //end WeissLab5 class
  106.  
  107.  
  108. /**************************************************************************************************
  109.  *  Specified testing arguments:
  110.  *
  111.  *  9 minutes
  112.  *  > Your 9-minute call costs $0.99.
  113.  *  +PASSES
  114.  *
  115.  *  10 minutes
  116.  *  > Your 10-minute call costs $0.99.
  117.  *  +PASSES
  118.  *
  119.  *  11 minutes
  120.  *  > Your 11-minute call costs $1.09.
  121.  *  +PASSES
  122.  *
  123.  *  35 minutes
  124.  *  > Your 35-minute call costs $3.49.
  125.  *  +PASSES
  126.  *
  127.  *  0 minutes
  128.  *  > No minutes were entered.
  129.  *  +PASSES
  130.  **************************************************************************************************/
Advertisement
Add Comment
Please, Sign In to add comment