22-SE-096 Lab Report 6
22-SE-096 Lab Report 6
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);
}
}
}
}
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);
}
}
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 class Lab_06_task_03 {
public static void main(String[] args) {
Customer c1 = new Customer();
c1.input_detail();
c1.display();
}
}
Output :-
THE END…!