You are on page 1of 8

BAHRIA UNIVERSITY (KARACHI CAMPUS)

ASSIGNMENT # 2 - SPRING 2022


Object Oriented Programming (CSC-210)
Max Marks: 10 Points
Class:BSE-2
Course Instructor: Engr. Muhammad
Faisal
IMPLEMENTATION

This assignment is the continuation of assignment 1, where you are supposed you implement all
the 10 classes that you have modeled in previous assignment, using Java language. You are also
supposed to create the objects to each class in main method and call appropriate method.
1. Employee Class

class Employee{
private final String Name;
private String Designation, Email;
private final int Salary;
public void setDesignation(String Designation) { this.Designation = Designation; }
public void setEmail(String Email) { this.Email = Email; }
public Employee(String Name, String Designation, String Email, int Salary) {
this.Name = Name;
this.Designation = Designation;
this.Email = Email;
this.Salary = Salary;
}
public void Display(){
System.out.println("Name : " + Name);
System.out.println("Designation : " + Designation);
System.out.println("Email : " + Email);
System.out.println("Salary : " + Salary);
}
}
public class Main {
public static void main(String[] args) {
Employee e1 = new Employee("Noman", "Receptionist", "nomanjr123@gmail.com",
40000);
e1.Display();
}
}

Name: Rizwan Akram Enrollment No. : 02-131212-026


2. Car Class

class Car{
private final String model, name, VIN;
private String color;
int year;
public Car(String name, String model, String VIN, String color, int year) {
this.name = name;
this.model = model;
this.VIN = VIN;
this.color = color;
this.year = year;
}
public void setColor(String color) { this.color = color; }
public String getVIN() { return VIN; }
public void Display() {
System.out.println("\t\tCar Details");
System.out.println("Name : " + name);
System.out.println("Model : " + model);
System.out.println("Year : " + year);
System.out.println("VIN : " + VIN);
System.out.println("Color : " + color);
}
}
public class Main {
public static void main(String[] args) {
Car corolla = new Car("Corolla", "Altis", "APG-123", "Blue", 2021);
corolla.setColor("Blue");
corolla.Display();
}
}

3. Customer Class
Name: Rizwan Akram Enrollment No. : 02-131212-026
class Customer{
String[] Item_Name;
Date date = new Date();
int Customer_Id;
double Payment;
public Customer(String[] name, double payment) {
Item_Name = name;
Customer_Id++;
Payment = payment;
}
public double getPayment() { return Payment; }
public void generateBill(){
System.out.println("\t\t Imtiaz Utility Store");
System.out.printf(" \t %s\n", date.toLocaleString());
System.out.println("Name : " + Arrays.toString(Item_Name));
System.out.println("Customer Id : " + Customer_Id);
System.out.println("Payment : " + Payment);
}
}
public class Main {
public static void main(String[] args) {
Customer C1 = new Customer(new String[]{"Biscuits", "Chocolate"}, 3400);
C1.generateBill();
}
}

4. Book Class

class Book{
int no_OfPages, Price;
String Name;
public void setPrice(int price) { Price = price; }
public Book(String Name, int no_OfPages, int price) {
this.Name = Name;
this.no_OfPages = no_OfPages;
Price = price;
}
public void Display() {
System.out.println("\t\tBook Details");
System.out.println("Name : " + Name);
System.out.println("No. Of Pages : " + no_OfPages);
System.out.println("Price : " + Price);
}
}
public class Main {
public static void main(String[] args) {
Book HarryPotter = new Book("Harry Potter",23, 1000);
HarryPotter.Display();
}
}

Name: Rizwan Akram Enrollment No. : 02-131212-026


5. Item Class

