Math, asked by mansiyuvrajbansode30, 1 day ago

Define a class Telephone having the following description:
Data members int prv,pre
: to store the previous and present meter readings
int call : to store the calls made
String name : to store name of the consumer
double amt
: to store the amount
double total : to store the total amount to be paid
Member functions:
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 made
Rate
Up to 100 calls
No charge
For the next 100 calls
90 paise per calls
80 paise per calls
For the next 200 calls
More than 400 calls
70 paise per calls
However, every consumer has to pay 180 per month as monthly rent for availing the
service.
solve with import java ​

Answers

Answered by anirudhsharathchandr
3

Step-by-step explanation:

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();

}

}

Similar questions