Object Oriented Programming Language
Object Oriented Programming Language
(OOP)(CS-104)
INTRODUCTION TO BASIC JAVA PROGRAM AND JAVA IDE
LAB#06
SUBMITTED TO:
SIR TALHA SAEED
SUBMITTED BY:
Noor-ul-Huda
REGISTRATION NO:
22-SE-032
SEMESTER SECTION:
SE-2A
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{
calculator(int x, int y) {
this.x = x;
this.y = y;
}
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{
Aera(){
Aera(float lenght){
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{
this.cust_id = cust_id;
this.first_name = first_name;
this.last_name = last_name;
this.credit_limt = Credit_limt;
this.address = address;
return last_name;
}
return address;
Customer(){ this.cust_id= 0;
this.first_name = " ";
this.last_name = " "; this.address
= " ";
this.credit_limt = 0;
this.last_name = last_name;
+ cust_id);
: " + last_name);
: " + address);
+ credit_limt);
c1.input_detail();
c1.display();
}
Output :-
THE END…!