Question

In: Computer Science

JAVA Lab 9: Phone Call Write a program that will calculate the cost of a phone...

JAVA

Lab 9: Phone Call

Write a program that will calculate the cost of a phone call as follows:

  1. The first 10 minutes are charged at a flat rate of $0.99 (Not 99 cents a minute - but 99 cents for the first 10 minutes or less).
  2. This means that a phone call of 1 minute or 6 minutes or 10 minutes will be charged the same flat rate of 99 cents.
  3. Every minute after the initial 10 minutes will be charged at $0.10 per minute.
  4. Input the number of minutes talked as an integer.
  5. Using an IF/ELSE structure, check for an entry of 0 minutes first, and inform the User that no minutes were entered.
    • IF 0 minutes are entered THEN
      • output an error message stating that no minutes were entered.
    • ELSE
      • Calculate and display the results.
      • The final display will show the minutes and the final cost.
      • The price will be formatted with 2 decimal places.
    • END IF

Include all Prologue information with your program

  • Include an Initial Algorithm
  • Include Input, Output, and Formulas (if any)
  • Include a Refined Algorithm
  • Test your program thoroughly with the following data:

1. 9 minutes
2. 10 minutes
3. 11 minutes
4. 35 minutes
5. 0 minutes

NOTE 1:

  • DO NOT use the "return 0" code, end, break, or exit to force an exit from within your IF/ELSE structure.  Declare all variables within the data declaration section.
    • Let the program progress to the end of the main function.
    • The end of the main function is the only place that the “return 0” should be placed.
    • A switch statement is the only place that the break command should be placed.
  • DO NOT use the continue statement.

NOTE 2:

1. Declare all variables within the data declaration section of each class and method.  (-.1)
2   Do not get input on the same line as a variable declaration.  
(-.1)

3. Do not place an equation for computation on the same line as declaring a variable.  (-.1)
4
. Do not place an equation for computation on the same line as an input statement.  (-.1)
5. Do not place any computations within an output statement. (-.1)

Solutions

Expert Solution

PFB PhoneCall java class source code.

Solution summary :

Program ask the user to enter call minutes and print the cost ($0.99/min for first 10 minutes , after that $0.10/min)
Displays error if , minutes entered is equal to or less than 0.

Finally it displays the call minutes and call cost.

Note : Program is tested for all asked test cases.

--------------
PhoneCall.java
--------------
import java.util.Scanner;

public class PhoneCall{

//driver method
public static void main(String[] args){

//Input the number of minutes talked as an integer.
int callTimeInMinutes;

//To store total call cost
double totalCallCost=0.0;
  
Scanner s = new Scanner(System.in);
  
System.out.print("Enter the call time in minutes : ");
callTimeInMinutes = s.nextInt();

//Checking if minutes entered is not less than or equal to 0.
//output an error message stating that no minutes were entered.
if(callTimeInMinutes<=0){
System.out.println("\nNo minutes were entered!");
}else{

//The first 10 minutes are charged at a flat rate of $0.99 or 99 cents
//Every minute after the initial 10 minutes will be charged at $0.10 per minute.
if(callTimeInMinutes>10){
totalCallCost=totalCallCost+(10*0.99) + ((callTimeInMinutes-10)*(0.10));
}else{
//calculate if minutes are less than or equal to 10
totalCallCost=totalCallCost+(callTimeInMinutes*0.99);
}
}

//Displaying call minutes ans call cost
System.out.println("\nCall minutes : " + callTimeInMinutes);

//The price will be formatted with 2 decimal places.
System.out.println("Call cost : " + String.format("%.2f", totalCallCost));

s.close();

}
}
--------------

Output of asked inputs :
------------------------


------------------------

Let me know, if any further help is required.


Related Solutions

