Java program

profilesmartstudent12
Instruction.pptx

You are asked to develop an app for Burger211 Inc.

Assignment 2 Discussion

About the Burger211 Company

Burger211 manages 1000+ shops in different countries.

Burger211 sells 3 burgers: inheritance burger, overriding burger and polymorphism burger.

All 3 burgers have a name, price in US$ and toppings. These values were decided by the HQ in advance.

Each country displays their own style of menu because of different language, currency and culture.

All the Buger211 shops in the same country display the same format of menu except promotion at their shop.

Menu contains the shop name, promotion information, all 3 burger names, prices, and their toppings.

The prices should be displayed in their own currency. (eg: If the inheritance burger has a price of $3.0, the exchange rate for the country is 500, and the country use €, the price of the burger is € 1500.)

Franchise can hold individual promotional events with special discounts.

If people in the country don’t eat certain topping, the topping can be removed or replaced them with other topping.

Your mission is to develop an app for printing menu.

Assignment 2 Discussion

Sample output (two countries, and each country has two franchises.)

USA

KOREA

Assignment 2 Discussion

Overall class structure

superclass: Burger211.java
subclass: USA.java
subclass: Korea.java
Test Program: MyBurger211Test.java

output

API

** API for menu is provided.

Assignment 2 Discussion

Requirement

You must apply the following Java related techniques:

Tech (subject) Location
abstract class/method superclass
Encapsulation superclass
User-defined class superclass
ArrayList superclass
inheritance subclass
overriding subclass
run-time Polymorphism Main test program
superclass: Burger211.java
abstract class/method Encapsulation User-defined class ArrayList
subclass: USA.java
inheritance overriding
subclass: Korea.java
inheritance overriding
Test Program: MyBurger211Test.java
run-time Polymorphism

Assignment 2 Discussion

What to prepare before programming for Assignment 2

The code below is designed to be easy to explain. Upgrade the code to improve your programming skills.

This assignment is not difficult, but it takes a long time. I highly recommend starting this assignment ASAP.

2

3

4

Create a superclass

Create a subclass (USA)

Create a subclass

(Any Country)

Write a test Program

0

Download API & Burger Images

5

Run

1

Steps to write program.

Assignment 2 Discussion

Download MenuGUI.java from canvas, save it to your package folder. In case of jGrasp, save it to source folder.

import MenuGUI to eclipse ( We choose a simple way. See next slide)

package

Source

folder

project

workspace

If you don’t know how to do this, follow next slide, otherwise jump to slide #11.

2

3

4

Create a superclass

Create a subclass (USA)

Create a subclass

(Any Country)

Write a test Program

0

Download API & Burger Images

5

Run

1

Assignment 2 Discussion

Assignment 2 Discussion

2

3

4

Create a superclass

Create a subclass (USA)

Create a subclass

(Any Country)

Write a test Program

0

Download API & Burger Images

5

1

Right click your project

MenuGUI is now loaded but there is an error mark.

Double click MenuGUI to open.

The reason why this program issue an error is “THERE IS NO PACKAGE NAME” or “DIFFERENT PACKAGE NAME”.

ADD/replace your package name.

hit refresh

hit save icon.

You are ready to use MenuGUI

Run

Assignment 2 Discussion

2

3

4

Create a superclass

Create a subclass (USA)

Create a subclass

(Any Country)

Write a test Program

0

Download API & Burger Images

5

1

Download burger1.png, burger2.png and burger3,png and save it in the project folder.

hit refresh

You are ready to use.

project

workspace

Run

Variables Data type
Burger1 Name, Burger2 Name, Burger3 Name String
Burger1 Price, Burger2 Price, Burger3 Price Double
Burger1 Topping, Burger2 Topping, Burger3 Topping String

2

3

4

Create a superclass

Create a subclass (USA)

Create a subclass

(Any Country)

Write a test Program

0

Download API & Burger Images

5

1

1. Define variables

Assignment 2 Discussion

Run

2

3

4

Create a superclass

Create a subclass (USA)

Create a subclass

(Any Country)

Write a test Program

0

Download API & Burger Images

5

1

2. Choosing Data Structure - Array

Assignment 2 Discussion

Array is a good data structure for this program, but it’s better to use ArrayList. (See next slide)

Run

2

3

4

Create a superclass

Create a subclass (USA)

Create a subclass

(Any Country)

Write a test Program

0

Download API & Burger Images

5

1

2. Choosing Data Structure - ArrayList & user-defined class

Assignment 2 Discussion

user-defined class (object)

constructor to

initialize ArrayList

create an object (instant) for Burger1

assign values to the valuable in the object

save the object into ArrayList

create an object (instant) for Burger2

create an object (instant) for Burger3

Run

2

3

4

Create a superclass

Create a subclass (USA)

Create a subclass

(Any Country)

Write a test Program

0

Download API & Burger Images

5

1

3. Security issue: How to protect against unwanted access or modify values.

Solution : Encapsulation

Protect ArrayList by adding private

Prepare getter

Assignment 2 Discussion

Run

2

3

4

Create a superclass

Create a subclass (USA)

Create a subclass

(Any Country)

Write a test Program

0

