Assignment-2

Assignment-2 A class TelCall calculates the monthly phone bill of a consumer. Some of the members of the class are given below. Class name- TelCall Data member- Phno- Phone no. Name- name of the consumer N- no. of calls made Amt- bill amount Methods- Void compute()- to calculate the phone bill amount based on the slabs given below. No. of calls Rate (Rs.) 1-100 500/- :: Rental 101-200 Rs. 1/call + Rental 201-300 Rs 1.20/call + Rental above 300 Rs. 1.50/call + Rental [the calculations need to be done as per the slabs] Void dispdata()- to display the details in specified format . constructor- to assign values to data members. Specify the class TelCall giving the details of the constructor, void compute() and void dispdata(). In the main function, create an object of type TelCall and display the phone bill in the following format: Phone no. Name Total calls Amount xxxxxxxxxx xx xx xxx Source Code: import java.io.*; class Telcall { String Phno,Name; int N; double Amt; Telcall(String s1,String s2,int x) { Phno=s1; Name=s2; N=x; Amt=0; } void compute() { if(N>=1 && N<=100) Amt=500; else if(N>=101 && N<=200) Amt=500+((N-100)*1); else if(N>=201 && N<=300) Amt=500+((N-100)*1.2); else if(N>300) Amt=500+((N-100)*1.5); } void dispdata() { System.out.println("Phone no. Name Total Calls Amount"); System.out.println(Phno+" "+Name+" "+N+" "+Amt); } } ************MAIN CLASS************* class main { public static void main(String ars[])throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); System.out.println("Enter Phone Number:"); String s1=br.readLine(); System.out.println("Enter Name:"); String s2=br.readLine(); System.out.println("Enter No. of calls:"); int x=Integer.parseInt(br.readLine()); Telcall ob=new Telcall(s1,s2,x); ob.compute(); ob.dispdata(); } } OUTPUT: D:\java>javac assignment2.java D:\java>java main Enter Phone Number: 9878787878 Enter Name: Ramesh Enter No. of calls: 345 Phone no. Name Total Calls Amount 9878787878 Ramesh 345 867.5

Share:

0 comments