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

Class 9 Project Second

Really don't know what you love is a great day cod zombies and how much you you love is a great
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views7 pages

Class 9 Project Second

Really don't know what you love is a great day cod zombies and how much you you love is a great
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

CLASS 9

PROJECT

1.
import java.util.Scanner;
class ElectricBill
{
// Instance variables
String n; // To store the name of the customer
int units; // To store the number of units consumed
double bill; // To store the amount to be paid
// Method to accept the name of the customer and number of units consumed
void accept()
{
Scanner scanner = new Scanner(System.in);
System.out.print("Enter the name of the customer: ");
n = scanner.nextLine();
System.out.print("Enter the number of units consumed: ");
units = scanner.nextInt();
}
// Method to calculate the bill as per the given tariff
void calculate() {
if (units <= 100)
{
bill = units * 2.00;
} else if (units <= 300)
{
bill = (100 * 2.00) + ((units - 100) * 3.00);
} else
{
bill = (100 * 2.00) + (200 * 3.00) + ((units - 300) * 5.00);
// Apply surcharge if units are above 300
bill += bill * 0.025;
}
}
// Method to print the details
void print()
{
System.out.println("Name of the customer: " + n);
System.out.println("Number of units consumed: " + units);
System.out.println("Bill amount: Rs. " + bill);
}
// Main method to create an object of ElectricBill and call the member methods
public static void main()
{
ElectricBill ob = new ElectricBill();
ob.accept();
ob.calculate();
ob.print();
}
}

Page 1 of 7
CLASS 9
PROJECT

/*Output
* Enter the name of the customer: Amit Kumar Singh
Enter the number of units consumed: 246
Name of the customer: Amit Kumar Singh
Number of units consumed: 246
Bill amount: Rs. 638.0
*/

2.
import java.util.*;
class ShowRoom
{
// Instance variables
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
// Default constructor to initialize data members
ShowRoom()
{
name = "";
mobno = 0;
cost = 0.0;
dis = 0.0;
amount = 0.0;
}
// Method to input customer name, mobile number, and cost
void input() {
Scanner sc = new Scanner(System.in);
System.out.print("Enter the name of the customer: ");
name = sc.nextLine();
System.out.print("Enter the mobile number of the customer: ");
mobno = sc.nextLong();
System.out.print("Enter the cost of the items purchased: ₹ ");
cost = sc.nextDouble();
}

// Method to calculate discount based on the cost


void calculate() {
if (cost <= 10000) {
dis = cost * 0.05; // 5% discount
} else if (cost <= 20000) {
dis = cost * 0.10; // 10% discount
} else if (cost <= 35000) {
dis = cost * 0.15; // 15% discount
} else {

Page 2 of 7
CLASS 9
PROJECT

dis = cost * 0.20; // 20% discount


}
amount = cost - dis; // Amount to be paid after discount
}

// Method to display customer name, mobile number, and amount to be paid after discount
void display() {
System.out.println("Name of the customer: " + name);
System.out.println("Mobile number of the customer: " + mobno);
System.out.println("Amount to be paid after discount: ₹ " + String.format("%.2f", amount));
}

// Main method to create an object of ShowRoom and call the member methods
public static void main()
{
ShowRoom sr = new ShowRoom();
sr.input();
sr.calculate();
sr.display();
}
}

/* Output
* Enter the name of the customer: Ram Kumar Saha
Enter the mobile number of the customer: 8767283921
Enter the cost of the items purchased: ₹ 898
Name of the customer: Ram Kumar Saha
Mobile number of the customer: 8767283921
Amount to be paid after discount: ₹ 853.10
*/
3.
import java.util.*;
class BookFair
{
// Instance variables
String Bname; // To store the name of the book
double price; // To store the price of the book
// Default constructor to initialize data members
BookFair()
{
Bname = "";
price = 0.0;
}
// Method to input and store the name and the price of the book
void Input()
{
Scanner sc = new Scanner(System.in);
System.out.print("Enter the name of the book: ");

Page 3 of 7
CLASS 9
PROJECT

Bname = sc.nextLine();
System.out.print("Enter the price of the book: ₹ ");
price = sc.nextDouble();
}
// Method to calculate the price after discount based on given criteria
void calculate() {
double discount;
if (price <= 1000) {
discount = price * 0.02; // 2% discount
} else if (price <= 3000) {
discount = price * 0.10; // 10% discount
} else {
discount = price * 0.15; // 15% discount
}
price -= discount; // Apply the discount
}

// Method to display the name and price of the book after discount
void display() {
System.out.println("Name of the book: " + Bname);
System.out.println("Price after discount: ₹ " + price);
}
// Main method to create an object of BookFair and call the member methods
public static void main()
{
BookFair ob = new BookFair();
ob.Input();
ob.calculate();
ob.display();
}
}

