Answer to Question #314726 in Java | JSP | JSF for Abdallah

Question #314726

Write a program that calculates and prints the bill for a cellular telephone company.

1
Expert's answer
2022-03-20T06:20:23-0400
import java.util.Scanner;


class Bill {
	private int bno;
	private String name;
	private int call;
	private double amt;


	public Bill() {
		bno = 0;
		name = "";
		call = 0;
		amt = 0.0;
	}


	public Bill(int bno, String name, int call) {
		this.bno = bno;
		this.name = name;
		this.call = call;
	}


	public void calculate() {
		double charge;
		if (call <= 100)
			charge = call * 0.6;
		else if (call <= 200)
			charge = 60 + ((call - 100) * 0.8);
		else if (call <= 300)
			charge = 60 + 80 + ((call - 200) * 1.2);
		else
			charge = 60 + 80 + 120 + ((call - 300) * 1.5);


		amt = charge + 125;
	}


	public void display() {
		System.out.println("Bill No: " + bno);
		System.out.println("Name: " + name);
		System.out.println("Calls: " + call);
		System.out.println("Amount Payable: " + amt);
	}
};


public class App {
	/** Main Method */
	public static void main(String[] args) {
		Scanner keyBoard = new Scanner(System.in);
		System.out.print("Enter Name: ");
		String name = keyBoard.nextLine();
		System.out.print("Enter Bill Number: ");
		int bno = keyBoard.nextInt();
		System.out.print("Enter Calls: ");
		int call = keyBoard.nextInt();
		Bill objBill = new Bill(bno, name, call);
		objBill.calculate();
		objBill.display();
		keyBoard.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