0% found this document useful (0 votes)
20 views7 pages

2023 Table

The document contains Java class implementations for various scenarios including a showroom for calculating discounts on purchases, a bike rental system for computing charges based on rental days, a travel agency calculating ticket discounts, and an income tax calculation based on taxable income. Each class includes methods for inputting data, calculating values, and displaying results. The examples illustrate object-oriented programming principles and basic control structures in Java.

Uploaded by

Ashish Rajput
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views7 pages

2023 Table

The document contains Java class implementations for various scenarios including a showroom for calculating discounts on purchases, a bike rental system for computing charges based on rental days, a travel agency calculating ticket discounts, and an income tax calculation based on taxable income. Each class includes methods for inputting data, calculating values, and displaying results. The examples illustrate object-oriented programming principles and basic control structures in Java.

Uploaded by

Ashish Rajput
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

1

Design a class name ShowRoom with the following description:

Instance variables / Data members:


String name — To store the name of the customer
long mobno — To store the mobile number of the customer
double cost — To store the cost of the items purchased
double dis — To store the discount amount
double amount — To store the amount to be paid after discount

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

Cost Discount (in percentage)


Less than or equal to ₹10000 5%
More than ₹10000 and less than or equal to ₹20000 10%
More than ₹20000 and less than or equal to ₹35000 15%
More than ₹35000 20%
void display() — To display customer name, mobile number, amount to be paid
after discount.

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:

Data Members Purpose

int bno To store the bike number


int phno To store the phone number of the customer
String name To store the name of the customer
int days To store the number of days the bike is taken on rent
int charge To calculate and store the rental charge

Member Methods Purpose

void input() To input and store the details of the customer


void compute() To compute the rental charge
void display() To display the details in the given format
The rent for a mobike is charged on the following basis:

Days Charge

For first five days ₹500 per day


For next five days ₹400 per day
Rest of the days ₹200 per day
Output:

Bike No. Phone No. Name No. of days Charge


xxxxxxx xxxxxxxx xxxx xxx xxxxxx

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:

Ticket Amount Discount


Above Rs. 70000 18%
Rs. 55001 to Rs. 70000 16%
Rs. 35001 to Rs. 55000 12%
Rs. 25001 to Rs. 35000 10%
Less than Rs. 25001 2%
Write a program to input the name and ticket amount for the customer and
calculate the discount amount and net amount to be paid. Display the output
in the following format for each customer:
Sl. No. Name Ticket Charges Discount Net Amount
(Assume that there are 15 customers, first customer is given the serial no (SI.
No.) 1, next customer 2 …….. and so on)

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:

Taxable income (TI) in ₹ Income Tax in ₹


Does not exceed Rs. 1,60,000 Nil
Is greater than Rs. 1,60,000 and less (TI - 1,60,000) x 10%
than or equal to Rs. 5,00,000.
Is greater than Rs. 5,00,000 and less [(TI - 5,00,000) x 20%] + 34,000
than or equal to Rs. 8,00,000
Is greater than Rs. 8,00,000 [(TI - 8,00,000) x 30%] + 94,000
Write a program to input the age, gender (male or female) and Taxable Income
of a person.
If the age is more than 65 years or the gender is female, display “wrong
category”. If the age is less than or equal to 65 years and the gender is male,
compute and display the income tax payable as per the table given above.

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;

if (age > 65 || gender.equalsIgnoreCase("female"))


{
System.out.print("Wrong Category");
}
else
{
if (ti <= 160000)
tax = 0;
else if (ti <= 500000)
tax = (ti - 160000) * 10 / 100;
else if (ti <= 800000)
tax = 34000 + ((ti - 500000) * 20 / 100);
else
tax = 94000 + ((ti - 800000) * 30 / 100);
System.out.println("Tax Payable: " + tax);
}
}
}

You might also like