Download API & Burger Images

5

1

4. Let each country design their own menu.

Solution : abstract method

Assignment 2 Discussion

Run

2

3

4

Create a superclass

Create a subclass (USA)

Create a subclass

(Any Country)

Write a test Program

0

Download API & Burger Images

5

1

5. Let each franchise participate their own promotion and discount rate.

Solution : abstract method

Example

in USA subclass

output

in Main test program

Assignment 2 Discussion

Run

2

3

4

Create a superclass

Create a subclass (USA)

Create a subclass

(Any Country)

Write a test Program

0

Download API & Burger Images

5

1

Variables Data type Usage
discountRate Double
burgerNamePrice String/Array To send API (Burger name and its price)
pro String To send API (promotion info)

1. Define variables

Assignment 2 Discussion

Run

2

3

4

Create a superclass

Create a subclass (USA)

Create a subclass

(Any Country)

Write a test Program

0

Download API & Burger Images

5

1

2. Implement @Override

This subclass must implement two abstract methods declared in the superclass as follows.

Assignment 2 Discussion

Run

2

3

4

Create a superclass

Create a subclass (USA)

Create a subclass

(Any Country)

Write a test Program

0

Download API & Burger Images

5

1

3. Call API

To print the menu, call API and pass necessary information .

Assignment 2 Discussion

Run

2

3

4

Create a superclass

Create a subclass (USA)

Create a subclass

(Any Country)

Write a test Program

0

Download API & Burger Images

5

1

4. Overall Structure (USA)

Assignment 2 Discussion

Run

2

3

4

Create a superclass

Create a subclass (USA)

Create a subclass

(Any Country)

Write a test Program

0

Download API & Burger Images

5

1

Assignment 2 Discussion

1. Special requirements and its solution

Requirement Solution
The prices should be displayed in their own currency. (eg: If the inheritance burger has a price of $3.0, the exchange rate for the country is 500, and the country use €, the price of the burger is € 1500.) @Override public double getBurgerPrice(int i) { . . . }
Franchise can hold individual promotional events with special discounts. Same as USA
If people in the country don’t eat certain topping, the topping can be removed or replaced them with other topping. @Override public String getBurgerTopping(int i) { . . . }

Run

2

3

4

Create a superclass

Create a subclass (USA)

Create a subclass

(Any Country)

Write a test Program

0

Download API & Burger Images

5

1

Assignment 2 Discussion

2. Define variables

Variables Data type Usage
exchangeRate Double To calculate local price
discountRate Double
burgerNamePrice String/Array To send API (Burger name and its price)
pro String To send API (promotion info)

Run

2

3

4

Create a superclass

Create a subclass (USA)

Create a subclass

(Any Country)

Write a test Program

0

Download API & Burger Images

5

1

Assignment 2 Discussion

3. About the exchangeRate

The country's exchange rate can be assigned any value like

Bonus points (8points) are added If you read and use the current exchange rate in real time. To do this you need to study “week 3-3 How to read bigdata.pptx” by yourself .

Run

2

3

4

Create a superclass

Create a subclass (USA)

Create a subclass

(Any Country)

Write a test Program

0

Download API & Burger Images

5

1

Assignment 2 Discussion

4. About the topping.

If changing the 3rd burger’s topping from

to

Use @Override concept like

Run

2

3

4

Create a superclass

Create a subclass (USA)

Create a subclass

(Any Country)

Write a test Program

0

Download API & Burger Images

5

1

Assignment 2 Discussion

1. Special requirements and its solution

Requirement Example
Use run-time polymorphism Burger211 Bellevue = new USA();
Two countries (USA + any other country) and each country has two franchises.
Apply any promotion Bellevue.Promotion(0.1,"10% Off - BTS Bellevue College Concert Special");

Run

2

3

4

Create a superclass

Create a subclass (USA)

Create a subclass

(Any Country)

Write a test Program

0

Download API & Burger Images

5

1

Assignment 2 Discussion

2. Overall Structure

Run

2

3

4

Create a superclass

Create a subclass (USA)

Create a subclass

(Any Country)

Write a test Program

0

Download API & Burger Images

5

1

Assignment 2 Discussion

3. About foreign character

If you use a foreign character in your code, like you will be asked

in this case, just select “Save as UTF-8”.

Run

2

3

4

Create a superclass

Create a subclass (USA)

Create a subclass

(Any Country)

Write a test Program

0

Download API & Burger Images

5

1

Assignment 2 Discussion

Menus are all superimposed and the one behind them is not visible. Click here and then drag. You will see next one.

Output

Run

2

3

4

Create a superclass

Create a subclass (USA)

Create a subclass

(Any Country)

Write a test Program

0

Download API & Burger Images

5

1

Submission (5 files)

Superclass (Burger211.java)

Subclass (USA) (USA.java)

Subclass (Any County) (CountryName.java)

Main test program (MyBurger211Test.java)

One page of pdf or ppt file (capture all 4 menus on one page as shown bellow)

6. Code for real-time exchange rate if you did bonus work.

7. You MUST include your first and last name, your student ID, the date. a short description of the program’s function, and comments necessary to explain the operation of your program

Run

Assignment 2 Discussion