KnowledgeBoat Logo

Computer Applications

Define a class Telephone having the following description:

Class name : Telephone

Data MembersPurpose
int prv, preto store the previous and present meter readings
int callto store the calls made (i.e. pre - prv)
String nameto store name of the consumer
double amtto store the amount
double totalto store the total amount to be paid
Member functionsPurpose
void input()Stores the previous reading, present reading and name of the consumer
void cal()Calculates the amount and total amount to be paid
void display()Displays the name of the consumer, calls made, amount and total amount to be paid

Write a program to compute the monthly bill to be paid according to the given conditions and display the output as per the given format.

Calls madeRate
Up to 100 callsNo charge
For the next 100 calls90 paise per call
For the next 200 calls80 paise per call
More than 400 calls70 paise per call

However, every consumer has to pay ₹180 per month as monthly rent for availing the service.

Output:

Name of the customer    Calls made  Amount to be paid
....................    ..........  .................
....................    ..........  .................

Java

Java Classes

87 Likes

Answer

import java.util.Scanner;

public class Telephone
{
    private int prv;
    private int pre;
    private int call;
    private String name;
    private double amt;
    private double total;
    
    public void input() {
        Scanner in = new Scanner(System.in);
        System.out.print("Enter Customer Name: ");
        name = in.nextLine();
        System.out.print("Enter previous reading: ");
        prv = in.nextInt();
        System.out.print("Enter present reading: ");
        pre = in.nextInt();
    }
    
    public void cal() {
        call = pre - prv;
        if (call <= 100)
            amt = 0;
        else if (call <= 200)
            amt = (call - 100) * 0.9;
        else if (call <= 400)
            amt = (100 * 0.9) + (call - 200) * 0.8;
        else
            amt = (100 * 0.9) + (200 * 0.8) + ((call - 400) * 0.7);
            
        total = amt + 180;
    }
    
    public void display() {
        System.out.println("Name of the customer\tCalls made\tAmount to be paid");
        System.out.println(name + "\t" + call + "\t" + total);
    }
    
    public static void main(String args[]) {
        Telephone obj = new Telephone();
        obj.input();
        obj.cal();
        obj.display();
    }
}

Variable Description Table

Program Explanation

Output

BlueJ output of Define a class Telephone having the following description: Write a program to compute the monthly bill to be paid according to the given conditions and display the output as per the given format. However, every consumer has to pay ₹180 per month as monthly rent for availing the service. Output: Name of the customer Calls made Amount to be paid .................... .......... ................. .................... .......... .................

Answered By

36 Likes


Related Questions