2023 Table
2023 Table
Member methods:
ShowRoom() — default constructor to initialize data members
void input() — To input customer name, mobile number, cost
void calculate() — To calculate discount on the cost of purchased items, based
on following criteria
Write a main method to create an object of the class and call the above
member methods.
import java.util.*;
public class ShowRoom
{
String name;
long mobno;
double cost, dis,amount;
public ShowRoom()
{
name = "";mobno = 0;cost = 0.0;dis = 0.0;amount = 0.0;
}
public void input()
{
Scanner sc = new Scanner(System.in);
System.out.print("Enter customer name: ");
name = sc.nextLine();
System.out.print("Enter customer mobile no: ");
mobno = sc.nextLong();
System.out.print("Enter cost: ");
cost = sc.nextDouble();
}
public void calculate()
{
int disPercent = 0;
if (cost <= 10000)
disPercent = 5;
else if (cost <= 20000)
disPercent = 10;
else if (cost <= 35000)
disPercent = 15;
else
disPercent = 20;
dis = cost * disPercent / 100.0;
amount = cost - dis;
}
public void display()
{
System.out.println("Customer Name: " + name);
System.out.println("Mobile Number: " + mobno);
System.out.println("Amout after discount: " + amount);
}
public static void main(String args[])
{
ShowRoom obj = new ShowRoom();
obj.input();
obj.calculate();
obj.display();
}
}
2
Define a class called 'Mobike' with the following specifications:
Days Charge
import java.util.*;
public class Mobike
{
int bno,phno,days,charge;
String name;
public void input()
{
Scanner sc = new Scanner(System.in);
System.out.print("Enter Customer Name: ");
name = sc.nextLine();
System.out.print("Enter Customer Phone Number: ");
phno = sc.nextInt();
System.out.print("Enter Bike Number: ");
bno = sc.nextInt();
System.out.print("Enter Number of Days: ");
days = sc.nextInt();
}
public void compute()
{
if (days <= 5)
charge = days * 500;
else if (days <= 10)
charge = (5 * 500) + ((days - 5) * 400);
else
charge = (5 * 500) + (5 * 400) + ((days - 10) * 200);
}
public void display()
{
System.out.println("Bike No.\tPhone No.\tName\tNo. of days \tCharge");
System.out.println(bno + "\t" + phno + "\t" + name + "\t" + days
+ "\t" + charge);
}
public static void main(String args[])
{
Mobike obj = new Mobike();
obj.input();
obj.compute();
obj.display();
}
}
3
Shasha Travels Pvt. Ltd. gives the following discount to its customers:
import java.util.*;
public class ShashaTravel
{
public static void main(String args[])
{
Scanner in = new Scanner(System.in);
String names[] = new String[15];
int amounts[] = new int[15];
for (int i = 0; i < 15; i++)
{
System.out.print("Enter " + "Customer " + (i+1) + " Name: ");
names[i] = in.nextLine();
System.out.print("Enter " + "Customer " + (i+1) + " Ticket Charges: ");
amounts[i] = in.nextInt();
in.nextLine();
}
System.out.println("Sl. No.\tName\t\tTicket Charges\tDiscount\t\tNet
Amount");
for (int i = 0; i < 15; i++)
{
int dp = 0;
int amt = amounts[i];
if (amt > 70000)
dp = 18;
else if (amt >= 55001)
dp = 16;
else if (amt >= 35001)
dp = 12;
else if (amt >= 25001)
dp = 10;
else
dp = 2;
double disc = amt * dp / 100.0;
double net = amt - disc;
System.out.println((i+1) + "\t" + names[i] + "\t" + amounts[i] + "\t\t" +
disc + "\t\t" + net);
}
}
}
4
Given below is a hypothetical table showing rates of income tax for male
citizens below the age of 65 years:
import java.util.*;
class Test
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
System.out.print("Enter Gender(male/female): ");
String gender = in.nextLine();
System.out.print("Enter Age: ");
int age = sc.nextInt();
System.out.print("Enter Taxable Income: ");
double ti = sc.nextDouble();
double tax = 0.0;