/* Output
* Enter the name of the book: Computer Applications with BlueJ
Enter the price of the book: ₹ 640
Name of the book: Computer Applications with BlueJ
Price after discount: ₹ 627.2
*/
4.
import java.util.*;
class SumSeries {
// Method to find and display the sum of the series
void Sum1(int n, double x) {
double sum = 0.0;
for (int i = 1; i <= n; i++) {
if (i % 2 == 0) {
sum -= x / i; // subtract if i is even
} else {

Page 4 of 7
CLASS 9
PROJECT

sum += x / i; // add if i is odd


}
}
System.out.println("Sum of the series: " + String.format("%.2f", sum));
}
// Method to find and display the sum of the factorial series
void Sum2() {
double sum = 0.0;
long factorial = 1;
for (int i = 1; i <= 20; i++) {
factorial *= i; // Compute factorial
sum += factorial; // Add factorial to sum
}
System.out.println("Sum of the series: " + String.format("%.2f", sum));
}
// Main method with menu-driven interface
public static void main() {
Scanner sc = new Scanner(System.in);
SumSeries ob = new SumSeries();

int choice;

System.out.println("Menu:");
System.out.println("1. Calculate Sum1");
System.out.println("2. Calculate Sum2");
System.out.println("3. Exit");
System.out.print("Enter your choice: ");
choice = sc.nextInt();

switch (choice) {
case 1:
System.out.print("Enter the number of terms (n): ");
int n = sc.nextInt();
System.out.print("Enter the value of x: ");
double x = sc.nextDouble();
ob.Sum1(n, x);
break;

case 2:
ob.Sum2();
break;

case 3:
System.out.println("Exiting...");
break;

default:
System.out.println("Invalid choice. Please try again.");

Page 5 of 7
CLASS 9
PROJECT

}
}
/* Output
* Menu:
1. Calculate Sum1
2. Calculate Sum2
3. Exit
Enter your choice: 1
Enter the number of terms (n): 5
Enter the value of x: 4
Sum of the series: 3.13
*/

5.
import java.util.*;
class Volume
{
// Method to calculate the volume of a sphere
void volume_sphere(double R)
{
// Use the formula V = 4/3 * π * R^3
double volume = (4.0 / 3.0) * (22.0 / 7.0) * Math.pow(R, 3);
System.out.println("Volume of the sphere: " + volume);
}
// Method to calculate the volume of a cylinder
void volume_cylinder(double H, double R)
{
// Use the formula V = π * R^2 * H
double volume = (22.0 / 7.0) * Math.pow(R, 2) * H;
System.out.println("Volume of the cylinder: " + volume);
}
// Method to calculate the volume of a cuboid
void volume_cuboid(double L, double B, double H)
{
// Use the formula V = L * B * H
double volume = L * B * H;
System.out.println("Volume of the cuboid: " + volume);
}
// Main method with menu-driven interface
public static void main() {
Scanner sc = new Scanner(System.in);
Volume v = new Volume();
int choice;
System.out.println("Menu:");
System.out.println("1. Calculate volume of a sphere");

Page 6 of 7
CLASS 9
PROJECT

System.out.println("2. Calculate volume of a cylinder");


System.out.println("3. Calculate volume of a cuboid");
System.out.println("4. Exit");
System.out.print("Enter your choice: ");
choice = sc.nextInt();
switch (choice)
{
case 1:
System.out.print("Enter the radius of the sphere: ");
double radiusSphere = sc.nextDouble();
v.volume_sphere(radiusSphere);
break;
case 2:
System.out.print("Enter the radius of the cylinder: ");
double radiusCylinder = sc.nextDouble();
System.out.print("Enter the height of the cylinder: ");
double heightCylinder = sc.nextDouble();
v.volume_cylinder(heightCylinder, radiusCylinder);
break;
case 3:
System.out.print("Enter the length of the cuboid: ");
double lengthCuboid = sc.nextDouble();
System.out.print("Enter the breadth of the cuboid: ");
double breadthCuboid = sc.nextDouble();
System.out.print("Enter the height of the cuboid: ");
double heightCuboid = sc.nextDouble();
v.volume_cuboid(lengthCuboid, breadthCuboid, heightCuboid);
break;
case 4:
System.out.println("Exiting...");
break;
default:
System.out.println("Invalid choice. Please try again.");
}
}
}
/* Output
* Menu:
1. Calculate volume of a sphere
2. Calculate volume of a cylinder
3. Calculate volume of a cuboid
4. Exit
Enter your choice: 1
Enter the radius of the sphere: 56
Volume of the sphere: 735914.6666666665
*/

Page 7 of 7

You might also like