OOP Mini Project Report
OOP Mini Project Report
FURNITURE
SEMESTER 1 2015/2016
Lecturer Name: DR. ZALMIYAH BINTI ZAKARIA
Prepared by :
NO NAME MATRIC NO
1 Mardiana binti Abu Hassan SX140047CSJS04
2 Nur Allyyaa binti Abd Halim SX140055CSJS04
3 Nur Syuhada binti Zulkifli SX140104SCSV04
4 Nurul Hidayah binti Anuar SX140056CSJS04
TABLE OF CONTENT
UML Class Diagram…………………………………………………………….. 1-4
Class Explaination………………………………………………………………. 5
1. MyFurniture Class……………………………………………….....…… 5-6
2. Purchaser Class……………………………………………………….…. 7-8
3. TypeOfFurniture……………………………………………………........ 9
4. MySofa Class……………………………………………………………. 10-11
5. MyBedroomSet Class…………………………………………………… 12-13
6. MyKidsSet Class………………………………………………………… 14-15
7. Comparable Interface…………………………………………………… 16
8. ComparableKidsSet Class………………………………………………. 16-17
9. Max Class……………………………………………………………….. 17
10. Member Class…………………………………………………………… 17
11. Membership Class………………………………………………………. 18
12. TestMyFurniture Class………………………………………………….. 18-23
Source Code……………………………………………………………………... 24
1. MyFurniture Class………………………………………………………. 24-25
2. Purchaser Class………………………………………………………….. 26
3. TypeOfFurniture Class………………………………………………….. 27-28
4. MySofa Class……………………………………………………………. 29-30
5. MyBedroomSet Class…………………………………………………… 31-32
6. MyKidsSet Class………………………………………………………… 33-34
7. Comparable Interface…………………………………………………… 35
8. CompaarableKidsSet Class……………………………………………… 36-37
9. Max Class……………………………………………………………….. 38
10. Member Class…………………………………………………………… 39
11. Membership Class………………………………………………………. 40
12. TestMyFurniture Class………………………………………………….. 41-49
Output…………………………………………………………………………… 50-57
Object Oriented Programming : Furniture
Furniture
EA 12.1 Unregistered Trial Version EA 12.1 Unregistered Trial Version EA 12.1 Unregistered Trial Version EA 12.1
«interface»
MyKidsSet Comparable MyFurniture
EA 12.1 Unregistered Trial Version EA 12.1 Unregistered Trial Version EA 12.1 Unregistered Trial Version EA 12.1
- furName + compareTo - date
- kidsId - numOfType: int
- type
EA 12.1 Unregistered Trial Version EA 12.1 Unregistered Trial Version EA 12.1 Unregistered Trial Version EA 12.1
- price: double
EA 12.1 Unregistered Trial Version EA 12.1 Unregistered Trial Version EA 12.1 Unregistered Trial Version EA 12.1
EA 12.1 Unregistered Trial Version EA 12.1 Unregistered Trial Version EA 12.1 Unregistered Trial Version EA 12.1
Membership Member
- nBirthday - nColor
EA 12.1 Unregistered Trial Version EA 12.1 Unregistered Trial Version EA 12.1 Unregistered Trial Version EA 12.1
- nFee: double - nName
- nName - nprice: double
EA 12.1 Unregistered Trial Version EA 12.1 Unregistered Trial Version EA 12.1 Unregistered Trial Version EA 12.1
EA 12.1 Unregistered Trial Version EA 12.1 Unregistered Trial Version EA 12.1 Unregistered Trial Version EA 12.1
EA 12.1 Unregistered Trial Version EA 12.1 Unregistered Trial Version EA 12.1 Unregistered Trial Version EA 12.1
EA 12.1 Unregistered Trial Version EA 12.1 Unregistered Trial Version EA 12.1 Unregistered Trial Version EA 12.1
EA 12.1 Unregistered Trial Version EA 12.1 Unregistered Trial Version EA 12.1 Unregistered Trial Version EA 12.1
EA 12.1 Unregistered Trial Version EA 12.1 Unregistered Trial Version EA 12.1 Unregistered Trial Version EA 12.1
EA 12.1 Unregistered Trial Version EA 12.1 Unregistered Trial Version EA 12.1 Unregistered Trial Version EA 12.1
EA 12.1 Unregistered Trial Version EA 12.1 Unregistered Trial Version EA 12.1 Unregistered Trial1Version EA 12.1
EA 12.1 Unregistered Trial Version EA 12.1 Unregistered Trial Version EA 12.1 Unregistered Trial Version EA 12.1
EA 12.1 Unregistered Trial Version EA 12.1 Unregistered Trial Version EA 12.1 Unregistered Trial Version EA 12.1
Object Oriented Programming : Furniture
Purchaser MyFurniture
- id : final int - type : String
- name : final String - dateOfPurchased : java.util.Date
- furnitureType : String - numOfType : int
- furnitureList : Purchaser[ ]
# MyFurniture ()
+ Purchaser ( int, String, String ) # MyFurniture ( String, String )
+ getName() : String + getType() : String
+ getID : int + setType ( String ) : void
+ getFurnitureType () : String + getDatePurchased () : java.util.Date
+ toString : String + toString : String
+ addFurnitureList ( Purchaser ) : void + addFurnitureList ( Purchaser ) : void
+ printAllInfo () : void
+ getDiscount () : double
Purchaser TypeOfFurniture
- id : final int - id : int
- name : final String - name : String
- furnitureType : String - numOfType : int
- furnitureList : Purchaser[ ]
+ TypeOfFurniture (int m,String,String)
+ Purchaser ( int, String, String ) + getName () : String
+ getName() : String + getMemberId ( int ) : int
+ getID : int + addFurniture (Purchaser ) : void
+ getFurnitureType () : String + getNumOfFurniture (): int
+ toString : String + printAllInfo () : void
+ addFurnitureList ( Purchaser ) : void + listOfFurniture () : void
Purchaser MyFurniture
- id : final int - type : String
- name : final String - dateOfPurchased : java.util.Date
- furnitureType : String - numOfType : int
- furnitureList : Purchaser[ ]
# MyFurniture ( String, String )
+ Purchaser ( int, String, String ) + getType() : String
+ getName() : String + setType ( String ) : void
+ getID : int + getDatePurchased () : java.util.Date
+ getFurnitureType () : String + toString : String
+ toString : String + addFurnitureList ( Purchaser ) : void
+ addFurnitureList ( Purchaser ) : void + printAllInfo () : void
+ getDiscount () : double
2
Object Oriented Programming : Furniture
MySofa
- sofaId : String MyFurniture
- sofaName : String - type : String
- discount : double - dateOfPurchased : java.util.Date
- price : double - numOfType : int
- furnitureList : Purchaser[ ]
+ MySofa() # MyFurniture ( String, String )
+ MySofa(double p) + getType() : String
+ MySofa(String id, String name,
double price) + setType ( String ) : void
+ setPrice() : double + getDatePurchased () : java.util.Date
+ listOfSofa() : void + toString : String
+ readInput() : void + addFurnitureList ( Purchaser ) : void
+ toString() : String + printAllInfo () : void
+ mixColor() : void + getDiscount () : double
+ getDiscount() : double
MyBedroomSet
- bedId : String MyFurniture
- bedName : String - type : String
- type : String - dateOfPurchased : java.util.Date
- price : double - numOfType : int
- furnitureList : Purchaser[ ]
+ MyBedroomSet()
# MyFurniture ( String, String )
+ MyBedroomSet(double p)
+ MyBedroomSet(String newBedId, + getType() : String
String newBedName, double + setType ( String ) : void
newPrice) + getDatePurchased () : java.util.Date
+ getBedName() : String + toString : String
+ typeOfBedroomType() : String + addFurnitureList ( Purchaser ) : void
+ readInput() : void + printAllInfo () : void
+ toString() : String + getDiscount () : double
+ showPrice() : void
+ getDiscount() : double
3
Object Oriented Programming : Furniture
MyKidsSet
- kidsId : String
- furName : String
- price : double
+ MyKidsSet()
+ MyKidsSet(double p)
+ MyKidsSet(String newId, String
newFurName, double newPrice)
+ getPrice() : double
+ typeOfBedroomType() : String
+ mysteryGift() : void
+ showPrice() : String
MyKidsSet
- kidsId : String
- furName : String
- price : double
+ MyKidsSet()
+ MyKidsSet(double p)
+ MyKidsSet(String newId, String
newFurName, double newPrice)
+ getPrice() : double
+ typeOfBedroomType() : String
+ mysteryGift() : void
+ showPrice() : String
Comparable
<interface>
+ compareTo(ComparableKidsSet o)
4
Object Oriented Programming : Furniture
CLASS EXPLAINATION
1. MyFurniture Class
MyFurniture defined as the superclass for MySofa and MyBedroomSet. MyFurniture
models common features of furniture. Both MySofa and MyBedroomSet contains
getDiscount() methods to calculate the discount given by the GA Sofa Company.
MyFurniture is an abstract class which the discount can be calculated in both MySofa
and MyBedroomSet class; getDiscount() method has been defined in MyFurniture
class because its implementation depends on the specific price that have been
initialized to each furniture type. Such methods are referred to as abstract methods
and are denoted using abstract modifier in the method header.
public abstract double getDiscount();
Once the methods has been defined in MyFurniture, this class will become an
abstract class and will be denoted using the abstract modifier in the class header :
public abstract class MyFurniture { }
This class declared type and numOfType as variable which is type is from String data
type while numOfType is an Integer data type. This class also declare datePurchased
as variable and used a Package from Date which it is a class to represent a specific
instant in time with millisecond precision when the Purchaser bought their furniture.
Finally, this class also create an array named furnitureList which hold a number of
purchaser and there is a one to one relationship (Association) between two classes :
MyFurniture and Purchaser
Purchaser MyFurniture
- id : final int - type : String
- name : final String - dateOfPurchased : java.util.Date
- furnitureType : String - numOfType : int
- furnitureList : Purchaser[ ]
# MyFurniture ()
+ Purchaser ( int, String, String ) # MyFurniture ( String, String )
+ getName() : String + getType() : String
+ getID : int + setType ( String ) : void
+ getFurnitureType () : String + getDatePurchased () : java.util.Date
+ toString : String + toString : String
+ addFurnitureList ( Purchaser ) : void + addFurnitureList ( Purchaser ) : void
+ printAllInfo () : void
+ getDiscount () : double
Figure 1.0
5
Object Oriented Programming : Furniture
For printAllInfo () method, this method will list all type of furniture. This method also
called typeOfFurniture () method which return String.
Output :
1. Sofa Set
2. Bedroom Set List of Furniture
3. Kids Set
The last method that has been declare in MyFurniture class is a double primitive type
named getDiscount () method. This is an abstract method which is we only declare the
method in parent and will define the whole process to calculate discount in their
subclass which is MySofa and MyBedroomSet
6
Object Oriented Programming : Furniture
2. Purchaser Class
Purchaser was built with three two primitive data type in three variables which is id,
name and furtnitureType. This is a concrete class where it has only one constructor
three set of assessor method.
The constructor contains three parameter with String and Integer primitive data type.
The three data attributes declare in Purchaser class are constants and have been
named as id, name and furnitureType. This class also have three accessor mothod
which is getName () to return String, getID () to return Integer and get furnitureType
() to return String.
Purchaser class has one to one class relationship between MyFurniture and
TypeOfFurniture called Association
Purchaser TypeOfFurniture
- id : final int - id : int
- name : final String - name : String
- furnitureType : String - numOfType : int
- furnitureList : Purchaser[ ]
+ TypeOfFurniture (int m,String,String)
+ Purchaser ( int, String, String ) + getName () : String
+ getName() : String + getMemberId ( int ) : int
+ getID : int + addFurniture (Purchaser ) : void
+ getFurnitureType () : String + getNumOfFurniture (): int
+ toString : String + printAllInfo () : void
+ addFurnitureList ( Purchaser ) : void + listOfFurniture () : void
Figure 1.
7
Object Oriented Programming : Furniture
Purchaser MyFurniture
- id : final int - type : String
- name : final String - dateOfPurchased : java.util.Date
- furnitureType : String - numOfType : int
- furnitureList : Purchaser[ ]
# MyFurniture ( String, String )
+ Purchaser ( int, String, String ) + getType() : String
+ getName() : String + setType ( String ) : void
+ getID : int + getDatePurchased () : java.util.Date
+ getFurnitureType () : String + toString : String
+ toString : String + addFurnitureList ( Purchaser ) : void
+ addFurnitureList ( Purchaser ) : void + printAllInfo () : void
+ getDiscount () : double
Figure 1.2
8
Object Oriented Programming : Furniture
3. TypeOfFurniture
TypeOfFurnitures is a solid class written with four types of variables with different
type of data type. It use String, integer, java Date package and a constant array named
furnitureList which is related with Purchaser. This class contains a constructor with
parameters, an acsessor and another two methods.
The constructor with arguments consist an Integer and String data type known as
name, memberId and furnitureList. Acsessor method which is getName (),
getMemberId and getNumOfFurniture should be able to allows the other class to
view the content of an attributes.
TypeOfFurniture class has one to one class relationship between MyFurniture and
Purchaser. This type of class relationship known as Association.
Method printAllInfo () will display all details of the furniture which are using for
looping to allows the codes can be repeated as long as the Boolean Expression is true.
Purchaser TypeOfFurniture
- id : final int - id : int
- name : final String - name : String
- furnitureType : String - numOfType : int
- furnitureList : Purchaser[ ]
+ TypeOfFurniture (int m,String,String)
+ Purchaser ( int, String, String ) + getName () : String
+ getName() : String + getMemberId ( int ) : int
+ getID : int + addFurniture (Purchaser ) : void
+ getFurnitureType () : String + getNumOfFurniture (): int
+ toString : String + printAllInfo () : void
+ addFurnitureList ( Purchaser ) : void + listOfFurniture () : void
Figure 1.3
9
Object Oriented Programming : Furniture
Purchaser s = (Purchaser)furnitureList[i];
System.out.println((i+1) + ". " + s.getName()); }
4. MySofa Class
MySofa was defined as the subclass for MyFurniture written with four types of
variables with different type of data type. It contains getDiscount() methods for
calculate discount given by the GA Sofa Company. MySofa was an child class of
MyFurniture which is since the discount can be calculated in its class; getDiscount()
method has been define in MyFurniture class because its implementation depends on
the specific price that have been initialize to every furniture type. Such methods are
referred to as abstract methods from superclass and are denoted using abstract
modifier in the method header.
public double getDiscount() //Abstract Method
{
//double newDiscount;
{
sofaId = "";
sofaName = "";
price = 0.0;
}
public MySofa(double p)
{
price = p;
}
{
sofaId = id;
sofaName = name;
price = price;
}
10
Object Oriented Programming : Furniture
MySofa MyFurniture
- sofaId : String - type : String
- sofaName : String - dateOfPurchased : java.util.Date
- discount : double - numOfType : int
- price : double - furnitureList : Purchaser[ ]
# MyFurniture ( String, String )
+ MySofa() + getType() : String
+ MySofa(double p) + setType ( String ) : void
+ MySofa(String id, String name,
+ getDatePurchased () : java.util.Date
double price)
+ toString : String
+ setPrice() : double
+ addFurnitureList ( Purchaser ) : void
+ listOfSofa() : void
+ printAllInfo () : void
+ readInput() : void
+ toString() : String + getDiscount () : double
+ mixColor() : void
+ getDiscount() : double
The method listOfSofa() is used to display the sofa list name that have been chosen by the
buyer.
public void listOfSofa()
{
JDialog.setDefaultLookAndFeelDecorated(true);
System.out.print("\n");
Object[] selectionValues = { "GA233 Lousiana", "GA235
Gorgia", "GA236 Ottava" };
String initialSelection = "GA233 Louisiana";
Object selection = JOptionPane.showInputDialog(null,
"Your Favourite Sofa Set?",
"Your Favourite Sofa Set",
JOptionPane.QUESTION_MESSAGE, null, selectionValues,
initialSelection);
System.out.println("Your choosen Sofa Set is : " +
selection);
}
{
Scanner input = new Scanner(System.in);
11
Object Oriented Programming : Furniture
5. MyBedroomSet Class
MyBedroomSet was defined as the subclass for MyFurniture written with four types
of variables with different type of data type. It contains getDiscount() methods for
calculate discount given by the GA Sofa Company. MyBedroomSet was an child class
of MyFurniture which is since the discount can be calculated in its class;
getDiscount() method has been define in MyFurniture class because its
implementation depends on the specific price that have been initialize to every
furniture type. Such methods are referred to as abstract methods from superclass and
are denoted using abstract modifier in the method header.
public double getDiscount() {
return price -(price*0.05);
}
}
MyBedroomSet class have default constructor and constructor overloading as below:
public MyBedroomSet()
{
bedId = "";
bedName = "";
price = 0.0;
}
public MyBedroomSet(double p) {
price = p;
}
12
Object Oriented Programming : Furniture
MyBedroomSet MyFurniture
- bedId : String - type : String
- bedName : String - dateOfPurchased : java.util.Date
- type : String - numOfType : int
- price : double - furnitureList : Purchaser[ ]
# MyFurniture ( String, String )
+ MyBedroomSet()
+ getType() : String
+ MyBedroomSet(double p)
+ setType ( String ) : void
+ MyBedroomSet(String newBedId,
String newBedName, double + getDatePurchased () : java.util.Date
newPrice) + toString : String
+ getBedName() : String + addFurnitureList ( Purchaser ) : void
+ typeOfBedroomType() : String + printAllInfo () : void
+ readInput() : void + getDiscount () : double
+ toString() : String
+ showPrice() : void
+ getDiscount() : double
13
Object Oriented Programming : Furniture
6. MyKidsSet Class
MyKidsSet is an abstract class and was a superclass to ComparableKidsSet class. This
class was declare three set of data attribute which is kidsId, furName and price where
kidsId and furName is a String while price is double.
MyKidsSet class have a few list of methods that have been used such as a
constructors, acsessor and the other method that will discuss later. This class also has
an implementation by using an Interface.
MyKidsSet () is no-argument constructor where all values of the three variables that
have been declared is set to default, in which Java will set all of the object’s numeric
variables to 0 and reference variable to the special value null. This class used
constructor with one argument and three argument. This type of constructors known
as an Overloading Constructor.
public MyKidsSet()
public MyKidsSet(double p)
public MyKidsSet(String newId, String newFurName, double
newPrice)
getPrice () was declared as double return type and also used keyword this which is
referred to the current instance of the method.
showPrice () method is able to request input from keyboard by using Scanner class
that have been provided by Java. Types of choosen kids set and prices will be
displayed based on the kid’s set id entered using switch case.
14
Object Oriented Programming : Furniture
The mysteryGift () method is using a package that have been provided by Java which
is JDialog and JOpitonPane. User can choose their sofa set and colors. This method
also use constant array to display both sofa and colors.
15
Object Oriented Programming : Furniture
7. Comparable Interface
Comparable Interface is an interface for comparing object that have been defined in
java.lang. This is accomplished by letting the class for the object implement this
interface using the implements keyword. The relationship between the class and the
interface is known as interface inheritance.
package furniture;
The compareTo () method determines the order of this object with the specified object
o and returns a negative integer, zero or positive integer if this object is less than,
equal or more greater than o.
8. ComparableKidsSet Class
Comparable extends MyKidSet implements Comparable as shown below inherits all
the contants from the Comparable interface and implements the methods in the
interface.
The compareTo () method compares the price of the two kids set. An instance of
ComparabeKidsSet is also an instance of MyKidsSet and Comparable.
}
public int compareTo(ComparableKidsSet o) {
if(getPrice() > ((ComparableKidsSet)o).getPrice())
return 1;
else if(getPrice() <
((ComparableKidsSet)o).getPrice())
return -1;
else
return 0;
}
16
Object Oriented Programming : Furniture
showPrice () method is able to request input from keyboard by using Scanner class
that have been provided by Java. Types of choosen kids set and prices will be
displayed based on the kid’s set id entered using switch case.
9. Max Class
In Max class, o1 is declared as ComparableKidsSet and (Comparable)o1 tells the
compiler to cast o1 into Comparable so that the compareTo method can be invoked
from o1.
public static ComparableKidsSet max(ComparableKidsSet
o1,ComparableKidsSet o2){
if(((ComparableKidsSet)o1).compareTo(o2) > 0){
System.out.println("\nYour 1st item is more
expensive then 2nd item");
return o1;
}
else{
System.out.print("\nYour 2nd item is more cheaper.
Enjoy!!");
return o2;
}
}
The constructor with arguments consist an String and double data type known as
name, color and price. Accessor method which is getName (), getColor and getPrice
should be able to allows the other class to view the content of an attributes.
17
Object Oriented Programming : Furniture
The constructor with arguments consist a String and double data type known as
nName, nBirth and nFee. Accessor method which is getName (), getBirthday and
getFees should be able to allows the other class to view the content of an attributes.
The ArrayList is used in here to store unlimited number of furniture and membership
for this system.
ArrayList<Member> stud = new ArrayList<>();
ArrayList<Membership> ship = new ArrayList<>();
Boolean control is also been used in this system to let the system to called
displayMenu () method in both for Member’s and Furniture’s in which the system will
display menu first to let the user choose the menu as long as the boolean control is
true. Once the user has chosen their menu, then the chosen menu number will display.
return select;
}
18
Object Oriented Programming : Furniture
The if – else statement below will execute one group of statement based on user
selection. The methods in each if – else statement will be called and the values of the
methods will be assigned to the new Member object which is mem1. Finally the
ArrayList for Member class will append new furniture in the array. The process is all
same for creating new furniture into the specific index and to remove specific index
funriture’s and finally will displayed it on the table.
The if – else statement below will execute one group of statement based on user
selection. The methods in each if – else statement will be called and the values of the
methods will be assigned to the new Membership object which is ship1. Finally the
ArrayList for Membership class will append new member in the array. The process is
19
Object Oriented Programming : Furniture
all same for creating new member into the specific index and to remove specific index
member’s and finally will displayed it on the table.
}
for(int i = 0;i<a;i++){
20
Object Oriented Programming : Furniture
This explanation is about how to manage the chosen furniture by members. MySofa
and MyBedroom will be creating new object while MyFurniture will creating new
object and pass it by value to MyBedroomSet and MySofa.
The codes below explain how an association relationship between Purchaser and
TypeOfFurniture is implemented.
Purchaser p1 = new Purchaser(001, "Mardiana", "Kids Set");
Purchaser p2 = new Purchaser(002, "Syuhada", "Bedroom Set");
Purchaser p3 = new Purchaser(003, "Allyyaa", "Sofa Set");
System.out.println("\n" +ms1.toString());
equalDiscount(object1,object2));
The totalPaid (object1,object2) was defined in main used to calculate total between
the two price
21
Object Oriented Programming : Furniture
This application was used Comparable Interface to compare price between to items in
KidsSet class. In order to accomplish this, the Comparable Interface was defined in
the Comparable class. The compareTo () method determines the order of this object
with the specified object o and return a negative interger, zero or positive integer if
this object is less then, equal or greater than o.
A generic max method was defined in Max class to tells the compiler to cast o1 into
Comparable so that the compareTo () method can be invoked from o1.
22
Object Oriented Programming : Furniture
}
else{
System.out.print("\nYour 2nd item is more cheaper.
Enjoy!!");
return o2;
}
}
23
Object Oriented Programming : Furniture
SOURCE CODES
MyFurniture Class
/**
* @author myTeam --> MARDIANA | NUR ALLYYAA | NUR SYUHADA | NURUL HIDAYAH
*/
package furniture;
import java.text.DecimalFormat;
/** Construct a furniture object with the specified type and choice
* @return
* @param type
* @param c
* @param numOfType
*/
protected MyFurniture(String type, String c) {
datePurchased = new java.util.Date();
this.type = type;
furnitureList = new Purchaser[5];
}
/**Return type
* @return */
public String getType() {
return type;
}
24
Object Oriented Programming : Furniture
25
Object Oriented Programming : Furniture
SOURCE CODES
Purchaser Class
/**
* @author myTeam --> MARDIANA | NUR ALLYYAA | NUR SYUHADA | NURUL HIDAYAH
*/
package furniture;
26
Object Oriented Programming : Furniture
SOURCE CODES
TypeOfFurniture Class
/**
* @author myTeam --> MARDIANA | NUR ALLYYAA | NUR SYUHADA | NURUL HIDAYAH
*/
package furniture;
27
Object Oriented Programming : Furniture
}
}
28
Object Oriented Programming : Furniture
SOURCE CODES
MySofa Class
/**
* @author myTeam --> MARDIANA | NUR ALLYYAA | NUR SYUHADA | NURUL HIDAYAH
*/
package furniture;
import java.util.Scanner;
import javax.swing.JDialog;
import javax.swing.JOptionPane;
public MySofa()
{
sofaId = "";
sofaName = "";
price = 0.0;
}
public MySofa(double p)
{
price = p;
}
{
price = newPrice;
}
29
Object Oriented Programming : Furniture
{
JDialog.setDefaultLookAndFeelDecorated(true);
System.out.print("\n");
Object[] selectionValues = { "GA233 Lousiana", "GA235 Gorgia", "GA236
Ottava" };
String initialSelection = "GA233 Louisiana";
Object selection = JOptionPane.showInputDialog(null, "Your Favourite Sofa
Set?", "Your Favourite Sofa Set", JOptionPane.QUESTION_MESSAGE,
null, selectionValues, initialSelection);
System.out.println("Your choosen Sofa Set is : " + selection);
}
{
Scanner input = new Scanner(System.in);
@Override
public String toString() {
return "Thank You!. Your Purchased Date is on " + datePurchased ;
}
{
JDialog.setDefaultLookAndFeelDecorated(true);
System.out.print("\n");
System.out.print("Ohh wait!!!You can choose your favourite color too!!!");
Object [] selectionValues = {"Red and Black", "Pink and Turqoise", "Light
Green and Cream", "Orrange and Light Green"};
String initialSelection = "Red and Black";
Object selection = JOptionPane.showInputDialog(null, "Mix and Match",
"Mix and Match", JOptionPane.QUESTION_MESSAGE, null, selectionValues,
initialSelection);
System.out.println("Colour : " + selection);
}
//Abstract
public double getDiscount()
{
return price -(price*0.10);
}
}
30
Object Oriented Programming : Furniture
SOURCE CODES
MyBedroomSet Class
/**
* @author myTeam --> MARDIANA | NUR ALLYYAA | NUR SYUHADA | NURUL HIDAYAH
*/
package furniture;
import java.util.Scanner;
public MyBedroomSet()
{
bedId = "";
bedName = "";
price = 0.0;
}
public MyBedroomSet(double p) {
price = p;
}
newType = input.nextLine();
31
Object Oriented Programming : Furniture
case "QUEEN":
newType = "G046 Exquisite Twin Set";
System.out.println("G046 Exquisite Twin Set");
break;
case "KING":
newType = "G047 Chatham King Set";
System.out.println("G047 Chatham King Set");
break;
default:
System.out.println("Invalid choice!!");
System.exit(0);
}
return newType;
{
Scanner input = new Scanner(System.in);
@Override
public String toString() {
return super.toString() + "\nPurchased on :" + datePurchased;
}
//@Abstract Method
public double getDiscount() {
return price -(price*0.05);
}
}
32
Object Oriented Programming : Furniture
SOURCE CODES
MyKidsSet Class
/**
* @author myTeam --> MARDIANA | NUR ALLYYAA | NUR SYUHADA | NURUL HIDAYAH
*/
package furniture;
import java.util.Scanner;
import javax.swing.JOptionPane;
import javax.swing.JDialog;
public MyKidsSet()
{
kidsId = "";
furName = "";
price = 0.0;
}
public MyKidsSet(double p) {
price = p;
}
switch(kidsId)
{
case("IK001"):
price = 45.00;
System.out.print("Price is RM :" + price);
break;
33
Object Oriented Programming : Furniture
case("IK002"):
price = 100.00;
System.out.print("Price is RM :" + price);
break;
case("IK003"):
price = 250.00;
System.out.print("Price is RM :" + price);
break;
case("IK004"):
price = 150.00;
System.out.print("Price is RM :" + price);
break;
case("IK005"):
price = 450.00;
System.out.print("Price is RM :" + price);
break;
default:
System.out.println("Invalid choice!!");
System.exit(0);
}
return kidsId;
}
34
Object Oriented Programming : Furniture
SOURCE CODES
Comparable Interface
/**
*
* @author myTeam --> MARDIANA | NUR ALLYYAA | NUR SYUHADA | NURUL HIDAYAH
*/
package furniture;
35
Object Oriented Programming : Furniture
SOURCE CODES
ComparableKidsSet Class
/**
*
* @author myTeam --> MARDIANA | NUR ALLYYAA | NUR SYUHADA | NURUL HIDAYAH
*/
package furniture;
import java.util.Scanner;
public ComparableKidsSet() {}
switch(kidsId)
{
case("IK001"):
price = 45.00;
System.out.printf("Price is RM%.2f ", price);
break;
case("IK002"):
price = 100.00;
System.out.printf("Price is RM%.2f ",price);
36
Object Oriented Programming : Furniture
break;
case("IK003"):
price = 250.00;
System.out.printf("Price is RM%.2f ",price);
break;
case("IK004"):
price = 150.00;
System.out.printf("Price is RM%.2f ", price);
break;
case("IK005"):
price = 450.00;
System.out.printf("Price is RM%.2f ",price);
break;
default:
System.out.println("Invalid choice!!");
System.exit(0);
}
return kidsId;
}
37
Object Oriented Programming : Furniture
SOURCE CODES
Max Class
/**
*
* @author myTeam --> MARDIANA | NUR ALLYYAA | NUR SYUHADA | NURUL HIDAYAH
*/
package furniture;
38
Object Oriented Programming : Furniture
SOURCE CODES
Member Class
package furniture;
/**
*@author myTeam --> MARDIANA | NUR ALLYYAA | NUR SYUHADA | NURUL HIDAYAH
*/
public Member()
{
nName = "";
nColor = "";
nprice = 0.0;
}
39
Object Oriented Programming : Furniture
SOURCE CODES
Membership Class
/**
*@author myTeam --> MARDIANA | NUR ALLYYAA | NUR SYUHADA | NURUL HIDAYAH
*/
package furniture;
public Membership()
{
nName = "";
nBirthday = "";
nFee = 0.0;
}
40
Object Oriented Programming : Furniture
SOURCE CODES
TestMyFurniture Class
/**
* @author myTeam --> MARDIANA | NUR ALLYYAA | NUR SYUHADA | NURUL HIDAYAH
*/
package furniture;
import java.util.ArrayList;
import java.util.Scanner;
import java.text.DecimalFormat;
System.out.print("\n///////////////////////////////////////////////////////////");
System.out.print("\n///////////////////////////////////////////////////////////");
System.out.print("\n\n\n");
//********************************************************************************
//To Display Furniture Menu
//********************************************************************************
ArrayList<Member> stud = new ArrayList<>();
while(control){
int displayMenu = displayMenu();
int userSelection = userSelection(displayMenu);
System.out.println("User selects : " + userSelection);
if(userSelection==1){
System.out.println("*******************************************");
System.out.println("\t\tEnter New Data ");
System.out.println("*******************************************");
Scanner option = new Scanner(System.in);
System.out.print("How many set of furniture you want to add: ");
int op = option.nextInt();
41
Object Oriented Programming : Furniture
for(int i = 0;i<op;i++){
Member mem1 = input();
stud.add(mem1);
}
}
else if (userSelection==2){
else if (userSelection==0){
control = false;
}
else if (userSelection==3){
Scanner inp = new Scanner(System.in);
System.out.println("Enter index number: ");
int index = inp.nextInt();
Member std = option3();
stud.add(index, std);
}
else if (userSelection==4){
System.out.println("\nThanks for adding to the directory\n");
displayTable();
System.out.println("===========================================================");
System.out.println("\n");
}
//End Of Furniture Array List
42
Object Oriented Programming : Furniture
//********************************************************************************
//To Display Membership Menu
//********************************************************************************
while(control1){
int displayMenu1 = displayMenu1();
int userSelection1 = userSelection1(displayMenu1);
System.out.println("User selects : " + userSelection1);
if(userSelection1==1){
System.out.println("*******************************************");
System.out.println("\t\tEnter New Membership Details ");
System.out.println("*******************************************");
Scanner opt = new Scanner(System.in);
System.out.print("How many members you want to register today: ");
int a = opt.nextInt();
for(int i = 0;i<a;i++){
}
else if (userSelection1==2){
else if (userSelection1==0){
control1 = false;
}
else if (userSelection1==3){
Scanner in = new Scanner(System.in);
System.out.println("Enter index number: ");
int ind = in.nextInt();
Membership st = option5();
ship.add(ind, st);
}
else if (userSelection1==4){
System.out.println("\nThanks for adding to the directory\n");
displayTable1();
43
Object Oriented Programming : Furniture
}
}
System.out.println("===========================================================");
System.out.println("\n");
}
//End Of Membership Array
//********************************************************************************
//To Manage Purchaser Details of Purchased Item
//********************************************************************************
/*Abstract*/
MyFurniture object2 = new MyBedroomSet(5000);
MyFurniture object1 = new MySofa(10000);
/** Association*/
System.out.println();
System.out.println("TO MANAGE PURCHASER DETAILS OF PURCHASED ITEM");
System.out.println("Here Is Your Purchaser Details | " + object1.toString());
System.out.println();
System.out.println("\n" +ms1.toString());
System.out.println();
44
Object Oriented Programming : Furniture
System.out.println("\nBedroom Descriptions");
b1.typeOfBedroomType();
System.out.println();
System.out.println("*******************************************");
System.out.printf("Total Amount Paid is : RM %.2f",
totalPaid(object1,object2));
System.out.println("\n*******************************************");
s2.listOfFurniture();
System.out.println();
System.out.println(Max.max(kids1, kids2));
/** A method for comparing the discount of the two MyFurniture Object | Abstract
Class
*
* @param object1
* @param object2
* @return
*/
public static boolean equalDiscount(MyFurniture object1, MyFurniture object2) {
return object1.getDiscount() == object2.getDiscount();
}
45
Object Oriented Programming : Furniture
/** A method for displaying the discount of the two MyFurniture Object */
public static void displayMyFurnitureObject(MyFurniture object) {
System.out.printf("Total Price After Discount Is RM %.2f ",
object.getDiscount() );
}
//********************************************************************************
//To Display Menu Of The Application
//********************************************************************************
return select;
}
46
Object Oriented Programming : Furniture
else if (a==5){
System.out.println("5 selected");
b=5;
}
else if (a==0){
System.out.println("Exit");
b=0;
}
else
System.out.println("Error");
return b;
}
//End Furniture Menu
return select;
}
47
Object Oriented Programming : Furniture
else if (a==0){
System.out.println("Exit");
b=0;
}
else
System.out.println("Error");
return b;
}
//End Of Membership Menu
System.out.println("===========================================================");
String format = "%1$-15s%2$-25s%3$-10s\n";
System.out.format(format, "Furniture's Name", "Furniture's Color", "Furniture
Price");
System.out.println("===========================================================");
}
System.out.println("===========================================================");
String format = "%1$-15s%2$-25s%3$-10s\n";
System.out.format(format, "Member's Name", "Member's Birthday", "Member's
Fee");
System.out.println("===========================================================");
}
48
Object Oriented Programming : Furniture
49
Object Oriented Programming : Furniture
OUTPUT
////////////////////////////////////////////////////////////////
//Mardiana binti Abu Hassan SX140047CSJS04//////////////////
//Nur Allyyaa binti Abdul Halim SX140055CSJS04//////////////////
//Nur Syuhadah binti Zulkifli SX1401047SCSV04//////////////////
//Nurul Hidayah binti Anuar SX140056CSJS04//////////////////
//Application Name : Furniture//////////////////////////////////
////////////////////////////////////////////////////////////////
==========================
GA Sofa Furniture Details
==========================
1 - Add New Furniture
2 - Remove Furniture
3 - Add Furniture to Specific Index
4 - Display Furniture Information
0 - Exit
==========================
Your Selection : 1
1 selected
User selects : 1
*******************************************
Enter New Data
*******************************************
How many set of furniture you want to add: 3
*******************************************
Enter your details
*******************************************
Enter furniture name :Lousiana
Enter color :Black and Red
Enter price :2500
*******************************************
Enter your details
*******************************************
Enter furniture name :Catham
Enter color :White
Enter price :5500
*******************************************
Enter your details
*******************************************
Enter furniture name :Rocking Chair
Enter color :White
Enter price :45
====================================================================
50
Object Oriented Programming : Furniture
==========================
GA Sofa Furniture Details
==========================
1 - Add New Furniture
2 - Remove Furniture
3 - Add Furniture to Specific Index
4 - Display Furniture Information
0 - Exit
==========================
Your Selection : 4
4 selected
User selects : 4
====================================================================
Furniture's NameFurniture's Color Furniture Price
====================================================================
Lousiana Black and Red 2500.00
Catham White 5500.00
Rocking Chair White 45.00
====================================================================
==========================
GA Sofa Furniture Details
==========================
1 - Add New Furniture
2 - Remove Furniture
3 - Add Furniture to Specific Index
4 - Display Furniture Information
0 - Exit
==========================
Your Selection : 2
2 selected
User selects : 2
Insert index to remove
1
====================================================================
==========================
GA Sofa Furniture Details
==========================
1 - Add New Furniture
2 - Remove Furniture
3 - Add Furniture to Specific Index
4 - Display Furniture Information
0 - Exit
==========================
Your Selection : 4
4 selected
User selects : 4
51
Object Oriented Programming : Furniture
====================================================================
Furniture's NameFurniture's Color Furniture Price
====================================================================
Lousiana Black and Red 2500.00
Rocking Chair White 45.00
====================================================================
==========================
GA Sofa Furniture Details
==========================
1 - Add New Furniture
2 - Remove Furniture
3 - Add Furniture to Specific Index
4 - Display Furniture Information
0 - Exit
==========================
Your Selection : 3
3 selected
User selects : 3
Enter index number:
1
Enter furniture name :Ottava
Enter color :White
Enter price :4500
====================================================================
==========================
GA Sofa Furniture Details
==========================
1 - Add New Furniture
2 - Remove Furniture
3 - Add Furniture to Specific Index
4 - Display Furniture Information
0 - Exit
==========================
Your Selection : 4
4 selected
User selects : 4
====================================================================
Furniture's NameFurniture's Color Furniture Price
====================================================================
Lousiana Black and Red 2500.00
Ottava White 4500.00
Rocking Chair White 45.00
====================================================================
52
Object Oriented Programming : Furniture
==========================
GA Sofa Furniture Details
==========================
1 - Add New Furniture
2 - Remove Furniture
3 - Add Furniture to Specific Index
4 - Display Furniture Information
0 - Exit
==========================
Your Selection : 0
Exit
User selects : 0
====================================================================
==========================
GA Sofa Membership Details
==========================
1 - Add New Member
2 - Remove Member
3 - Add Member to Specific Index
4 - Display Member's Information
0 - Exit
==========================
Your Selection : 1
1 selected
User selects : 1
*******************************************
Enter New Membership Details
*******************************************
How many members you want to register today: 4
*******************************************
Enter your details
*******************************************
Enter Member name :Mardiana
Enter Member Birthday :Jan 82
Enter Member Fees Registration :100
*******************************************
Enter your details
*******************************************
Enter Member name :Allyyaa
Enter Member Birthday :Sept 92
Enter Member Fees Registration :120
*******************************************
Enter your details
*******************************************
Enter Member name :Syu
Enter Member Birthday :Jun 90
Enter Member Fees Registration :130
*******************************************
Enter your details
*******************************************
Enter Member name :Hidayah
Enter Member Birthday :Sept 92
53
Object Oriented Programming : Furniture
====================================================================
==========================
GA Sofa Membership Details
==========================
1 - Add New Member
2 - Remove Member
3 - Add Member to Specific Index
4 - Display Member's Information
0 - Exit
==========================
Your Selection : 4
4 selected
User selects : 4
====================================================================
Member's Name Member's Birthday Member's Fee
====================================================================
Mardiana Jan 82 100.00
Allyyaa Sept 92 120.00
Syu Jun 90 130.00
Hidayah Sept 92 120.00
====================================================================
==========================
GA Sofa Membership Details
==========================
1 - Add New Member
2 - Remove Member
3 - Add Member to Specific Index
4 - Display Member's Information
0 - Exit
==========================
Your Selection : 2
2 selected
User selects : 2
Insert index to remove
2
====================================================================
==========================
GA Sofa Membership Details
==========================
1 - Add New Member
2 - Remove Member
3 - Add Member to Specific Index
4 - Display Member's Information
0 - Exit
==========================
Your Selection : 4
54
Object Oriented Programming : Furniture
4 selected
User selects : 4
====================================================================
Member's Name Member's Birthday Member's Fee
====================================================================
Mardiana Jan 82 100.00
Allyyaa Sept 92 120.00
Hidayah Sept 92 120.00
====================================================================
==========================
GA Sofa Membership Details
==========================
1 - Add New Member
2 - Remove Member
3 - Add Member to Specific Index
4 - Display Member's Information
0 - Exit
==========================
Your Selection : 3
3 selected
User selects : 3
Enter index number:
3
Enter Member's name :Syuhada
Enter Member's Birthday :Jun 92
Enter Member's fee Registration :120
====================================================================
==========================
GA Sofa Membership Details
==========================
1 - Add New Member
2 - Remove Member
3 - Add Member to Specific Index
4 - Display Member's Information
0 - Exit
==========================
Your Selection : 4
4 selected
User selects : 4
55
Object Oriented Programming : Furniture
====================================================================
Member's Name Member's Birthday Member's Fee
====================================================================
Mardiana Jan 82 100.00
Allyyaa Sept 92 120.00
Hidayah Sept 92 120.00
Syuhada Jun 92 120.00
====================================================================
==========================
GA Sofa Membership Details
==========================
1 - Add New Member
2 - Remove Member
3 - Add Member to Specific Index
4 - Display Member's Information
0 - Exit
==========================
Your Selection : 0
Exit
User selects : 0
====================================================================
Ohh wait!!!You can choose your favourite color too!!!Colour : Red and Black
Total Price After Discount Is RM 9000.00
Thank You!. Your Purchased Date is on Wed Dec 23 23:04:52 SGT 2015
Bedroom Descriptions
Enter your preferred size of bedroom set : SINGLE | QUEEN | KING : QUEEN
G046 Exquisite Twin Set
Total Price After Discount Is RM 4750.00
*******************************************
Total Amount Paid is : RM 13750.00
*******************************************
56
Object Oriented Programming : Furniture
Hi! Here is the list of furniture that you can choose for your kiddos!! =)
57