Input name of a subscriber, mobile number, previous reading and present reading.
Find number of calls, phone charge and print a bill. The charge is Rs. 0.80 per call.
import java.util.*;
public class Mobile
{
public static void main()
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter name, mobile number, previous and present reading");
Input previous reading and present reading. Find number of calls, mobile charge and print a bill.
If the calls are above 50 then the charge is Rs. 0.80 per unit. (Otherwise no charge). Use simple if.
import java.util.*;
public class Mobile
{
public static void main()
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter previous and present reading");
Input previous reading and present reading. Find the mobile charge and print a bill.
For the first 50 calls the charge is Rs. 0.0 per unit. For remaining calls Rs. 0.80 per unit.
import java.util.*;
public class Mobile
{
public static void main()
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter previous and present reading");
Input previous reading and present reading. Find mobile charge and print a bill.
For the first 50 calls the charge is Rs. 0.0 per unit. Next 50 calls Rs. 0.80 per unit.
For remaining calls Rs. 1.20 per unit.
import java.util.*;
public class Mobile
{
public static void main()
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter previous and present reading");
Input previous reading and present reading. Find mobile charge and print a bill.
For the first 50 calls charge is Rs. 0.80 per call.
For remaining calls Rs. 1.00 per call.
For BSNL employees 60% reduction.
import java.util.*;
public class Mobile
{
public static void main()
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter previous and present reading");
Input n subscribers’ names and number of calls. Find mobile charge and print a bill
for each subscriber. Also find total collection. For first 50 calls charge is Rs. 0.80 per unit.
Remaining calls Rs. 1.00 per unit.
import java.util.*;
public class Mobile
{
public static void main()
{
Scanner sc=new Scanner(System.in);
System.out.print("Enter number of subscribers: ");
int n=sc.nextInt();
double tot=0.0;
for(int i=1;i<=n;i++)
{
System.out.println("Enter name and number of calls");
String name= sc.nextLine();
int calls=sc.nextInt();
double charge;
if(calls<=50)
charge= calls*0.80;
else
charge= 50*0.80+(calls-50)*1.0;
tot+=charge;
System.out.println("Name: "+name);
System.out.println("Calls: "+calls);
System.out.println("Charge: "+charge);
}
System.out.println("Total collection: "+tot);
}
}
4.1 S D Array:
Input n subscribers’ consumer numbers, names and number of calls into three arrays. Find mobile charge
of each subscriber and store them into another array. Input a search number; print the details of the subscriber.
(Use binary search as the consumer numbers are in ascending order)
For first 50 calls charge is Rs. 0.80 per unit.
Remaining calls Rs. 1.00 per unit.
import java.util.*;
public class Bill
{
public static void main()
{
Scanner sc=new Scanner(System.in);
System.out.print("Enter number of subscribers: ");
int n=sc.nextInt();
int cn[] = new int[n];
String name[] = String[n];
int calls[] = int[n];
double charge[] = double[n];
for(int i=0;i<n;i++)
{
System.out.println("Enter number, name and number of calls");
Define a class MobileBill. Data members: name, calls, charge.
Member methods: 1) getData() - to input name and calls.
2) compute() – to find mobile charge:
First 50 units: 0.80 per unit. Next 50 units: 1.00 per unit: Remaining units: 1.20 per unit.
3) display() – to print the bill. Write main() also.