Comsats University Islamabad Wah Campus Object Oriented Programming

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 7

Comsats University Islamabad

Wah Campus

Object Oriented Programming


Assignment # 01

Submitted to: Miss Samia Zafar

Submitted by:

Nofil Abbas FA21-BCS-046


Task 1
CarLearner Car

package car.learner; package car.learner;

import java.util.Scanner;
public class Car {
public String carOwner;
public class CarLearner { public String carName;
public int carPrice;
public String carModel;
public static void main(String[] args) {
Car c1=new Car(); public void setCarOwner(String a){
Car c2=new Car(); carOwner=a;
Car c3=new Car(); }
Scanner sc=new Scanner(System.in); public void setCarName(String a){
System.out.println("Enter data of first carName=a;
car."); }
System.out.print("Owner Name: "); public void setCarPrice(int a){
c1.setCarOwner(sc.nextLine()); carPrice=a;
System.out.print("Car Name: "); }
c1.setCarName(sc.nextLine()); public void setCarModel(String a){
System.out.print("Car Price: "); carModel=a;
c1.setCarPrice(sc.nextInt()); }
System.out.print("Car Model: "); public void display(){
sc.nextLine(); System.out.println(carOwner+"\t"+carName+"\
c1.setCarModel(sc.nextLine()); t"+carPrice+"\t"+carModel+"\n"+);
}
System.out.println("\nEnnter data of
second car."); }
System.out.print("Owner Name: ");
c2.setCarOwner(sc.nextLine());
System.out.print("Car Name: ");
c2.setCarName(sc.nextLine());
System.out.print("Car Price: ");
c2.setCarPrice(sc.nextInt());
System.out.print("Car Model: ");
sc.nextLine();
c2.setCarModel(sc.nextLine());

System.out.println("\nEnter data of third


car.");
System.out.print("Owner Name: ");
c3.setCarOwner(sc.nextLine());
System.out.print("Car Name: ");
c3.setCarName(sc.nextLine());
System.out.print("Car Price: ");
c3.setCarPrice(sc.nextInt());
System.out.print("Car Model: ");
sc.nextLine();
c3.setCarModel(sc.nextLine());

System.out.println("\
t\""+c1.carOwner+"\"");
c1.display();
System.out.println("\
t\""+c2.carOwner+"\"");
c2.display();
System.out.println("\
t\""+c3.carOwner+"\"");
c3.display();
}

}
Task 2
AccountLearner Account

package accountlearner; package accountlearner;


import java.util.Scanner;

public class accountlearner { public class Account {


public String ac_title;
public String ac_number;
public static void main(String[] args) { public double balance=1000;
Scanner sc=new Scanner(System.in);
Account a1=new Account(); public void deposit(int a){
a1.ac_number="CUI-046"; balance+=a;
a1.ac_title="NOFIL ABBAS"; System.out.println("Amount deposited.");
System.out.println("WElCOME to CUI- }
WAH BANK"); public void withdraw(int a){
while(true){ if(a>balance){
System.out.println("\nChoose options.\n1: System.out.println("Insufficient Balance!");
Show Balance\t2: Deposit\t3: Withdraw\t4: }
Exit\n"); else{
int opt=sc.nextInt(); balance-=a;
switch(opt){ System.out.println("Amount withdrawn.");
case 1: }
System.out.println("Balance: }
"+a1.showBalance()); public double showBalance(){
break; return balance;
case 2: }
System.out.print("Enter Deposit }
amount: ");
int deposit=sc.nextInt();
a1.deposit(deposit);
break;
case 3:
System.out.print("Enter Withdraw
amount: ");
int withdraw=sc.nextInt();
a1.withdraw(withdraw);
break;
case 4:
System.out.println("Thank you for
using CUI-WAH");
break;
}
if(opt==4){
break;
}
}
}

}
Task 3
EmployeeLearner Employee

package employee.learner; package employee.learner;

import java.text.ParseException; import java.text.ParseException;


import java.util.Scanner; import java.text.SimpleDateFormat;
import java.text.SimpleDateFormat; import java.util.Date;
import java.util.Date; import java.util.Scanner;

public class EmployeeLearner {


static Scanner sc=new Scanner(System.in); public class Employee {
public static void data(Employee e) throws public int employeeCode;
ParseException{ public String employeeName;
System.out.print("Enter employee name: public Date employeeDOJ;
"); Scanner input=new Scanner(System.in);
e.setEmployeeName(sc.nextLine()); public void setEmployeeCode(int a){
System.out.print("Enter employee code: employeeCode=a;
"); }
e.setEmployeeCode(sc.nextInt()); public void setEmployeeName(String a){
sc.nextLine(); employeeName=a;
System.out.print("Enter employee DOJ: }
"); public void setEmployeeDOJ(String a) throws
e.setEmployeeDOJ(sc.nextLine()); ParseException{
} Date d=new
SimpleDateFormat("dd/MM/yyyy").parse(a);
employeeDOJ=d;
public static void main(String[] args) throws }
ParseException { public void check(Date a,Date b,Employee e)
Scanner input=new Scanner(System.in); throws ParseException{
Employee e1=new Employee(); long difference_In_Time = a.getTime()-
Employee e2=new Employee(); b.getTime();
System.out.println("Enter employee 1 long difference_In_Years =
data."); (difference_In_Time/ (1000l * 60 * 60 * 24 * 365));
data(e1); if(difference_In_Years>=3){
System.out.println("Enter employee 2 System.out.println(e.employeeName+" tenure
data."); is more than 3 years.");
data(e2); System.out.println("Tenure=
System.out.print("Enter today date: "); "+difference_In_Years+" Years");
String tdate=sc.nextLine(); }
Date d=new else{
SimpleDateFormat("dd/MM/yyyy").parse(tdat System.out.println(e.employeeName+" tenure
e); is less than 3 years.");
e1.check(d,e1.employeeDOJ,e1); System.out.println("Tenure=
e2.check(d,e2.employeeDOJ,e2); "+difference_In_Years+" Years");
} }
} }
}

You might also like