class Item{
String Name;
int Quantity;
int UnitPrice;

public void setQuantity(int quantity) { Quantity = quantity; }


public void setUnitPrice(int unitPrice) { UnitPrice = unitPrice; }
public Item(String name, int quantity, int unitPrice) {
Name = name;
Quantity = quantity;
UnitPrice = unitPrice;
}
public int calculateBill(){
return Quantity*UnitPrice;
}
public void generateBill(){
System.out.println("\t\t Ahsan General Store");
System.out.println("Name : " + Name);
System.out.println("Quantity : " + Quantity);
System.out.println("UnitPrice : " + UnitPrice);
System.out.println("Bill : " + calculateBill());
}
}
public class Main {
public static void main(String[] args) {
Item Rice = new Item("Rice", 2, 200);
Rice.calculateBill();
Rice.generateBill();
}

Name: Rizwan Akram Enrollment No. : 02-131212-026


6. Food Class

class Food{
private final String Name, Type;
private final int Price;
Date ExpDate;
public Food(String name, String type, int price) {
Name = name;
Type = type;
Price = price;
}
public void setExpDate(String Date) {
try {
ExpDate = new SimpleDateFormat("dd/MM/yy").parse(Date);
} catch (ParseException e) {
throw new RuntimeException(e);
}
}
public void Display(){
System.out.println("\t\t Food Info");
System.out.println("Name : " + Name);
System.out.println("Type : " + Type);
System.out.println("Price : " + Price);
System.out.println("ExpDate : " + ExpDate.toLocaleString());
}
}
public class Main {
public static void main(String[] args) {
Food BBQ = new Food("BBQ", "Fast Food", 2000);
BBQ.setExpDate("3/12/2022");
BBQ.Display();
}

7. Student Class

Name: Rizwan Akram Enrollment No. : 02-131212-026


class Student{
private final String St_Name, UniName, Enrollment, Grade;
double GPA;
Student(String St_Name, String UniName, String Enrollment, String Grade) {
this.St_Name = St_Name;
this.UniName = UniName;
this.Enrollment = Enrollment;
this.Grade = Grade;
}
public double calculateGPA(){
if (Grade.equals("A")) { return GPA = 4.00; }
else if (Grade.equals("A-")) { return GPA = 3.67; }
else if (Grade.equals("B+")) { return GPA = 3.33; }
else if (Grade.equals("B")) { return GPA = 3.0; }
else if (Grade.equals("B-")) { return GPA = 2.67; }
else if (Grade.equals("C+")) { return GPA = 2.33; }
else if (Grade.equals("C")) { return GPA = 2.00; }
else if (Grade.equals("C-")) { return GPA = 1.87; }
else if (Grade.equals("D+")) { return GPA = 1.33; }
else if (Grade.equals("D")) { return GPA = 1.00; }
else if (Grade.equals("F")) { return GPA = 0.00; }
else { return GPA = 0.00; }
}
public void Display() {
System.out.println("\t\t Student Record");
System.out.println("Student Name | " + St_Name);
System.out.println("University | " + UniName);
System.out.println("Enrollment | " + Enrollment);
System.out.println("Grade | " + Grade);
System.out.println("GPA | " + calculateGPA());
}
}
public class Main {
public static void main(String[] args) {
Student St1 = new Student("Rizwan Akram", "Bahria University", "02-131212-026",
"A-");
St1.Display();
}
}

8. Bank Class

Name: Rizwan Akram Enrollment No. : 02-131212-026


class Bank{
private final String Name, Branch, City;
private String Interest_Rate;
Bank(String name, String city, String branch) {
Name = name;
Branch = branch;
City = city;
}
public void setInterest_Rate(String interest_Rate) { Interest_Rate = interest_Rate;
}
public void Display() {
System.out.println("\t\t Habib Bank Limited");
System.out.println("Name : " + Name);
System.out.println("City : " + City);
System.out.println("Branch : " + Branch);
System.out.println("Interest_Rate : " + Interest_Rate);
}
}
public class Main {
public static void main(String[] args) {
Bank HabibBank = new Bank("Habib","Karachi", "Malir");
HabibBank.setInterest_Rate("8.00%");
HabibBank.Display();
}
}

9. Person / Human Class

class Person{
String Name;
int Age, Salary;
public void setSalary(int salary) { Salary = salary; }

public Person(String name, int age, int salary) {


Name = name;
Age = age;
Salary = salary;
}
public void Display() {
System.out.println("\t\t Person Info");
System.out.println("Name : " + Name);
System.out.println("Age : " + Age);
System.out.println("Salary : " + Salary);
}
}

public class Main {


public static void main(String[] args) {
Name: Rizwan Akram Enrollment No. : 02-131212-026
Person P1 = new Person("Anas", 21, 30000);
P1.setSalary(34000);
P1.Display();
}
}

10. Shape Class

class Shape{
String Name;
int Area, Length;
public void setArea(int area) { Area = area; }
public int calculateArea(){
return Area = Length * Length;
}
public Shape(String name, int length) {
Name = name;
Length = length;
}
public void DisplayArea() {
System.out.printf("Area Of The %s Is %d sq.meter\n\n", Name, Area);
}
}
public class Main {
public static void main(String[] args) {
Shape Square = new Shape("Square", 12);
Square.calculateArea();
Square.DisplayArea();
}
}

Name: Rizwan Akram Enrollment No. : 02-131212-026

You might also like