Answer to Question #230498 in Java | JSP | JSF for arz

Question #230498

Regular service: $10.00 plus first 50 min. are free. Charges for over 50 min. are $0.20 per minPrem. service: $25.00 plus: calls made from 6:00 a.m. to 6:00 p.m., the first 75 min. are free; charges for over 75 minutes are $0.10 per mincalls made from 6:00 p.m. to 6:00 a.m., the first 100 minutes are free; charges for over 100 minutes are $0.05 per minprogram should prompt the user to enter an account num, a service code (type char), and the number of minutes the service was used. A service code of r or R means regular service; a service code of p means prem service. Treat any other character as an error. Your program should output the account number, type of service, number of min. the telephone service was used, and the amount due from the user. For the premium service, the customer may be using the service during the day and the night., to calculate the bill, you must ask the user to input the number of min the service was used during the day and the number of minutes the service was used during the night.


1
Expert's answer
2021-08-29T00:57:32-0400
import java.util.Scanner;


public class Service {


	
	public static void main(String[] args) {
		
		Scanner input = new Scanner(System.in);
		System.out.print("Enter the account number: ");
		String accountNumber = input.nextLine();
		System.out.print("Select service code R - Regular, P - Premium: ");
		char serviceCode = input.nextLine().toLowerCase().charAt(0);
		System.out.print("Enter the number of minutes: ");
		int numberMinutes=input.nextInt();
		float amountDue=0;
		if(serviceCode=='r') {
			//Regular service: $10.00 plus first 50 min. are free. 
			//Charges for over 50 min. are $0.20 per min
			amountDue+=10.0;
			if(numberMinutes>50) {
				amountDue+=0.20*(numberMinutes-50);
			}
			System.out.println("Account number: "+accountNumber);
			System.out.println("Type of service: Regular");
			System.out.println("Number of minutes: "+numberMinutes);
			System.out.printf("Amount due: %.2f\n",amountDue);
		}else if(serviceCode=='p') {
			//Prem. service: $25.00 plus: calls made from 6:00 a.m. to 6:00 p.m., the first 75 min. are free; 
			//charges for over 75 minutes are $0.10 per min calls made from 6:00 p.m. to 6:00 a.m., 
			//the first 100 minutes are free; charges for over 100 minutes are $0.05 per min
			System.out.print("Enter the number of minutes the service was used during the night: ");
			int numberMinutesNight=input.nextInt();
			amountDue+=25.0;
			if(numberMinutes>75) {
				amountDue+=0.10*(numberMinutes-75);
			}
			if(numberMinutesNight>100) {
				amountDue+=0.05*(numberMinutesNight-100);
			}
			
			System.out.println("Account number: "+accountNumber);
			System.out.println("Type of service: Premium");
			System.out.println("Number of minutes: "+numberMinutes);
			System.out.println("Number of minutes the service was used during the night: "+numberMinutesNight);
			System.out.printf("Amount due: %.2f\n",amountDue);
		}else {
			System.out.println("\nWrong service code.\n");	
		}
		
		input.close();
	}
}





Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS