Sie sind auf Seite 1von 16

UNIVERSITI TEKNOLOGI MARA KELANTAN BRANCH

MACHANG CAMPUS

FACULTY OF COMPUTER & MATHEMATICAL SCIENCE

CSC584 - ENTERPRISE PROGRAMMING


TITLE: Exercise 2

PREPARED BY (D1CS2404A):
NAME MATRIC NUMBER
Nur Syafiqah Bahirah binti Mohd Saipul Bahari 2020985161
Aisyah Hamizah binti Mahussin 2020964577
Nur Syazana Binti Ahmad Jefiruddin 2020977237

PREPARED FOR:
Dr. Muhammad Firdaus Mustapha

1
TABLE OF CONTENTS

1. Source code...................................................................................................................................3
2. Output.........................................................................................................................................12

2
1. Source code

i. OrderServiceApp

import java.util.Scanner;
import java.lang.String;

class OrderServiceApp{
public static void main(String []args){
try{
Scanner sc = new Scanner(System.in);

//assume we set for 5 customers

OrderService os[] = new OrderService[5];

for(int i = 0; i<5; i++)


{

System.out.print("\nCustomer Name :");


String cn = sc.nextLine();

System.out.print("Customer Phone Number:");


String ph = sc.nextLine();

System.out.print("Date:");
String dt = sc.nextLine();

System.out.print("Choose code [1=Burger / 2=Sandwich /3=Pasta]");


//burger=rm10 / sandwich=rm5 / pasta=rm7
int code = Integer.parseInt(sc.nextLine());

System.out.print("Quantity : ");
int qty = Integer.parseInt(sc.nextLine());

System.out.print("Service [C:COD / D:Dine-In]");

String c = sc.nextLine();

3
//COD
if(c.equalsIgnoreCase("C")){
System.out.print("Enter detailed address:");
String ad = sc.nextLine();

System.out.print("Enter estimate distance in KM:");


double di = Double.parseDouble(sc.nextLine());

os[i] = new Cod(cn, ph, dt,code, qty, ad, di);

os[i].calcServiceTax();
os[i].print();

}
//Dine In
else if(c.equalsIgnoreCase("D")){
System.out.print("Enter table no:");
int tn = Integer.parseInt(sc.nextLine());

System.out.print("Include birthday package? (Y/N)");


String bt = sc.nextLine();

os[i] = new DineIn(cn, ph, dt,code, qty, tn, bt);

os[i].calcServiceTax();

if(bt.equalsIgnoreCase("Y")){
((DineIn) os[i]).calcTaxBirth();

}
else{
os[i].print();
}

4
catch (Exception e) {
//System.out.println("Something went wrong.");
System.out.println(e.getMessage());
e.printStackTrace();
}
}
}

5
ii. OrderService

abstract class OrderService{

private String name, phoneNo, date;


protected int code, quantity;
protected double orderPrice;

public OrderService (String n, String p, String d, int cde, int q){


this.name = n;
phoneNo = p;
date = d;
code = cde;
quantity = q;
}

public String getName() {return name;}


public String getPhoneNo() {return phoneNo;}
public String getDate() {return date;}
public int getCode() {return code;}
public int getQuantity(){return quantity;}
public double getOrderPrice() { return orderPrice; }

public abstract void calcServiceTax();

public void print(){


System.out.println("Name: "+name);
System.out.println("Phone No: "+phoneNo);
System.out.println("Date: "+date);
System.out.println("Code: "+code);
System.out.println("Quantity:"+quantity);
System.out.println("Order Price:"+orderPrice);
}
}

6
iii. Cod

class Cod extends OrderService {

protected String address;


protected double distance;
private String birth;

public Cod(String a, String b, String c, int d, int e, String f, double g)


{
super(a, b, c, d, e);
address = f;
distance = g;

public String getAddress() {return address;}


public double getDistance(){return distance;}

public void calcServiceTax(){

double delCaj = 0.0;

if(distance > 10)


delCaj = 5 + (distance - 10);
else if(distance > 4 && distance < 10)
delCaj = 5;

double burgerPrice, sandwichPrice, pastaPrice;

if(code == 1)
{
burgerPrice = quantity * 10;
orderPrice = burgerPrice + delCaj;
}
else if(code == 2)
{
sandwichPrice = quantity * 5;
orderPrice = sandwichPrice + delCaj;
}
else if(code ==3 )
{

7
pastaPrice = quantity * 7;
orderPrice = pastaPrice + delCaj;
}

public void print(){


System.out.println("Address: "+address);
System.out.println("Distance in KM:"+distance);
System.out.println("Total Price: RM"+orderPrice);

8
iv. DineIn

class DineIn extends OrderService implements Package{

private int tableNo;


private String birth;

public DineIn(String a, String b, String c, int d, int e,int tn, String bt)
{
super(a, b, c, d, e);
tableNo = tn;
birth = bt;
}

public int getTableNo() {return tableNo;}

public void calcServiceTax(){

double burgerPrice, sandwichPrice, pastaPrice;

if(code == 1)
{
burgerPrice = 10 * quantity ;
orderPrice = burgerPrice + serviceTax;
}
else if(code == 2)
{
sandwichPrice = 5 * quantity ;
orderPrice= sandwichPrice + serviceTax;
}
else if(code ==3 )
{
pastaPrice = 7 * quantity ;
orderPrice = pastaPrice + serviceTax;
}

9
public void calcTaxBirth(){

double totalBirth;
if(birth.equalsIgnoreCase("Y")){
totalBirth = getOrderPrice() + birthdayTax; //+ rm5
System.out.println("Total price + Birthday package price : " + totalBirth);
}

public void print(){


System.out.println("TableNo: "+tableNo);
System.out.println("Total Price: RM"+orderPrice);

}
}

10
v. Package

public interface Package{

public static final double birthdayTax = 5;


public static final double serviceTax = 3.5;
public void calcTaxBirth();

11
2. Output

i.

12
13
ii.

14
15
iii.

16

Das könnte Ihnen auch gefallen