Java
Programs-
Project
By Sri Krishna 9V
Program1: Write a program to calculate the incentive of an employee as per the following data:
Sale Amount Incentive
More than or equal to 1,00,000 35% of sale amount
Sale Amount Incentive
80,000 to 99,999 30% of sale amount
60,000 to 79,999 20% of sale amount
40,000 to 59,999 15% of sale amount
Less than 40,000 10% of sale amount
Create the following methods:
void input()
Input employee name, employee ID, and sale amount.
void calculate()
Calculate the incentive earned based on the above table.
void output()
Print the employee name, employee ID, sale amount, and incentive earned.
void main()
Create an object of the class and call all the above methods.
import [Link];
class Employee {
String name;
String empId;
double saleAmount;
double incentive;
// Method to input employee details
void input() {
Scanner sc = new Scanner([Link]);
[Link]("Enter employee name: ");
name = [Link]();
[Link]("Enter employee ID: ");
empId = [Link]();
[Link]("Enter sale amount: ");
saleAmount = [Link](); // Use nextDouble() directly here
// Method to calculate incentive based on sale amount
void calculate() {
if (saleAmount >= 100000) {
incentive = 0.35 * saleAmount;
} else if (saleAmount >= 80000) {
incentive = 0.30 * saleAmount;
} else if (saleAmount >= 60000) {
incentive = 0.20 * saleAmount;
} else if (saleAmount >= 40000) {
incentive = 0.15 * saleAmount;
} else {
incentive = 0.10 * saleAmount;
// Method to display employee details and incentive
void output() {
[Link]("\n--- Employee Details ---");
[Link]("Name: " + name);
[Link]("Employee ID: " + empId);
[Link]("Sale Amount: ₹" + saleAmount);
[Link]("Incentive Earned: ₹" + incentive);
// Main method to run the program
public static void main(String[] args) {
Employee emp = new Employee();
[Link]();
[Link]();
[Link]();
Program 2: Income Tax Calculation for Male Citizens Below 65
Given below is a hypothetical table showing rates of Income Tax for male citizens below the age of
65 years:
Taxable Income (TI) Income Tax (in ₹)
Does not exceed ₹1,60,000 Nil
> ₹1,60,000 and ≤ ₹5,00,000 (TI - 1,60,000) × 10%
> ₹5,00,000 and ≤ ₹8,00,000 (TI - 5,00,000) × 20% + ₹34,000
> ₹8,00,000 (TI - 8,00,000) × 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 gender is female, display: "Tax not applicable".
Otherwise, compute and display the income tax payable as per the table.
import [Link]
class IncomeTaxCalculator {
// Method to input the age, gender, and taxable income
void input() {
Scanner sc = new Scanner([Link]);
[Link]("Enter age: ");
int age = [Link]();
[Link]("Enter gender (male/female): ");
String gender = [Link]().toLowerCase();
[Link]("Enter taxable income: ₹");
double taxableIncome = [Link]();
// Check tax applicability based on age and gender
if (age > 65 || [Link]("female")) {
[Link]("Tax not applicable");
} else {
// Calculate income tax for males under 65 years
double tax = calculateTax(taxableIncome);
[Link]("Income tax payable: ₹" + tax);
}
// Method to calculate income tax as per the given table
double calculateTax(double taxableIncome) {
double tax = 0;
if (taxableIncome <= 160000) {
tax = 0; // No tax for incomes up to ₹1,60,000
} else if (taxableIncome <= 500000) {
tax = (taxableIncome - 160000) * 0.10;
} else if (taxableIncome <= 800000) {
tax = ((taxableIncome - 500000) * 0.20) + 34000;
} else {
tax = ((taxableIncome - 800000) * 0.30) + 94000;
return tax;
public static void main(String[] args) {
IncomeTaxCalculator calculator = new IncomeTaxCalculator();
[Link]();
}
Program3:
Design a class to input the Principal amount (P), Rate (R), and Time (T).
Calculate and print the Compound Interest (CI) using the formula:
A = P * (1 + R/100)^T
CI = A - P
import [Link];
class CompoundInterest {
// Method to input principal, rate, and time
void input() {
Scanner sc = new Scanner([Link]);
// Taking inputs for principal, time, and rate
[Link]("Enter principal amount: ");
double principal = [Link]();
[Link]("Enter time (in years): ");
double time = [Link]();
[Link]("Enter rate of interest: ");
double rate = [Link]();
// Calculating Compound Interest
double compoundInterest = calculateCI(principal, rate, time);
// Outputting the results
[Link]("Principal amount: " + principal);
[Link]("Time: " + time);
[Link]("Rate of interest: " + rate);
[Link]("Compound Interest: " + compoundInterest);
// Method to calculate Compound Interest (CI)
double calculateCI(double principal, double rate, double time) {
// Formula to calculate compound interest
double amount = principal * [Link]((1 + rate / 100), time);
return amount - principal; // CI = A - P
public static void main(String[] args) {
CompoundInterest ci = new CompoundInterest();
[Link]();
}
Program4:Design a class Railway to calculate the ticket amount based on the selected train:
[Link] Name of the Train Ticket Amount (₹)
1 Venkatadri Express 900
2 Rameshwaram Express 1100
3 Krishna Express 1300
4 Godavari Express 1500
Write a program to:
Input the name of the train (via number 1–4) and name of the traveler.
Calculate the ticket price using an if-else ladder.
import [Link];
class Railway {
// Method to input train selection and traveler details
void input() {
Scanner sc = new Scanner([Link]);
// Display the train options
[Link]("Choose the train:\nEnter");
[Link]("1. Venkatadri Express");
[Link]("2. Rameshwaram Express");
[Link]("3. Krishna Express");
[Link]("4. Godavari Express");
[Link]("Enter your choice (1-4): ");
int choice = [Link]();
// Get the traveler name
[Link]("Enter the name of the traveler: ");
[Link](); // Consume newline
String travelerName = [Link]();
// Initialize ticket price to 0
double ticketAmount = 0;
String trainName = "";
// If-else ladder to select the correct train and ticket amount
if (choice == 1) {
trainName = "Venkatadri Express";
ticketAmount = 900;
} else if (choice == 2) {
trainName = "Rameshwaram Express";
ticketAmount = 1100;
} else if (choice == 3) {
trainName = "Krishna Express";
ticketAmount = 1300;
} else if (choice == 4) {
trainName = "Godavari Express";
ticketAmount = 1500;
} else {
trainName = "Invalid Train";
ticketAmount = 0;
// Output the details
[Link]("\nName of the traveler: " + travelerName);
[Link]("Name of the train: " + trainName);
[Link]("Ticket amount: " + ticketAmount);
public static void main(String[] args) {
Railway railway = new Railway();
[Link]();
Progrm5:
Define a class to verify the Triangle Inequality Theorem, i.e., a triangle can be formed from three
sides if and only if the sum of the lengths of any two sides is greater than the third side.
Input the lengths of three sides (s1, s2, s3).
First, check if the triangle can be formed.
If it can be formed:
o Check whether it's Equilateral, Isosceles, or Scalene.
Hints:
Equilateral Triangle: all 3 sides equal
Isosceles Triangle: any 2 sides equal
Scalene Triangle: all 3 sides unequal
import [Link];
class Triangle {
// Method to check if the triangle can be formed and classify it
void verifyTriangle() {
Scanner sc = new Scanner([Link]);
// Input the three sides of the triangle
[Link]("Enter side1: ");
double s1 = [Link]();
[Link]("Enter side2: ");
double s2 = [Link]();
[Link]("Enter side3: ");
double s3 = [Link]();
// Check if the sides satisfy the Triangle Inequality Theorem
if (s1 + s2 > s3 && s2 + s3 > s1 && s1 + s3 > s2) {
[Link]("Triangle can be formed");
// Classify the type of triangle based on the sides
if (s1 == s2 && s2 == s3) {
[Link]("The triangle is Equilateral");
} else if (s1 == s2 || s2 == s3 || s1 == s3) {
[Link]("The triangle is Isosceles");
} else {
[Link]("The triangle is Scalene");
} else {
[Link]("Triangle cannot be formed");
public static void main(String[] args) {
Triangle triangle = new Triangle();
[Link]();
Program 6:
An electronic shop has announced seasonal discounts on Laptops and Desktops based on the
purchase amount:
Purchase Amount (₹) Laptop Discount Desktop Discount
0 – 25,000 0% 5.0%
25,001 – 57,000 5.0% 7.5%
57,001 – 1,00,000 7.5% 10.0%
More than 1,00,000 10.0% 15.0%
Write a program to:
Input the customer’s name, address, purchase amount, and type of purchase (l for laptop, d
for desktop).
Compute and print the net amount to be paid along with the name and address of the
customer.
import [Link];
class ElectronicShop {
// Method to calculate the net amount after applying discount
void calculateAmount() {
Scanner sc = new Scanner([Link]);
// Input customer details
[Link]("Enter your name: ");
String name = [Link]();
[Link]("Enter your address: ");
String address = [Link]();
[Link]("Enter amount to purchase: ₹");
double purchaseAmount = [Link]();
[Link]("Enter type of purchase (l for laptop, d for desktop): ");
char typeOfPurchase = [Link]().charAt(0);
// Initialize discount and final price
double discount = 0;
double netAmount = purchaseAmount;
// Calculate the discount based on the type of purchase and the amount
if (typeOfPurchase == 'l' || typeOfPurchase == 'L') {
// Discount for laptop
if (purchaseAmount <= 25000) {
discount = 0;
} else if (purchaseAmount <= 57000) {
discount = 5.0;
} else if (purchaseAmount <= 100000) {
discount = 7.5;
} else {
discount = 10.0;
} else if (typeOfPurchase == 'd' || typeOfPurchase == 'D') {
// Discount for desktop
if (purchaseAmount <= 25000) {
discount = 5.0;
} else if (purchaseAmount <= 57000) {
discount = 7.5;
} else if (purchaseAmount <= 100000) {
discount = 10.0;
} else {
discount = 15.0;
} else {
[Link]("Invalid type of purchase.");
return;
}
// Calculate the discount and net amount
double discountAmount = (purchaseAmount * discount) / 100;
netAmount = purchaseAmount - discountAmount;
// Output the final result
[Link]("\n--- Customer Details ---");
[Link]("Name: " + name);
[Link]("Address: " + address);
[Link]("Amount to purchase: ₹" + purchaseAmount);
[Link]("Type of purchase: " + (typeOfPurchase == 'l' || typeOfPurchase == 'L' ?
"Laptop" : "Desktop"));
[Link]("Discount: " + discount + "%");
[Link]("Discount amount: ₹" + discountAmount);
[Link]("Net amount to be paid: ₹" + netAmount);
public static void main(String[] args) {
ElectronicShop shop = new ElectronicShop();
[Link]();
}
----------------------------------------------------------THE END----------------------------------------------------------------