Comsats University Islamabad

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

COMSATS UNIVERSITY ISLAMABAD

WAH CAMPUS
Name: Nimra safa
Roll no: SP22-BCS-049
Question 1.
package com.mycompany.account;

class account1
{
private double balance;

public void setbalance(double b)


{
balance = b;
}
public void showbalance()
{
System.out.println("Balance is " + balance);

}
public void withdraw(int a)
{
balance = balance - a;
}
public void deposit(int c)
{
balance = balance + c;
}
}

public class Account {

public static void main(String[] args) {


account1 A = new account1();
A.setbalance(100);
A.showbalance();
A.withdraw(2);
A.deposit(3);
A.showbalance();

}
}

Question 2
package com.mycompany.task2;
import java.util.Scanner;
class car

private int carmodel;

private String carname;

private double price;

private String carowner;

public void setmodel()

System.out.println("Enter the model :");

Scanner input = new Scanner(System.in);

carmodel = input.nextInt();

public void setprice()

System.out.println("Enter the price :");

Scanner input1 = new Scanner(System.in);

price = input1.nextInt();

}
public void setcarname()

System.out.println("Enter the car name :");

Scanner input2 = new Scanner(System.in);

carname = input2.nextLine();

public void setcarowner()

System.out.println("Enter the owner :");

Scanner input3 = new Scanner(System.in);

carowner = input3.nextLine();

public void display()

System.out.println("The car model is " + carmodel);

System.out.println("The car price is " + price);

System.out.println("The car name is " + carname);

System.out.println("The car owner is " + carowner);

}
}

class Book

private String title;

private double bprice;

private int noofpages;

public void settitle(String s)

title = s;

public void setprice(double p)

bprice = p;

public void setNoofpages(int n)

noofpages = n;

public void display()

{
System.out.println("The title of Book" + title);

System.out.println("The Price of Book RS" + bprice);

System.out.println("The No of pages of Book" + noofpages);

public class Task2 {

public static void main(String[] args)

car c1 = new car();

c1.setmodel();

c1.setprice();

c1.setcarname();

c1.setcarowner();

c1.display();

Book c2 = new Book();

c2.settitle("The PPC");

c2.setprice(300);

c2.setNoofpages(302);

c2.display();
}

Question 3:
package Task3;

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

class employee{
Scanner input = new Scanner(System.in);
private int employeeCode;
private String employeeName;
private String employeeDateOfJoining;
private String CurrentDate;

public void setEmployeeCode(){

System.out.println("Enter Employee Code: ");


employeeCode = input.nextInt();
}

public void setEmployeeName(){


System.out.println("Enter Employee Name: ");
Scanner input1 = new Scanner(System.in);
employeeName = input1.nextLine();
}

public void setDateOfJoining(){


System.out.println("Enter Date of Joining: ");
Scanner input2 = new Scanner(System.in);
employeeDateOfJoining= input2.nextLine();
}

public void employeeTenure() throws ParseException


{
SimpleDateFormat demo = new SimpleDateFormat("MM-dd-
yyyy");
System.out.println("Enter Current Date: ");
Scanner input3 = new Scanner(System.in);
CurrentDate= input3.nextLine();
Date Joindate = demo.parse(employeeDateOfJoining);
Date Currentdate = demo.parse(CurrentDate);
long Check = (Currentdate.getTime() - Joindate.getTime()) /
(1000*60*60*24);

if((Check/365)>3)
{
System.out.println("Tenure is more than 3 years");
}
else
{
System.out.println("Tenure is less than 3 years");
}

}
}

public class LAB2_Task3 {

public static void main(String[] args) throws ParseException {

employee a1 = new employee();


a1.setEmployeeCode();
a1.setEmployeeName();
a1.setDateOfJoining();
a1.employeeTenure();

You might also like