Write a Java program in Eclipse to calculate the total cost to enter into a waterpark...
Write a Java program in Eclipse to calculate the total cost to enter into a waterpark for a family/group Ticket rates are listed below kids (Age 12 and under)=$ 12.50 Regular( Age between12 -55) =$ 18.25 Seniors (55 and above) = $15.00 Tax =7% Your program should ask the user to enter the total number of members in their group. User needs to enter the ages for all members. Write appropriate error messages for invalid entries. An array should be...
in java Write a Java Program that displays a menu with five different options: 1. Lab...
in java Write a Java Program that displays a menu with five different options: 1. Lab Test Average Calculator 2. Dice Roll 3. Circle Area Calculator 4. Compute Distance 5. Quit The program will display a menu with each of the options above, and then ask the user to enter their choice. There is also a fifth option to quit, in which case, the program will simply display a goodbye message. Based on the user’s choice, one of the options...
For this lab, you will write a C++ program that will calculate the matrix inverse of...
For this lab, you will write a C++ program that will calculate the matrix inverse of a matrix no bigger than 10x10. I will guarantee that the matrix will be invertible and that you will not have a divide by 0 problem. For this program, you are required to use the modified Gaussian elimination algorithm. Your program should ask for the size (number of rows only) of a matrix. It will then read the matrix, calculate the inverse, and print...
For this lab, you will write a C++ program that will calculate the matrix inverse of...
For this lab, you will write a C++ program that will calculate the matrix inverse of a matrix no bigger than 10x10. I will guarantee that the matrix will be invertible and that you will not have a divide by 0 problem. For this program, you are required to use the modified Gaussian elimination algorithm. Your program should ask for the size (number of rows only) of a matrix. It will then read the matrix, calculate the inverse, and print...
For this lab, you will write a C++ program that will calculate the matrix inverse of...
For this lab, you will write a C++ program that will calculate the matrix inverse of a matrix no bigger than 10x10. I will guarantee that the matrix will be invertible and that you will not have a divide by 0 problem. For this program, you are required to use the modified Gaussian elimination algorithm. Your program should ask for the size (number of rows only) of a matrix. It will then read the matrix, calculate the inverse, and print...
Assignment Purpose The purpose of this lab is to write a well commented java program that...
Assignment Purpose The purpose of this lab is to write a well commented java program that demonstrates the use of one dimensional arrays and methods.(Need Comment, Write by Java Code) Instructions Write a method rotateArray that is passed to an array, x, of integers (minimum 7 numbers) and an integer rotation count, n. x is an array filled with randomly generated integers between 1 and 100. The method creates a new array with the items of x moved forward by...
Assignment Purpose The purpose of this lab is to write a well commented java program that...
Assignment Purpose The purpose of this lab is to write a well commented java program that demonstrates the use and re-use of methods with input validation. Instructions It is quite interesting that most of us are likely to be able to read and comprehend words, even if the alphabets of these words are scrambled (two of them) given the fact that the first and last alphabets remain the same. For example, “I dn'ot gvie a dman for a man taht...
Assignment Purpose The purpose of this lab is to write a well commented java program that...
Assignment Purpose The purpose of this lab is to write a well commented java program that demonstrates the use of one dimensional arrays and methods. Instructions Write a method rotateArray that is passed to an array, x, of integers (minimum 7 numbers) and an integer rotation count, n. x is an array filled with randomly generated integers between 1 and 100. The method creates a new array with the items of x moved forward by n Elements that are rotated...
• This lab, you will write a Java program to determine if a given Sudoku puzzle...
• This lab, you will write a Java program to determine if a given Sudoku puzzle is valid or not. • You determine if the puzzle is complete and valid, incomplete, or is invalid. • A puzzle is a 2-dimensional array 9x9 array. Each element contains the numbers 1 – 9. A space may also contain a 0 (zero), which means the spot is blank. • If you don’t know how a Sudoku Puzzle works, do some research, or download...
Assignment Purpose The purpose of this lab is to write a well commented java program that...
Assignment Purpose The purpose of this lab is to write a well commented java program that demonstrates the use of two dimensional arrays, input validation, and methods. (Write by Java Code, Need Comment) Instructions A theater seating chart is implemented as a two-dimensional array of ticket prices, like this: Seat Ticket Price 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT