Oop Lab Ass # 3
Oop Lab Ass # 3
Lab Assignment # 3
this.rating = rating;
this.id = id;
this.title = title;
return rating;
this.rating = rating;
return id;
this.id = id;
}
public String getTitle() {
return title;
this.title = title;
@Override
// if (this == obj) {
// return true;
// }
// return false;
// }
return id == otherMovie.id;
@Override
@Override
Task 2
class Simple {
int num1;
int num2;
this.num1 = num1;
this.num2 = num2;
}
public void add() {
double sum=num1+num2;
System.out.println("Sum :"+sum) ;
if (num2 != 0) {
} else {
super(num1, num2);
@Override
public void add() {
super.add();
} else {
@Override
super.sub();
} else {
@Override
super.mul();
} else {
@Override
} else {
System.out.println("Simple Class:");
simpleObj.add();
simpleObj.sub();
simpleObj.mul();
simpleObj.div();
System.out.println();
System.out.println("VerifiedSimple Class:");
verifiedSimpleObj.add();
verifiedSimpleObj.sub();
verifiedSimpleObj.mul();
verifiedSimpleObj.div();
}
Task 3
abstract class Shape {
this.numberOfLines = numberOfLines;
this.penColor = penColor;
this.fillColor = fillColor;
this.radius = radius;
}
@Override
this.side = side;
@Override
this.base = base;
this.height = height;
@Override
System.out.println("Drawing Triangle with Base: " + base + " and Height: " + height);
System.out.println("Drawing Shapes:");
circle.draw();
square.draw();
triangle.draw();
}
}
Lab 8
Task1
class Package {
this.senderName = senderName;
this.senderAddress = senderAddress;
this.recipientName = recipientName;
this.recipientAddress = recipientAddress;
if (weight > 0) {
this.weight = weight;
} else {
if (costPerOunce > 0) {
this.costPerOunce = costPerOunce;
} else {
if (flatFee >= 0) {
this.flatFee = flatFee;
} else {
}
@Override
if (additionalFee >= 0) {
this.additionalFee = additionalFee;
} else {
@Override
TwoDayPackage package2 = new TwoDayPackage("Alice Smith", "789 Oak St", "Bob Johnson", "321
Pine St", 8, 3.0, 5.0);
Task2
this.name = name;
return name;
this.name = name;
}
public abstract boolean isOutstanding();
super(name);
this.CGPA = CGPA;
return CGPA;
this.CGPA = CGPA;
@Override
super(name);
this.numberOfPublications = numberOfPublications;
return numberOfPublications;
this.numberOfPublications = numberOfPublications;
@Override
System.out.println("---------------");
}
professor.setNumberOfPublications(100);
// Calling isOutstanding() for the professor after updating the publication count
Task 3
this.val1 = val1;
public abstract void compute(); // abstract method for performing the conversion
public void displayResult() {
super(liters);
@Override
super(fahrenheit);
@Override
super(feet);
@Override
l_to_g.compute();
l_to_g.displayResult();
System.out.println();
f_to_c.compute();
f_to_c.displayResult();
System.out.println();
f_to_m.compute();
System.out.println("Feet to Meters Conversion:");
f_to_m.displayResult();
Lab 10
Task1
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Scanner;
class Contact {
// Constructor
this.firstName = firstName;
this.lastName = lastName;
this.phoneNumber = phoneNumber;
this.emailAddress = emailAddress;
return firstName;
this.firstName = firstName;
return lastName;
this.lastName = lastName;
return phoneNumber;
this.phoneNumber = phoneNumber;
}
public String getEmailAddress() {
return emailAddress;
this.emailAddress = emailAddress;
int choice;
do {
System.out.println("5. Exit");
choice = scanner.nextInt();
switch (choice) {
case 1:
addContact();
break;
case 2:
displayAllContacts();
break;
case 3:
searchAndDisplayContact();
break;
case 4:
deleteContact();
break;
case 5:
break;
default:
contacts.add(newContact);
if (contacts.isEmpty()) {
} else {
System.out.println("All contacts:");
displayContact(contact);
if (contact.getFirstName().toLowerCase().contains(searchString) ||
contact.getLastName().toLowerCase().contains(searchString) ||
contact.getPhoneNumber().toLowerCase().contains(searchString) ||
contact.getEmailAddress().toLowerCase().contains(searchString)) {
searchResults.add(contact);
if (searchResults.isEmpty()) {
} else {
System.out.println("Matching contacts:");
displayContact(contact);
while (iterator.hasNext()) {
if (contact.getFirstName().toLowerCase().contains(searchString) ||
contact.getLastName().toLowerCase().contains(searchString) ||
contact.getPhoneNumber().toLowerCase().contains(searchString) ||
contact.getEmailAddress().toLowerCase().contains(searchString)) {
iterator.remove();
System.out.println("Contact deleted successfully.");
return;
System.out.println("--------------------");
}
}
Task 2
import java.util.ArrayList;
throw new IllegalArgumentException("At least two values are required to calculate standard
deviation.");
}
return Math.sqrt(variance);
sum += num.doubleValue();
intList.add(2);
intList.add(4);
intList.add(4);
intList.add(4);
intList.add(5);
intList.add(5);
intList.add(7);
intList.add(9);
Task 3
import java.util.ArrayList;
import java.util.Random;
public Task3() {
return box.isEmpty();
public T drawItem() {
if (isEmpty()) {
return null;
return box.remove(randomIndex);
nameBox.add("Alice");
nameBox.add("Bob");
nameBox.add("Charlie");
nameBox.add("David");
while (!nameBox.isEmpty()) {
numberBox.add(i);
while (!numberBox.isEmpty()) {
}
Task 4
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;
System.exit(1);
scores.add(score);
scanner.close();
Collections.sort(scores);
sum += score;
// Multiply by 0.6