0% found this document useful (0 votes)
30 views

Lab2 Report

The document contains source code for two Java classes - Program and Land. The Program class models an educational program with attributes like code, description, duration etc. and relevant methods. The Land class models a land property with attributes like ID, owner, type and area and methods to calculate tax. The main classes - ProgramApp and LandApp are used to create objects, input data via user and display output.

Uploaded by

muhammad hafeez
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views

Lab2 Report

The document contains source code for two Java classes - Program and Land. The Program class models an educational program with attributes like code, description, duration etc. and relevant methods. The Land class models a land property with attributes like ID, owner, type and area and methods to calculate tax. The main classes - ProgramApp and LandApp are used to create objects, input data via user and display output.

Uploaded by

muhammad hafeez
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

COLLEGE OF COMPUTING, INFORMATICS AND MATHEMATICS

UNIVERSITI TEKNOLOGI MARA

BACHELOR OF INFORMATION TECHNOLOGY


(CDCS240)

OBJECT-ORIENTED PROGRAMMING
(CSC435)

LAB ASSIGNMENT 2

By:
MUHAMMAD HAFIZ BIN MOHD RAFI
2023149239

Prepared for:
MOHD NIZAM BIN OSMAN

2 NOVEMBER 2023
QUESTION 1.1
SOURCE CODE (SPECIFIC CLASS = Program)

public class Program{

// Data Members

private String programCode;

private String programDescription;

private int programDuration;

private String faculty;

private String programHead;

// Default constructor

public Program(){

programCode = "";

programDescription = "";

programDuration = 0;

faculty = "";

programHead = "";

// Normal constructor

public Program(String code, String description, int duration, String faculty, String head){

programCode = code;

programDescription = description;

programDuration = duration;

faculty = faculty;

programHead = head;

}
// Copy Constructor

public Program(Program o){

programCode = o.programCode;

programDescription = o.programDescription;

programDuration = o.programDuration;

this.faculty = o.faculty;

programHead = o.programHead;

// Mutator/Setter

public void setProgramCode(String code){

programCode = code;

public void setProgramDescription(String description){

programDescription = description;

public void setProgramDuration(int duration){

programDuration = duration;

public void setFaculty(String faculty){

this.faculty = faculty;

public void setProgramHead(String head){

programHead = head;

}
// Retriever/Getter

public String getProgramCode(){

return programCode;

public String getProgramDescription(){

return programDescription;

public int getProgramDuration(){

return programDuration;

public String getFaculty(){

return faculty;

public String getProgramHead(){

return programHead;

}
// A processor

public String progLevel(){

String progLevel = "";

String sub = programCode.substring(2,3);

if (sub.equalsIgnoreCase("0"))

progLevel = "Certificate";

else if (sub.equalsIgnoreCase("1"))

progLevel = "Diploma";

else if (sub.equalsIgnoreCase("2"))

progLevel = "Degree";

else if (sub.equalsIgnoreCase("7"))

progLevel = "Master";

else if (sub.equalsIgnoreCase("9"))

progLevel = "Doctorate";

return progLevel;

// Printer

public String toString(){

return "Program Code: " + programCode +

"\nProgram Description: " + programDescription +

"\nProgram Duration: " + programDuration +

"\nFaculty: " + faculty +

"\nProgram Head: " + programHead +

"\nProgram Level: " + progLevel();

}
SOURCE CODE (MAIN CLASS= ProgramApp)

import java.util.*;

public class ProgramApp{

public static void main(String[] args){

Scanner scan = new Scanner(System.in);

Scanner scan1 = new Scanner(System.in);

// Step 1: Create object

Program tempO = new Program();

//Step 2: Input data from users

System.out.print("Please Enter the Program Code: ");

String programCode = scan.nextLine();

System.out.print("Please Enter the Program Description: ");

String programDescription = scan.nextLine();

System.out.print("Please Enter the Program Duration: ");

int programDuration = scan1.nextInt();

System.out.print("Please Enter the Faculty Name: ");

String faculty = scan.nextLine();

System.out.print("Please Enter the Program Head: ");

String programHead = scan.nextLine();

// Step 3: Store data onto object

tempO.setProgramCode(programCode);

tempO.setProgramDescription(programDescription);

tempO.setProgramDuration(programDuration);

tempO.setFaculty(faculty);

tempO.setProgramHead(programHead);

System.out.print(tempO.toString());

}
INPUT SAMPLE

OUTPUT SAMPLE
QUESTION 1.2
SOURCE CODE (SPECIFIC CLASS= Land)

public class Land{

// Data Members

private String id;

private String ownerName;

private char hType;

private int area;

// Default Constructor

public Land(){

id = "";

ownerName = "";

hType = 'a';

area = 0;

// Normal Constructor

public Land(String data ,String ownerN ,char type ,int ar){

id = data;

ownerName = ownerN;

hType = type;

area = ar;

// Copy Constructor

public Land(Land l){

id = l.id;

ownerName = l.ownerName;

hType = l.hType;

area = l.area;

}
// Setter/ Mutator

public void setId(String data){

id = data;

public void setOwnerName(String ownerN){

ownerName = ownerN;

public void setHType(char type){

hType = type;

public void setArea(int ar){

area = ar;

// Retriever/ Getter

public String getId(){

return id;

public String getOwnerName(){

return ownerName;

public char getHType(){

return hType;

public int getArea(){

return area;

}
// Processor

public double calculateTaxRate(){

int taxRate = 0;

if (hType == 'T' || hType == 't')

taxRate = 10;

else if (hType == 'S' || hType == 's')

taxRate = 15;

else if(hType == 'B' || hType == 'b')

taxRate = 20;

else if (hType == 'C' || hType == 'c')

taxRate = 30;

double sum = taxRate * area;

return sum;

//printer

public String toString(){

return "\nInsert Id: " + id +

"\nOwner Name: " + ownerName +

"\nHouse Type: " + hType +

"\nArea Land: " + area;

}
SOURCE CODE (MAIN CLASS= LandApp)

import java.util.*;

public class LandApp{

public static void main(String[] args){

Scanner scan = new Scanner(System.in);

//step 1: Create the object

Land land = new Land();

//step 2: Input data

System.out.print("Insert Id: ");

String id = scan.nextLine();

System.out.print("Enter Owner Name: ");

String ownerName = scan.nextLine();

System.out.print("Enter House Type: ");

char hType = scan.nextLine().charAt(0);

System.out.print("Land Area: ");

int area = scan.nextInt();

//step 3: Store data onto object using setter

land.setId(id);

land.setOwnerName(ownerName);

land.setHType(hType);

land.setArea(area);

System.out.println(land.toString() + "\nSum Tax: "+land.calculateTaxRate());

}
INPUT SAMPLE

OUTPUT SAMPLE

You might also like