College of Computing Informatics & Media
Bachelor of Computer Science (Hons.) Netcentric Computing
CSC435
Object Oriented Programming
Task: Lab Assignment 2
Name Khairil Hazmie Bin Abdul Razak
Student ID 2022697564
Group RCDCS2513A
Lecturer Sir Nizam Bin Osman
• Program class
public class Program
{
//Data Members
private String Prog_Code;
private String Prog_Desc;
private int Prog_duration;
private String Faculty;
private String Prog_Head;
//Method members
//Default Constructor
public Program()
{
Prog_Code = "";
Prog_Desc = "";
Prog_duration = 0;
Faculty = "";
Prog_Head = "";
}
//Normal Constructor
public Program(String PC, String PDesc, int Pdura, String Fc,
String PH)
{
Prog_Code = PC;
Prog_Desc = PDesc;
Prog_duration = Pdura;
Faculty = Fc;
Prog_Head = PH;
}
//Copy Constructor
public Program(Program p)
{
Prog_Code = p.Prog_Code;
Prog_Desc = p.Prog_Desc;
Prog_duration = p.Prog_duration;
Faculty = [Link];
Prog_Head = p.Prog_Head;
}
//Mutator/Setter method
public void setProg_Code(String PC)
{
Prog_Code = PC;
}
public void setProg_Desc(String PDesc)
{
Prog_Desc = PDesc;
}
public void setProg_duration(int Pdura)
{
Prog_duration = Pdura;
}
public void setFaculty(String Fc)
{
Faculty = Fc;
}
public void setProg_Head(String PH)
{
Prog_Head = PH;
}
//Retriever
public String getProg_Code()
{
return Prog_Code;
}
public String getProg_Desc()
{
return Prog_Desc;
}
public int getProg_duration()
{
return Prog_duration;
}
public String getFaculty()
{
return Faculty;
}
public String getProg_Head()
{
return Prog_Head;
}
//Processor
public String DetermineProgramLevel()
{
if (Prog_Code != null && Prog_Code.length() >= 3)
{
char thirdChar = Prog_Code.charAt(2);
switch (thirdChar)
{
case '0':
return "Certificate";
case '1':
return "Diploma";
case '2':
return "Degree";
case '7':
return "Master";
case '9':
return "Doctorate";
default:
return "Unknown Program Level";
}
}
else
{
return "Invalid Program Code";
}
}
//Printer
public String toString()
{
return "\n\nProgram code: " + Prog_Code + "\nProgram
Description: " + Prog_Desc + "\nProgram Duration: " + Prog_duration +
"\nFaculty: " + Faculty + "\nProgram Header: " + Prog_Head;
}
}
• ProgramApp main
import [Link].*;
public class ProgramApp
{
public static void main(String[] args)
{
Scanner scan = new Scanner([Link]);
//Step 1 Create an object
Program prog = new Program();
//Step 2 Input
//Setter
[Link]("Enter program code: ");
String programCode = [Link]();
prog.setProg_Code(programCode);
[Link]("Enter program description: ");
String programDesc = [Link]();
prog.setProg_Desc(programDesc);
[Link]("Enter program duration: ");
int programDuration = [Link]();
prog.setProg_duration(programDuration);
[Link]();
[Link]("Enter Faculty: ");
String faculty = [Link]();
[Link](faculty);
[Link]("Enter program head: ");
String programHead = [Link]();
prog.setProg_Head(programHead);
//normal Constructor
String Prog_Level = [Link]();
[Link]([Link]() + "\nProgram Level: " +
Prog_Level);
}
}
• Input & Output
Figure 1: Example of input and ouput 1.
Figure 2: Example of input and output 2.
• Land Class
public class Land
{
//Data Members
private int Id;
private String Owner_Name;
private char house_type;
private double area;
//Method members
//Default Constructor
public Land()
{
Id = 0;
Owner_Name = "";
house_type = '\0';
area = 0;
}
//Normal Constructor
public Land(int ID, String ON, char HT, double A)
{
Id = ID;
Owner_Name = ON;
house_type = HT;
area = A;
}
//Copy Constructor
public Land(Land l)
{
Id = [Link];
Owner_Name = l.Owner_Name;
house_type = l.house_type;
area = [Link];
}
//Mutator/Setter method
public void setId(int ID)
{
Id = ID;
}
public void setOwner_Name(String ON)
{
Owner_Name = ON;
}
public void sethouse_type(char HT)
{
house_type = HT;
}
public void setarea(double A)
{
area = A;
}
//Getter
public int getId()
{
return Id;
}
public String getOwner_Name()
{
return Owner_Name;
}
public char gethouse_type()
{
return house_type;
}
public double getarea()
{
return area;
}
//Processor
public double CalcTax()
{
double tax = 0;
if (house_type == 'T') {
tax = area * 10;
}
else if (house_type == 'S') {
tax = area * 15;
}
else if (house_type == 'B') {
tax = area * 20;
}
else if (house_type == 'C') {
tax = area * 30;
}
return tax;
}
public String HouseDescription()
{
String Description = "";
if (house_type == 'T') {
Description = "Terrace";
}
else if (house_type == 'S') {
Description = "Semi-Detached";
}
else if (house_type == 'B') {
Description = "Bungalow";
}
else if (house_type == 'C') {
Description = "Condominium";
}
return Description;
}
//Printer
public String toString()
{
return "\n\nUser id: " + Id + "\nOwner name: " + Owner_Name;
}
}
• LandApp main
import [Link].*;
public class LandApp
{
public static void main(String[] args)
{
Scanner scan = new Scanner([Link]);
//Step 1 Create an object
Land land = new Land();
//Step 2 Input
//Setter
[Link]("Enter User Id: ");
int UserId = [Link]();
[Link](UserId);
[Link]();
[Link]("Enter owner name: ");
String Name = [Link]();
land.setOwner_Name(Name);
[Link]("Enter house type: ");
char Type = [Link]().charAt(0);
land.sethouse_type(Type);
[Link]("Enter Area: ");
double AREA = [Link]();
[Link](AREA);
//normal Constructor
double totalTax = [Link]();
String houseType = [Link]();
[Link]([Link]() + "\nHouse type: " +
houseType + "\nTotal tax: " + totalTax);
}
}
• Input & Output
Figure 3:Example of input and output 1.
Figure 4:Example of input and output 2.