Oops Lab
Oops Lab
Oops Lab
Problem
Create a class "Room" which will hold the height, width and breadth of the room in three variables.
Create another class "Roomdemo" which will use the earlier class, create instances of rooms, set the
Solution:
class Room {
this.height = height;
this.width = width;
this.breadth = breadth;
Problem:
i) Name of the student, ii) Marks of the student, iii )Function to assign initial values, iv)
Solution:
class Student {
// Instance variables
this.name = name;
if (marks.length == this.marks.length) {
} else {
total += mark;
return total;
}
public class StudentDemo {
student1.setMarks(marks);
student1.displayData();
Problem:
Write a program to find given substring in a line of text taken as input and replace with another
substring.
Solution:
import java.util.Scanner;
scanner.close();
Problem:
Write a program to implement a class "Salesman" with the attributes: name, salesman code,
sales amount and commission. The company calculates the commission of salesman
8% if sales<2000
12% If sales>5000
Create 5 salesman objects and find their commissions for their sales.
Solution:
class Salesman {
this.name = name;
this.salesmanCode = salesmanCode;
this.salesAmount = salesAmount;}
public void calculateCommission() {
} else {
System.out.println("--------------------------");
salesman1.calculateCommission();
salesman2.calculateCommission();
salesman3.calculateCommission();
salesman4.calculateCommission();
salesman5.calculateCommission();
salesman1.displaySalesmanInfo();
salesman2.displaySalesmanInfo();
salesman3.displaySalesmanInfo();
salesman4.displaySalesmanInfo();
salesman5.displaySalesmanInfo();
Problem:
Write a class "ElectricityBill", which will read the customer number and power consumed and billing
date and prints the amount to be paid by the customer and bill payment date (within 10 days from
the date of bill generation).
Solution:
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Scanner;
class ElectricityBill {
private int customerNumber;
this.customerNumber = customerNumber;
this.powerConsumed = powerConsumed;
this.billDate = new Date(); // Initialize the bill date to the current date
} else {
amount = 200 * 0.50 + 200 * 0.65 + 200 * 0.80 + (powerConsumed - 600) * 1.00;
return dateFormat.format(date);
// Helper method to calculate the due date (10 days from the bill date)
calendar.setTime(billDate);
calendar.add(Calendar.DATE, 10);
return calendar.getTime();
bill.calculateAmount();
scanner.close();
}
Problem:
i.
ii.
Account Number
Balance amount
Methods:
i.
Initialize data
ii.
Deposit money
iii.
iv.
Write an appropriate main() to maintain details and access methods for N customers.
Solution:
import java.util.Scanner;
class BankAccount {
public void initializeData(String name, long accNumber, char accType, double initialBalance) {
accountHolderName = name;
accountNumber = accNumber;
accountType = accType;
balance = initialBalance;
if (amount > 0) {
balance += amount;
} else {
balance -= amount;
} else {
accounts[i].displayAccountDetails();
accounts[i].deposit(depositAmount);
accounts[i].withdraw(withdrawalAmount);
System.out.println();
scanner.close();
}
9.Write a Java Class "Number" which will hold a decimal number. Create another class
"Octal", which
will extend the class number and with a method namely "ConvertOctal" it will convert the
decimal no.
into equivalent octal. Write appropriate main class to demonstrate the functioning of the
above.
// NumberConverter.java
class Number {
this.decimalNumber = decimalNumber;
return decimalNumber;
super(decimalNumber);
octalRepresentation.append(Long.toOctalString(decimalPart));
if (fractionalPart > 0) {
octalRepresentation.append('.');
fractionalPart *= 8;
octalRepresentation.append(octalDigit);
fractionalPart -= octalDigit;
return octalRepresentation.toString();
}
10. Develop an abstract class "GeometricObject" which should have two abstract methods
findArea() and
findCircumference(). Write a subclass for "GeometricObject" called "Triangle" which wll be able to
calculate area and circumference for a triangle taking the sides form user as input.
import java.util.Scanner;
this.sideA = sideA;
this.sideB = sideB;
this.sideC = sideC;
// @Override
public double findArea() {
// @Override
scanner.close();
}