Group 6
Group 6
Group 6
NAME STUDENT ID
AHMAD ALIF BIN ABD KAHAR 2023172959
MUHAMMAD AIRISHAH ILHAM 2023140809
MUHAMMAD FARIZ BIN ZAIMI 2023364973
MUHAMMAD SHAFIQ HAIQAL BIN HISAMUDDIN 2023147911
MUHAMMAD AFIQ BIN ROY 2023164385
1
TABLE OF CONTENT
CONTENT PAGE
2.0 INTRODUCTION 4
2.1 OBJECTIVE
8.0 REFERENCE 52
2
1.0 ORGANIZATIONAL STRUCTURE
3
2.0 INTRODUCTION
Technology has reshaped consumer behaviour where everything can communicate
and purchase through online shopping. This project report will delve into the Object-Oriented
Programming based Shopping System, outlining its design, implementation, and its core
features. The system blends technology and effective management to deliver user-friendly
interface for phone model selection and purchases, repair services, database management,
Shipping, and receipt. It encapsulates the spirit of Object-Oriented Programming, offering
modular, organized, and reusable code.
Our research report explores the intricacies of the Object-Oriented Programming (OOP)-
based Shopping System and its impact on consumer interaction with businesses. This easy-
to-use platform enables users to seamlessly browse and purchase mobile phone models,
and request repairs.
The system's user-friendly design ensures a hassle-free shopping experience. The repair
service feature efficiently resolves device-related issues, while the robust database
management system guarantees the accuracy of stored information, including product
details, customer information, and sales records.
In summary, the Object-Oriented Programming-based Shopping System is a comprehensive
and efficient platform that integrates technology with effective management practices,
resulting in an unmatched shopping experience. Its modular and scalable code makes it
suitable for organizations of all sizes.
2.1 OBJECTIVES
1. Develop an Object-Oriented Programmming based Shopping System of Phone Market
that smoothly integrates technology and effective management. The System will include
various of online shopping, including phone model selection, purchase transactions and
repair services also integrating more feature for seller so that the sellers can access to data
of availability of various phone model, customer data to track their customer payment and
repairment.
2. Design user-friendly interface that prioritize to ease the interaction for the user to navigate
through selection of phone models, simplify the purchase process and improving the overall
user experience.
3. Develop a system that emphasis on Object-Oriented programming through fundamental
concept of Object-Orented programming that are Abstraction, Encapsulation, inheritance,
and polymorphism to provide advantages such as code reusability, make the system easier
to maintained and effortless for new features to be added or removed.
4. Designing a system to ease the customer to have an appointment with the store staff to
be it repair, selling or purchasing.
4
3.0 UML DIAGRAM
3.1 CLASS DIAGRAM
5
3.2 USE CASE DIAGRAM
6
4.0 INPUT DATA
CustomerData.txt
PhoneData.txt Repair.txt
sellPrice.txt
7
5.0 CLASS DEFINITION OF INHERITENCE AND POLYMORPHISM
Super Class
Phone.java
import java.io.*;
import java.util.*;
//This is a super class and it's abstract so it will only work as a frame from every class
public abstract class Phone {
private String model;
private String variant;
private float price;
private String color;
private String condition;
private int stock;
8
model = ml;
variant = v;
price = p;
color = c;
condition = "NEW";
}
//without price and stock
public Phone(String m, String v, String c, String cond){
model = m;
variant = v;
color = c;
condition = cond;
}
//default
public Phone(){
model = null;
variant = null;
price = 0.00f;
color = null;
condition = null;
}
//getter
public String getModel(){
return model;
}
public String getVariant(){
return variant;
}
public String getColor(){
return color;
}
9
public float getPrice(){
return price;
}
public String getCondition(){
return condition;
}
//to string with condition
public String toString(){
return "Model : "+model + "\nVariant : "+variant+"Color : "+color + "Condition :
"+condition + "Price : RM"+price;
}
//getYesorNo method for return boolean
public boolean getYesorNo(String massage){
Scanner userInput = new Scanner(System.in);
System.out.println("\n"+massage+"y/n");
String userChoice = userInput.next();
while(!userChoice.equalsIgnoreCase("y") && !userChoice.equalsIgnoreCase("n")){
System.err.println("YOUR CHOICE IS NOT Y / N ");
System.out.println("\n"+massage+"(Y/N)");
userChoice = userInput.next();
}
return userChoice.equalsIgnoreCase("y");
}
}
10
Sub Class
Repair.java
import java.io.*;
import java.util.*;
public class Repair extends Phone
{
//normal const
private String [] item = new String[2];
public Repair (int p ){
problem = p;
}
//calculate price for repair
public int showPhoneModel() throws IOException{
//Read Repair.txt file to see the repair price
FileReader read = new FileReader("Z:\\visual
code\\java\\Groupproject\\Main.java\\Repair.txt");
BufferedReader buff = new BufferedReader(read);
12
String fullItem = null;
//if customer choice same with entryCount it will run this
if(choice == entryCount){
//show the price if customer choose battery or lcd
if(problem == 1){
System.out.println("\nPhone Model : " + phoneModel);
item[0] = "Battery " + phoneModel;
price = scan.next();
System.out.println(item[0]+" : RM "+price);
fullItem = item[0] + " " + phoneModel;
}else if(problem == 2){
System.out.println("\nPhone Model : " + phoneModel);
item[1] = "LCD "+phoneModel;
scan.next();
price = scan.next();
System.out.println(item[1]+" : RM "+price);
fullItem = item[1] + " " + phoneModel;
}
else{
System.err.println("Error Pls try again");
}
//ask customer if they really want to proceed
boolean yesOrNo = super.getYesorNo("Do you want to repair : ");
if(yesOrNo){
//if yes, the system will write the data to Customer file
cust.writeCustomerData(fullItem, price);
}
}
data = buff.readLine();
//item , phone model , price
}
13
read.close();
buff.close();
}
}
Sell.java
import java.io.*;
import java.util.*;
14
System.err.println("Data Base Not Found");
System.err.println("PLEASE MAKE THE DATABASE FIRST");
return;
}
//get model and variant to search if the model have in database
String m,v;
m = getModel();
v = getVariant();
String findString = m+" "+v;
//to split the space
String [] keyword = findString.split("\\s+");
//call checkPhonePriceinDatabase method to check
checkPhonePriceinDatabase(keyword,showData);
}
public boolean checkPhonePriceinDatabase(String [] keyword, boolean
isDisplay)throws IOException{
//Read sellPrice.txt file
FileReader fileRead = new FileReader("Z:\\visual
code\\java\\Groupproject\\Main.java\\sellPrice.txt");
BufferedReader bufferRead = new BufferedReader(fileRead);
15
isExist = true;
for(String keywords: keyword){
isExist = isExist && data.toLowerCase().contains(keywords.toLowerCase());
}
if(isExist){
if(isDisplay){
totalData++;
StringTokenizer stringToken = new StringTokenizer(data,";");
//stringToken.nextToken();
System.out.printf("|%d ", totalData);
//model
System.out.printf("|%s ", stringToken.nextToken());
//variant
System.out.printf(" |%sGB \t", stringToken.nextToken());
//price
System.out.printf("|RM%s ", stringToken.nextToken());
System.out.println();
break;
}else{
//to take the price from the database
Scanner scan = new Scanner(data);
scan.useDelimiter(";");
for(int i =0; i < 2; i++){
scan.next();
}
double price = scan.nextDouble();
sellPrice(price);
break;
}
}
data = bufferRead.readLine();
16
}
if(!isExist){
System.out.println("NO DATA");
if(!isDisplay){
System.out.println("WE DONT ACCEPT THAT PHONE");
}
}
if(isDisplay){
System.out.println("=========================================");
}
bufferRead.close();
fileRead.close();
return isExist;
}
//method to calculate sell price
public void sellPrice(double price) throws IOException{
Customer cust = new Customer("Sell Phone");
double endPrice ;
System.out.println(super.getCondition());
Integer condition = Integer.valueOf(super.getCondition());
//condition for price the price is based on the condition
endPrice = price-(1000-(condition*100));
//display the price and if the seller want to approve to buy this customer phone
System.out.println("\n=========================================");
System.out.println("Price We Take : RM" + endPrice);
System.out.println("=========================================");
boolean approve = super.getYesorNo("CONTINUE: ");
if(approve){
try{
//if approve will write the customer phone data on phoneData.txt file
FileWriter write = new FileWriter("Z:\\visual
code\\java\\Groupproject\\Main.java\\phoneData.txt",true);
17
BufferedWriter buffWrite = new BufferedWriter(write);
buffWrite.write(getModel()+","+super.getVariant()+","+stringPrice+","+super.getColor
()+","+Stringcondition+"/10,"+"1");
cust.writeCustomerData(item, stringPrice);
System.out.println(item);
cust.showReceipt();
buffWrite.newLine();
buffWrite.flush();
}
}
18
else{
//if exist the system will ask to just edit the stock
System.out.println("The data is already there you should update the stock");
}
buffWrite.close();
write.close();
}catch(Exception e){
System.err.println("Error");
}
}
}
}
Seller.java
import java.io.*;
import java.util.*;
19
//take data from phoneData.txt and show them
FileReader fileRead;
BufferedReader bufferRead;
try{
//try to open phoneData.txt file in this file has all the information for phone in stock
fileRead = new FileReader("Z:\\visual
code\\java\\Groupproject\\Main.java\\phoneData.txt");
bufferRead = new BufferedReader(fileRead);
}
catch(Exception e){
System.err.println("DATABASE NOT FOUND");
System.err.println("PLEASE MAKE THE DATABASE FIRST !!!");
//if there's no database so it will call addData method to make a new file
addData();
return;
System.out.println("\n|NO|\tMODEL\t\t|VARIANT|PRICE\t|\tCOLOR\t|CONDITION\t|
STOCK\t");
System.out.println("================================================
=================================");
String data = bufferRead.readLine();
int i =0;
while (data != null) {
//display all phone in stock
i++;
StringTokenizer stringToken = new StringTokenizer(data, ",");
//yang ni untuk primary key
//stringToken.nextToken();
System.out.printf("|%d ", i);
20
//model
System.out.printf("|%s", stringToken.nextToken());
//variant
System.out.printf("|%sGB\t", stringToken.nextToken());
//price
System.out.printf("|RM%s\t", stringToken.nextToken());
//color
System.out.printf("|%s\t", stringToken.nextToken());
//condition
System.out.printf("|%s\t", stringToken.nextToken());
System.out.printf("|%s\t", stringToken.nextToken());
System.out.println();
data = bufferRead.readLine();
}
fileRead.close();
bufferRead.close();
System.out.println("\n===============================================
=================================");
}
//to find phone data
public void findData() throws IOException{
21
//take keyword from user
Scanner userInput = new Scanner(System.in);
System.out.print("Enter keyword : ");
String findString = userInput.nextLine();
//Untuk split kan space yang user masuk so akan masuk ke array 0 and array 1
String [] keyword = findString.split("\\s+");
checkPhoneinDatabase(keyword,true);
}
//to check phone in database
public boolean checkPhoneinDatabase(String [] keyword, boolean isDisplay)throws
IOException{
FileReader fileRead = new FileReader("Z:\\visual
code\\java\\Groupproject\\Main.java\\phoneData.txt");
BufferedReader bufferRead = new BufferedReader(fileRead);
System.out.println("================================================
=====================================================");
}
while(data != null){
//check keyword inside the line
isExist = true;
for(String keywords: keyword){
isExist = isExist && data.toLowerCase().contains(keywords.toLowerCase());
}
if(isExist){
if(isDisplay){
22
totalData++;
//if data is exist and isDisplay is true it will display
StringTokenizer stringToken = new StringTokenizer(data,",");
//stringToken.nextToken();
System.out.printf("|%d ", totalData);
//model
System.out.printf("|%s ", stringToken.nextToken());
//variant
System.out.printf(" |%sGB \t", stringToken.nextToken());
//price
System.out.printf("|RM%s ", stringToken.nextToken());
//color
System.out.printf("|\t%s\t", stringToken.nextToken());
//condition
System.out.printf("|\t%s ", stringToken.nextToken());
//STOCK
System.out.printf("|\t%s ", stringToken.nextToken());
System.out.println();
}
}
data = bufferRead.readLine();
}
if(isDisplay){
System.out.println("================================================
====================================================");
}
bufferRead.close();
fileRead.close();
return isExist;
23
}
//method to add data
public void addData() throws IOException{
//true mean it will append to exist file instead of overwrite it
FileWriter fileWrite = new FileWriter("Z:\\visual
code\\java\\Groupproject\\Main.java\\phoneData.txt",true);
BufferedWriter bufferWrite = new BufferedWriter(fileWrite);
24
// if the data isn't exist system will write phone data in database
if(!isExist){
System.out.println("\nData that you enter is : ");
System.out.println("=============================");
System.out.println("Phone Model : " + model);
System.out.println("Phone Variant : "+variant);
System.out.println("Phone Price : "+ price);
System.out.println("Phone Color : "+ color);
System.out.println("Phone Condition : " + condition);
bufferWrite.close();
fileWrite.close();
}
//decrease stock
public void decreaseStock(int updateStock) throws IOException{
//read phoneData.txt file
File databases = new File("Z:\\visual
code\\java\\Groupproject\\Main.java\\phoneData.txt");
25
FileReader read = new FileReader(databases);
BufferedReader buffRead = new BufferedReader(read);
//make a temporary file to update the stock
File tempDatas = new File("Z:\\visual
code\\java\\Groupproject\\Main.java\\temppDB.txt");
FileWriter temp = new FileWriter(tempDatas);
BufferedWriter buffTempData = new BufferedWriter(temp);
while(data != null){
entryCount++;
StringTokenizer st = new StringTokenizer(data, ",");
if(updateStock == entryCount){
for(int i =0; i < tempData.length; i++){
originalData = st.nextToken();
if(i==5){
String stockToken = originalData;
int stock = Integer.parseInt(stockToken);
stock--;
tempData[i] = String.valueOf(stock);
if(stock != 0){
String tempp =
tempData[0]+","+tempData[1]+","+tempData[2]+","+tempData[3]+","+tempData[4]+",
"+tempData[5];
System.out.println(tempp);
buffTempData.write(tempp);
buffTempData.newLine();
}else{
System.out.println("LAST STOCK !!!!");
26
}
}else{
tempData[i] = originalData;
}
}
}else{
buffTempData.write(data);
buffTempData.newLine();
}
data = buffRead.readLine();
} buffTempData.flush();
buffRead.close();
buffTempData.close();
read.close();
temp.close();
System.gc();
//delete the original file and rename temporary file to original file
databases.delete();
tempDatas.renameTo(databases);
}
//update stock
public void updateData() throws IOException{
//take database original
File dataBase = new File("Z:\\visual
code\\java\\Groupproject\\Main.java\\phoneData.txt");
FileReader fileRead = new FileReader(dataBase);
BufferedReader bufferRead = new BufferedReader(fileRead);
//make temporary database
File tempDB = new File("Z:\\visual code\\java\\Groupproject\\Main.java\\tempDb.txt");
FileWriter fileWrite = new FileWriter(tempDB);
BufferedWriter bufferWrite = new BufferedWriter(fileWrite);
27
//show all data
System.out.println("List Phone");
showPhoneData();
28
//refresh token
st= new StringTokenizer(data, ",");
String originalData = st.nextToken();
for(int i =0; i < (fieldData.length); i++){
boolean isUpdate = getYesorNo("Do you want to edit the " + fieldData[i]+" ");
//ask user if they want to update mode, variant, price, color, condition, or stock
if(isUpdate){
userInput = new Scanner(System.in);
System.out.println("\nEnter "+fieldData[i]+" new data : ");
tempData[i]= userInput.nextLine();
}
else{
tempData[i] = originalData;
}
//will stop the token if the system reach last fieldData or the system will be
error
if(!fieldData[i].equals("stock")){
originalData = st.nextToken();
}
}
//display new data
//confirmation
st = new StringTokenizer(data, ",");
System.out.println("\nNEW DATA");
System.out.println("===================================");
System.out.println("Phone Model :" + tempData[0]);
System.out.println("Phone Variant :" + tempData[1]);
System.out.println("Phone Price :" + tempData[2]);
System.out.println("Phone Color :" + tempData[3]);
System.out.println("Phone Condition :" + tempData[4]);
System.out.println("Phone Stock :" + tempData[5]);
29
boolean isUpdate = getYesorNo("Are you sure you want to update the data ");
if(isUpdate){
String tmodel = tempData[0];
String tvariant = tempData[1];
String tprice = tempData[2];
String tcolor = tempData[3];
String tcondition = tempData[4];
String tstock = tempData[5];
bufferWrite.write(tmodel+","+tvariant+","+tprice+","+tcolor+","+tcondition+","+tstock);
}
else{
bufferWrite.write(data);
}
}else{
bufferWrite.write(data);
}
bufferWrite.newLine();
data = bufferRead.readLine();
}
}
//to delete phone data from file
public void deletePhoneData () throws IOException{
//take database original
//just read the file
File dataBase = new File ("Z:\\visual
code\\java\\Groupproject\\Main.java\\phoneData.txt");
FileReader fileRead = new FileReader(dataBase);
BufferedReader bufferRead = new BufferedReader(fileRead);
//make temporary database
File tempData = new File("tempdb.txt");
FileWriter fileWrite = new FileWriter(tempData);
BufferedWriter bufferWrite = new BufferedWriter(fileWrite);
//show data
System.out.println("List Phone ");
showPhoneData();
//take use input for delete data
Scanner userInput = new Scanner(System.in);
System.out.println("Enter no you want to delete : ");
int deleteNum = userInput.nextInt();
//loop to read every row data and skip data selected
boolean isFound = false;
int entryCounts = 0;
String data = bufferRead.readLine();
while (data != null) {
entryCounts ++;
boolean isDelete = false;
StringTokenizer st = new StringTokenizer(data, ",");
//show data that use want to delete
31
if(deleteNum == entryCounts){
System.out.println("Data you want to delete : ");
System.out.println("=================================");
System.out.println("Phone Model : "+ st.nextToken());
System.out.println("Phone Variant : "+ st.nextToken());
System.out.println("Phone Price : "+ st.nextToken());
System.out.println("Phone Color : "+ st.nextToken());
System.out.println("Phone Condition : "+ st.nextToken());
System.out.println("Phone Stock : "+ st.nextToken());
}
if(isDelete){
//skip transfer data original to temporary
System.out.println("Data already deleted");
}else{
//transfer original data to temporary
bufferWrite.write(data);
bufferWrite.newLine();
}
data = bufferRead.readLine();
}
if(!isFound){
System.err.println("DATA IS NOT FOUND");
}
32
bufferWrite.close();
bufferRead.close();
fileRead.close();
fileWrite.close();
System.gc();
//delete original data
dataBase.delete();
//rename temporary file to database
tempData.renameTo(dataBase);
}
}
Customer.java
import java.io.*;
import java.util.*;
//this class have name, phone number, email, service and date as their data member
private String name;
private String phoneNumber;
private String email;
private String service;
private Date tarikh = new Date();
33
}
//getter
public String getName(){ return name;}
public String getPhoneNumber() {return phoneNumber;}
public String getEmail() { return email;}
34
}
//display for customer havae all data members
System.out.println("\n===============================================
=====================");
System.out.println("|NO|\tNAME\t\t|EMAIL|NO
PHONE\t|\tSERVICE\t|ITEM\t|DATE\t|TOTAL\t|");
System.out.println("================================================
====================");
int totalData =0;
String data = bufferRead.readLine();
//print untill the end of line in file
while(data != null){
totalData++;
StringTokenizer st = new StringTokenizer(data , ";");
System.out.printf("|%d ", totalData);
//name
System.out.printf("|%s", st.nextToken());
//email
System.out.printf("|%s\t", st.nextToken());
//no phone
System.out.printf("|%s\t", st.nextToken());
//service
System.out.printf("|%s\t", st.nextToken());
//item
System.out.printf("|%s\t", st.nextToken());
//date
System.out.printf("|%s\t", st.nextToken());
//total
System.out.printf("|%s\t", st.nextToken());
System.out.println();
data = bufferRead.readLine();
35
}
//close the file
fileRead.close();
bufferRead.close();
System.out.println("================================================
====================");
}
public void writeCustomerData( String item , String total ) throws IOException{
//try to write Customer Data
try {
FileWriter fileWrite = new FileWriter("Z:\\visual
code\\java\\Groupproject\\Main.java\\CustomerData.txt", true);
BufferedWriter bufferWrite = new BufferedWriter(fileWrite);
//User will input their name, phone number and email
Scanner userInput = new Scanner(System.in);
System.out.println("\n===================================");
System.out.print("Enter your name : ");
name = userInput.nextLine();
System.out.print("Enter your phone number : ");
phoneNumber = userInput.nextLine();
System.out.print("Enter your email: ");
email = userInput.nextLine();
System.out.println("===================================");
//write and flush the data into CustomerData.txt file
bufferWrite.write( name +";" +phoneNumber + ";" +
email+";"+service+";"+item+";"+tarikh+";"+total);
bufferWrite.flush();
bufferWrite.newLine();
bufferWrite.close();
fileWrite.close();
}
catch(Exception e){
36
//if the file is error to open
System.err.println("Error To Open File ");
}
}
public void findCustomerData() throws IOException{
//read whether the database have or not
try{
File file = new File("Z:\\visual
code\\java\\Groupproject\\Main.java\\CustomerData.txt");
}catch(Exception e){
//if there's no CustomerData.txt file user can make a file on add data
System.err.println("Data Base Not Found");
System.err.println("PLEASE MAKE THE DATABASE FIRST");
return;
}
//take keyword from user
Scanner userInput = new Scanner(System.in);
System.out.print("Enter Customer Name : ");
String findString = userInput.nextLine();
//For split the keyword by the space and to find the keyword have in database or not
String [] keyword = findString.split("\\s+");
//true is to display the data if false itsnot going to display the data it will only return the
boolean
checkCustomerInDatabase(keyword,true);
}
public boolean checkCustomerInDatabase(String[] keyword, boolean isDisplay) throws
IOException{
//take data from CustomerData.txt and show them
FileReader fileRead = new FileReader("Z:\\visual
code\\java\\Groupproject\\Main.java\\CustomerData.txt");
BufferedReader bufferRead = new BufferedReader(fileRead);
System.out.println("================================================
=================================");
}
//just for number on the left indicate how many customer there's
int totalData = 0;
while (data != null) {
//isExist is true to make a logic gate &&
isExist = true;
for(String keywords: keyword){
//so isExist is true so if in data there's a keyword than isExist will be true
because true + true = true
isExist = isExist && data.toLowerCase().contains(keywords.toLowerCase());
}
if(isExist){
if(isDisplay){
totalData++;
StringTokenizer stringToken = new StringTokenizer(data, ";");
//stringToken.nextToken();
System.out.printf("|%d ", totalData);
//name
System.out.printf("|%s", stringToken.nextToken());
//email
System.out.printf("|%s\t", stringToken.nextToken());
//no phone
38
System.out.printf("|%s\t", stringToken.nextToken());
//service
System.out.printf("|%s\t", stringToken.nextToken());
//item
System.out.printf("|%s\t", stringToken.nextToken());
//date
System.out.printf("|%s\t", stringToken.nextToken());
//total
System.out.printf("|%s\t", stringToken.nextToken());
System.out.println();
}
}
//to read next line for next loop
data = bufferRead.readLine();
}
if(isDisplay){
System.out.println("================================================
================================");
}
fileRead.close();
bufferRead.close();
return isExist;
}
//method for buy phone
public void buyPhone(int choice) throws IOException{
//open read file for phoneData in this file we save each phone price, stock and every
info about the phone
FileReader fileRead = new FileReader("Z:\\visual
code\\java\\Groupproject\\Main.java\\phoneData.txt");
BufferedReader buff = new BufferedReader(fileRead);
//for looping
int entryCount = 0;
39
String data = buff.readLine();
boolean wantBuy = false;//wantBuy is false by default
String item, model , variant , price, color , condition; //declare item ,model, variant ,
price, color, condition to take data from file
while(data != null){
entryCount++;
StringTokenizer st = new StringTokenizer(data,",");
if(choice == entryCount){
//take the data using String tokenizer and the delimeter is ","
model = st.nextToken();
variant = st.nextToken();
price = st.nextToken();
color = st.nextToken();
condition = st.nextToken();
//to make sure if customer really want to buy
System.out.println("\nModel : " + model);
System.out.println("Variant : "+variant);
System.out.println("Price: " + price);
System.out.println("Color: " + color);
System.out.println("Condition: " + condition);
wantBuy = phone.getYesorNo("Are you sure you want to buy this : ");
if(wantBuy){
//if yes it will call writeCustomerData method to write customer data and call
decreaseStock method from Seller class to decrease the stock
item = model+" "+variant+" "+color+" "+condition;
fileRead.close();
buff.close();
writeCustomerData(item, price);
phone.decreaseStock(entryCount);
break;
}
}
40
data = buff.readLine();
}
fileRead.close();
buff.close();
}
public void showReceipt() throws IOException{
// read CustomerData.txt file , in this file we save customer data
FileReader read = new FileReader("Z:\\visual
code\\java\\Groupproject\\Main.java\\CustomerData.txt");
BufferedReader buff = new BufferedReader(read);
//output for receipt
System.out.println("\n\nRECEIPT");
System.out.println("\n===================================");
System.out.println("KEDAI JUAL PHONE");
System.out.println("===================================");
}
}
42
6.0 CLASS APPLICATION
String userChoice;
Scanner userInput = new Scanner(System.in);
boolean isContinue = true;
int buyerOrSeller, dbOrSell, choice;
Seller phone1 = new Seller();
Customer cust = new Customer();
while(isContinue){
//interface
System.out.println("\n======================");
System.out.println("WELCOME TO KEDAI PHONE");
System.out.println("======================");
System.out.println("1.Seller");
System.out.println("2.Buyer");
System.out.println("======================");
System.out.print("Your Option : ");
buyerOrSeller = userInput.nextInt();
switch (buyerOrSeller) {
case 1:
//user need to insert password to open seller page
43
String password = "0";
System.out.print("\nEnter password to access Seller account : ");
password = userInput.next();
System.out.println(password);
if(password.equals("999")){
System.out.println("\n1.Access Database");
System.out.println("2.Sell Phone");
System.out.print("Your option : ");
dbOrSell = userInput.nextInt();
userInput.nextLine();
switch (dbOrSell) {
//access store database
case 1:
System.out.println("----------------");
System.out.println("STORE DATABASE");
System.out.println("----------------");
System.out.println("1.\tView Phone");
System.out.println("2.\tFind Phone");
System.out.println("3.\tAdd Phone");
System.out.println("4.\tEdit Phone Data");
System.out.println("5.\tDelete Phone");
System.out.println("6.\tFind Customer Data");
System.out.println("7.\tShow Customer Data");
System.out.print("\nEnter your choice : ");
userChoice = userInput.next();
//String model, String variant, String color, String condition
switch (userChoice) {
case "1":
System.out.println("\n______________");
System.out.println("List All Phone");
44
System.out.println("______________");
phone1.showPhoneData();
break;
case "2":
System.out.println("\n______________");
System.out.println("Find A Phone");
System.out.println("______________");
//FIND DATA
phone1.findData();
break;
case "3":
System.out.println("\n______________");
System.out.println("Add Phone");
System.out.println("______________");
phone1.addData();
break;
case "4":
System.out.println("\n______________");
System.out.println("Edit Phone Data");
System.out.println("______________");
phone1.updateData();
break;
case "5" :
System.out.println("\n______________");
System.out.println("Delete Phone on list");
System.out.println("______________");
phone1.deletePhoneData();
break;
case "6" :
System.out.println("\n______________");
System.out.println("Find Cust");
45
System.out.println("______________");
cust.findCustomerData();
break;
case "7" :
System.out.println("\n______________");
System.out.println("Show Customer Data");
System.out.println("______________");
cust.showCustInfo();
break;
default:
System.err.println("INPUT IS NOT FOUND");
break;
}
break;
case 2:
//if customer want to sell phone and this page only seller can open and
approve the phone
int FindOrSell;
System.out.println("\n----------------");
System.out.println("SELL PHONE");
System.out.println("----------------\n");
System.out.println("1.Find phone Price");
System.out.println("2.Sell Phone");
FindOrSell = userInput.nextInt();
//just want to fill condition value
String model,variant, color, condition="5";
int cond =5;
userInput.nextLine();
switch (FindOrSell) {
case 1:
//if only want to see the phone price
46
System.out.println("\n=================");
System.out.println("FIND PHONE PRICE");
System.out.println("=================\n");
System.out.print("Enter phone model : ");
model = userInput.nextLine();
System.out.print("Enter phone Variant : ");
variant = userInput.nextLine();
Sell find = new Sell(model,variant);
find.findPhonePrice(true);
break;
case 2:
//if customer want to sell phone
System.out.println("=================");
System.out.println("SELL PHONE");
System.out.println("=================\n");
System.out.print("Enter phone model : ");
model = userInput.nextLine();
System.out.println("Enter Variant: ");
variant = userInput.nextLine();
System.out.println("Enter Color: ");
color = userInput.nextLine();
while(true){
System.out.print("Enter condition : ");
cond = userInput.nextInt();
if(cond <= 10 && cond >=1){
condition = String.valueOf(cond);
break;
}
}
Sell sell = new Sell(model, variant,color,condition);
sell.findPhonePrice(false);
47
break;
default:
break;
}
break;
default:
System.out.println("WRONG INPUT");
break;
}
}else{
System.out.println("WRONG PASSWORD");
break;
}
break;
case 2:
//this is customer page so it's public everyone can access
System.out.println("\n1. Buy Phone");
System.out.println("2. Repair Phone");
System.out.println("Your Option : ");
int buyOrRepair = userInput.nextInt();
if(buyOrRepair == 1){
//page to buy phone
Customer custBuy = new Customer("Buy Phone");
System.out.println("----------------");
System.out.println("BUY PHONE");
System.out.println("----------------\n\n");
phone1.showPhoneData();
System.out.print("Choose Phone: ");
int phoneChoose = userInput.nextInt();
custBuy.buyPhone(phoneChoose);
48
}else if(buyOrRepair == 2){
//page to repair phone
System.out.println("----------------");
System.out.println("REPAIR PHONE");
System.out.println("----------------\n");
System.out.println("1. Battery");
System.out.println("2. LCD");
System.out.print("Choose: ");
choice = userInput.nextInt();
userInput.nextLine();
Repair baiki = new Repair(choice );
baiki.repairPrice();
}else{
System.err.println("Wrong Input !!!");
break;
}
cust.showReceipt();
break;
default:
System.out.println("WRONG INPUT");
break;
}
//if user want to continue
isContinue = phone1.getYesorNo("Do you want to Continue : ");
}
49
7.0 INFORMATION AND SAMPLE INTERFACE
50
diagram 3 (Customer buy phone)
51
8.0 REFERENCE
1) Danny Poo, Derek Kiong, Swarnalatha Ashok(2017). Object-Oriented programming and
Java(2nd ed.). Google Books.
https://books.google.com.my/books?hl=en&lr=&id=r10U16kgmkwC&oi=fnd&pg=PR3&dq=i
nfo:gu5E8-
ejZSAJ:scholar.google.com/&ots=5VOz5DHOCI&sig=a7Se2p5JaNGqi_0DnUHDdtb
zWzY&redir_esc=y#v=onepage&q&f=false
2) w3schools
https://www.w3schools.com/java/
3) Alex Lee (2018). Full Java Course By Alex Lee. YouTube
https://m.youtube.com/playlist?list=PL59LTecnGM1NRUyune3SxzZlYpZezK-oQ
52