Class 9 Project Second
Class 9 Project Second
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();
}
Page 2 of 7
CLASS 9
PROJECT
// 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
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
Page 7 of 7