[go: up one dir, main page]

0% found this document useful (0 votes)
39 views11 pages

22-SE-096 Lab Report 6

The document is a lab report submitted by Talha Ghafoor to Sir Khalid. It contains code and outputs for 3 tasks: 1) A calculator class with methods for addition, subtraction, multiplication and division using constructors. 2) An area class with constructors and a method to calculate the area of a rectangle. 3) A customer class with private fields and methods to set/get fields, overloaded constructors, and methods to input customer data and display it.

Uploaded by

Talha Ghafoor
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views11 pages

22-SE-096 Lab Report 6

The document is a lab report submitted by Talha Ghafoor to Sir Khalid. It contains code and outputs for 3 tasks: 1) A calculator class with methods for addition, subtraction, multiplication and division using constructors. 2) An area class with constructors and a method to calculate the area of a rectangle. 3) A customer class with private fields and methods to set/get fields, overloaded constructors, and methods to input customer data and display it.

Uploaded by

Talha Ghafoor
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

OBJECT ORIENTED PROGRAMMING

Lab Report #06

Submitted To:
Sir Khalid
Submitted By:
Talha Ghafoor

Roll Number:
22-SE-096
Task #01
Create a Java program using classes that will have four
function for calculations i.e. addition, subtraction,
multiplication and division. Use constructor to
initialize the value of data members.
Code :
import java.util.Scanner;

class calculator{
int sum = 0, x,y;

calculator(int x, int y) {
this.x = x;
this.y = y;
}

void addition ( ){
sum =this.x + this.y ;
System.out.println(" the total sum : "+ sum);

}
void subtraction (){
sum = this.x - this.y ;
System.out.println(" the total substraction : "+ sum);
}
void multipication ( ){
sum = this.x * this.y ;
System.out.println(" the total
multipication : "+ sum);
}
void division ( ){
sum = this.x / this.y ;
System.out.println(" the total division : "+ sum);
}
}

public class java_lab06_task01 { public


static void main(String[] args) {
calculator c1 = new calculator(89,34);
c1.addition();
c1.subtraction();
c1.multipication();
c1.division();

}
}
Output :-

Task #02 :-
Design, develop, and execute a program in Java based on
following criteria:
An area class to have two data members length and width
and following member
functions: three constructors one will be default
constructor, other two will be
parameterized constructors (one will take only length as
parameter other will take both length and width as
parameters). Create member function to calculate area of
rectangle.

Code :-

class Aera{
float lenght , width,Aera;
Aera(){

}
Aera(float lenght){

}
Aera(float lenght,float width){

}
void rectangle(float lenght ,float width){
Aera = lenght * width;
System.out.println(" The aera of Rectangle is : "+
Aera);
}
}

public class lab06_task02 {


public static void main(String[] args) {
Aera a1 = new Aera();
a1.rectangle(25,33);
}
}
Output :-

Task #03
Define a class Customer that holds private fields for
a customer's ID, first name, last name, address
and credit limit.
Define functions that set the fields of customer. For
example setCustomerID().
Define functions that show the fields of customer. For
example getCustomerID().
Use constructor to set the default values to each of the field.
Overload at least three constructor of the customer class.
Define a function that takes input from user and set the all
fields of customer data.
Define a function that displays the entire customer’s data.
Code :-

import java.util.Scanner;

class Customer{
private int cust_id,credit_limt;
private String first_name , last_name, address;

public void setCust_id(int cust_id) {


this.cust_id = cust_id;
}

public void setFirst_name(String first_name) {


this.first_name = first_name;
}

public void setLast_name(String last_name) {


this.last_name = last_name;
}

public void setCredit_limt(int Credit_limt) {


this.credit_limt = Credit_limt;
}
public void setaddress(String address){
this.address = address;
}
public int getCust_id() {
return cust_id;
}
public String getFirst_name() {
return first_name;
}

public String getLast_name() {


return last_name;
}

public String getAddress() {


return address;
}

public int getCredit_limt() {


return credit_limt;
}
Customer(){
this.cust_id= 0;
this.first_name = " ";
this.last_name = " ";
this.address = " ";
this.credit_limt = 0;
}
Customer( int Cust_id , String first_name , String
last_name){
this.cust_id = cust_id;
this.first_name = first_name;
this.last_name = last_name;
}
Customer( String address, int credit_limt){
this.address = address;
this.credit_limt = credit_limt; }
public void input_detail(){
Scanner sx = new Scanner(System.in);
System.out.println(" Enter a Customer Id :"); cust_id
= sx.nextInt();
System.out.println(" Enter a First Name : ");
first_name = sx.next();
System.out.println(" Enter a Last Name : ");
last_name = sx.next();
System.out.println(" Enter a Credit Limit : ");
credit_limt = sx.nextInt();
System.out.println(" Enter a address : ");
address = sx.next();
}
public void display(){
System.out.println("\n\t ");
System.out.println(" Your Entered Customer Id :"
+ cust_id);

System.out.println(" Your Entered Customer First


Name : " + first_name);
System.out.println(" Your Entered Customer Last Name
: " + last_name);

System.out.println(" Your Entered Customer Address


: " + address);

System.out.println(" Your Entered Credit Limit :"


+ credit_limt);

}
public class Lab_06_task_03 {
public static void main(String[] args) {
Customer c1 = new Customer();
c1.input_detail();
c1.display();

}
}
Output :-

THE END…!

You might also like