Assignment 2 Step-by-Step Development

Assignment 2 
Step by Step Development (outline)
You should read 10-07-2020 Assignment2 Discussion 1.pptx before starting this slide
Oct. 8 2020
The code below is designed to be easy to explain. Upgrade the code to
improve your programming skills.
If you have any questions, please request a zoom meeting or email your question.
This assignment is not difficult but it takes a long time. I highly recommend starting this
assignment  ASAP.
Preparation
1.
Create a project
2.
Create a package
3.
Download MenuGUI.java from canvas. Add (or import) MenuGUI to your package.
4.
Download burger1.png, burger2.png and burger3,png and save it in the correct location.
Download MenuGUI.java from canvas, save it to your package folder. In case of jGrasp, save it to source folder.
Preparation step 3/4
package
Source 
folder
project
workspace
import MenuGUI to eclipse
If you don’t know how to do this, follow next slide,
otherwise jump to slide #11.
How to add(import) .java file into your project
Assume that you have a project (myGraphics) and a package (taesik.kim)
FYI
From my cs210 lecture note
place a  .java file here
 your work space
 your project name
 your package name
 your package name
From my cs210 lecture note
.java file you want to add to your project.
From my cs210 lecture note
Open eclipse
From my cs210 lecture note
Right click your package
1
2
Hit Refresh
From my cs210 lecture note
The file is now loaded but error.
Click to open this file
The reason why this program issue an error is “THERE IS
NO PACKAGE NAME” or “DIFFERENT PACKAGE NAME”
ADD/replace your package name.
From my cs210 lecture note
Click to save
Error mark disappears
after a few seconds.
From my cs210 lecture note
Download burger1.png, burger2.png and burger3,png and save it in your 
Project
 folder.
Preparation step 4/4
project
workspace
Names appear in the eclipse
In case of jGrasp, save it to source folder. 
Development steps
1. Define data 
1. create a structure (super and sub class)
2. Data structure in Super class
For practice purposes, let’s define these variables as “private”.
(apply encapsulation)
Let all countries design menu in their own style. So there is no need to
implement a menu here. Just define the structure.
(apply abstract class)
2. Super class - abstract
public abstract class Burger211 {
 abstract void Menu(String franchise);
}
For printing franchise name
See Slide # 12 (10-06-2020)
2. Super class - encapsulation
static private double 
price1, price2, price3;
public abstract class Burger211 {
 public double getPrice1() {
  return 
price1;
 }
 public double getPrice2() {
  return 
price2;
 }
 public double getPrice3() {
  return 
price3;
 }
 void price(){
    
price1=3.0;
    
price2=2.0;
    
price3=3.5;
  }
abstract void Menu(String franchise);
This is an “Encapsulation”. (Chapter 8.4 in CS210)
If you need details, ask me. I will send you my CS210 note.
2. Super class – Initialization (constructor)
static private double 
price1, price2, price3;
public abstract class 
Burger211
 {
 public double getPrice1() {
  return 
price1;
 }
 public double getPrice2() {
  return 
price2;
 }
 public double getPrice3() {
  return 
price3;
 }
 void price(){
    
price1=3.0;
    
price2=2.0;
    
price3=3.5;
  }
 Burger211() {
   price();
 }
abstract void Menu(String franchise);
Sub class KOREA - Structure
package taesik;
import java.text.DecimalFormat;
public class KOREA extends Burger211 {
  static double 
exchangeRate=1000;  
// foreign currency exchange rate
  static double 
discountRate =0.5;  
// promotion 0.0~1.0
  String info1="", info2="", info3=""; 
// will be sent to GUI (see slide #23) as parametres.
  KOREA(){  
// constructor. Super class, Burger211, need to initialize first. Then KOREA will do next.
            // You must understand why.
  };
}
  @Override
  public double getPrice1() {
   return (super.getPrice1()*
exchangeRate);
  }
  @Override
  public double getPrice2() {
   return (super.getPrice2()*
exchangeRate);
  }
  public double getPrice3() {
   return (super.getPrice3()*
exchangeRate);
  }
Sub class KOREA – Reading private variable in super class
 @Override
  public String getAdvertising() {
  return "^ Buy One Get One ZERO % off - CS211 Student Only ^";
}
See Slide # 17 (10-01-2020)
Sub class KOREA – Overriding menu and calling GUI
@Override
  public void Menu(String franchise){
  DecimalFormat df = new DecimalFormat("#,###,##0.0");
   if (
discountRate>0.0) {
      String p1=df.format(getPrice1()*(1.0-
discountRate));
      info1=
name1 + " / " + "W" +p1 +" (was:" + getPrice1()+")";
      String p2=df.format(getPrice2()*(1.0-
discountRate));
      info2=
name2 + " / " + "W" +p2 +" (was:" + getPrice2()+")";
      String p3=df.format(getPrice3()*(1.0-
discountRate));
      info3=
name3 + " / " + "W" +p3 +" (was:" + getPrice3()+")";
   } else {
      info1=
name1 + " / " + "W" +getPrice1() ;
      info2=
name2 + " / " + "W" +getPrice2() ;
      info3=
name3 + " / " + "W" +getPrice3() ;
   }
 // call GUI
 
   new MenuGUI(franchise,info1,getTopping1(),info2,getTopping2(),info3,getTopping3(),getAdvertising());
Each country creates their own style of menu
because of different language, price, currency
and culture.
new MenuGUI(franchise,info1,topping1,info2,topping2,info3,topping3,promo);
How to call GUI menu
Main Program- myBurger211.java
package taesik;
public class myBurger211 {
   public static void main(String[] args) {
     
Burger211
 Bellevue = new 
USA
();
     Bellevue.Menu("Bellevue");
     
Burger211
 Seattle = new 
USA
();
     Seattle.Menu("Seattle");
     
Burger211
 PyeongChang = new 
KOREA
();
     PyeongChang.Menu("PyeongChang");
     
Burger211
 Seoul = new 
KOREA
();
     Seoul.Menu("Seoul");
    }
}
See Slide # 28 (10-05-2020)
run-time Polymorphism
Menus are all superimposed and the one behind them is not visible. Click
here and then drag. You will see next one.
Output
Next Step
Complete the program.
Encapsulation: burger name, topping, and promotion
Initialization: burger name, topping, and promotion
Super class: Burger211.java
Override: getToping1(), getToping2(), getToping3(), getAdvertising(), getName1(), getName2(), getName3()
Override Menu() in details if needed.
Sub class: USA and one more country (not Korea)
And more..
Slide Note
Embed
Share

Upgrade your programming skills by improving the provided code in a systematic manner. Follow the outlined steps to create a project, add files, and resolve common errors. Access images and instructions for importing Java files to your project workspace. Start this assignment promptly for efficient completion.

  • Programming
  • Development
  • Code Improvement
  • Project Setup
  • Error Resolution

Uploaded on Feb 20, 2025 | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.

E N D

Presentation Transcript


  1. Assignment 2 Step by Step Development (outline) The code below is designed to be easy to explain. Upgrade the code to improve your programming skills. You should read 10-07-2020 Assignment2 Discussion 1.pptx before starting this slide If you have any questions, please request a zoom meeting or email your question. This assignment is not difficult but it takes a long time. I highly recommend starting this assignment ASAP. Oct. 8 2020

  2. Preparation 1. Create a project 2. Create a package 3. Download MenuGUI.java from canvas. Add (or import) MenuGUI to your package. 4. Download burger1.png, burger2.png and burger3,png and save it in the correct location.

  3. Preparation step 3/4 Download MenuGUI.java from canvas, save it to your package folder. In case of jGrasp, save it to source folder. Source folder project package workspace import MenuGUI to eclipse If you don t know how to do this, follow next slide, otherwise jump to slide #11.

  4. FYI From my cs210 lecture note How to add(import) .java file into your project Assume that you have a project (myGraphics) and a package (taesik.kim)

  5. your work space From my cs210 lecture note your project name your package name your package name place a .java file here

  6. From my cs210 lecture note .java file you want to add to your project.

  7. From my cs210 lecture note Open eclipse

  8. From my cs210 lecture note 1 Right click your package The file is now loaded but error. 2 Hit Refresh Click to open this file

  9. From my cs210 lecture note The reason why this program issue an error is THERE IS NO PACKAGE NAME or DIFFERENT PACKAGE NAME ADD/replace your package name.

  10. From my cs210 lecture note Click to save Error mark disappears after a few seconds.

  11. Preparation step 4/4 In case of jGrasp, save it to source folder. Download burger1.png, burger2.png and burger3,png and save it in your Project folder. project workspace Names appear in the eclipse

  12. Development steps

  13. 1. Define data France USA Korea name1="Inheritance Burger"; name2="Overriding Burger"; name3="Polymorphism Burger price1=3.0 * exchange rate ; price2=2.0 * exchange rate ; price3=3.5 * exchange rate ; topping1="beef patty, tomato, onion, ranch source"; topping2="beef patty, lime, onion, lettuce, tomato source"; topping3="chicken breast, gallo, onion, ranch source"; Promotion= none ; MenuStyle= French, ; name1="Inheritance Burger"; name2="Overriding Burger"; name3="Polymorphism Burger price1=3.0; price2=2.0; price3=3.5; topping1="beef patty, tomato, onion, ranch source"; topping2="beef patty, lime, onion, lettuce, tomato source"; topping3="chicken breast, gallo, onion, ranch source"; Promotion= Stay Home 50% off ; MenuStyle= English, $ ; name1="Inheritance Burger"; name2="Overriding Burger"; name3="Polymorphism Burger price1=3.0 * exchange rate ; price2=2.0 * exchange rate ; price3=3.5 * exchange rate ; topping1="beef patty, tomato, onion, ranch source"; topping2="beef patty, lime, onion, lettuce, tomato source"; topping3="chicken breast, gallo, onion, ranch source"; Promotion= Winter Olympic 50% off ; MenuStyle= Korean, W ;

  14. 1. create a structure (super and sub class) Burger211 name1="Inheritance Burger"; name2="Overriding Burger"; name3="Polymorphism Burger price1=3.0; price2=2.0; price3=3.5; topping1="beef patty, tomato, onion, ranch source"; topping2="beef patty, lime, onion, lettuce, tomato source"; topping3="chicken breast, gallo, onion, ranch source"; Promotion= ; Menu{} USA France Korea @override menu(){ } @override menu(){ } @override menu(){ }

  15. 2. Data structure in Super class Burger211 name1="Inheritance Burger"; name2="Overriding Burger"; name3="Polymorphism Burger price1=3.0; price2=2.0; price3=3.5; topping1="beef patty, tomato, onion, ranch source"; topping2="beef patty, lime, onion, lettuce, tomato source"; topping3="chicken breast, gallo, onion, ranch source"; Promotion= ; Menu{} For practice purposes, let s define these variables as private . (apply encapsulation) Let all countries design menu in their own style. So there is no need to implement a menu here. Just define the structure. (apply abstract class)

  16. 2. Super class - abstract For printing franchise name public abstract class Burger211 { abstract void Menu(String franchise); } See Slide # 12 (10-06-2020)

  17. 2. Super class - encapsulation public abstract class Burger211 { static private double price1, price2, price3; abstract void Menu(String franchise); void price(){ price1=3.0; price2=2.0; price3=3.5; } This is an Encapsulation . (Chapter 8.4 in CS210) If you need details, ask me. I will send you my CS210 note. public double getPrice1() { return price1; } public double getPrice2() { return price2; } public double getPrice3() { return price3; }

  18. 2. Super class Initialization (constructor) public abstract class Burger211 { static private double price1, price2, price3; abstract void Menu(String franchise); Burger211() { price(); } void price(){ price1=3.0; price2=2.0; price3=3.5; } public double getPrice1() { return price1; } public double getPrice2() { return price2; } public double getPrice3() { return price3; }

  19. Sub class KOREA - Structure package taesik; import java.text.DecimalFormat; public class KOREA extends Burger211 { static double exchangeRate=1000; // foreign currency exchange rate static double discountRate =0.5; // promotion 0.0~1.0 String info1="", info2="", info3=""; // will be sent to GUI (see slide #23) as parametres. KOREA(){ // constructor. Super class, Burger211, need to initialize first. Then KOREA will do next. // You must understand why. }; }

  20. Sub class KOREA Reading private variable in super class See Slide # 17 (10-01-2020) @Override public double getPrice1() { return (super.getPrice1()*exchangeRate); } @Override public double getPrice2() { return (super.getPrice2()*exchangeRate); } public double getPrice3() { return (super.getPrice3()*exchangeRate); } @Override public String getAdvertising() { return "^ Buy One Get One ZERO % off - CS211 Student Only ^"; }

  21. Sub class KOREA Overriding menu and calling GUI @Override public void Menu(String franchise){ DecimalFormat df = new DecimalFormat("#,###,##0.0"); if (discountRate>0.0) { String p1=df.format(getPrice1()*(1.0-discountRate)); info1=name1 + " / " + "W" +p1 +" (was:" + getPrice1()+")"; Each country creates their own style of menu because of different language, price, currency and culture. String p2=df.format(getPrice2()*(1.0-discountRate)); info2=name2 + " / " + "W" +p2 +" (was:" + getPrice2()+")"; String p3=df.format(getPrice3()*(1.0-discountRate)); info3=name3 + " / " + "W" +p3 +" (was:" + getPrice3()+")"; } else { info1=name1 + " / " + "W" +getPrice1() ; info2=name2 + " / " + "W" +getPrice2() ; info3=name3 + " / " + "W" +getPrice3() ; } // call GUI new MenuGUI(franchise,info1,getTopping1(),info2,getTopping2(),info3,getTopping3(),getAdvertising());

  22. How to call GUI menu new MenuGUI(franchise,info1,topping1,info2,topping2,info3,topping3,promo);

  23. Main Program- myBurger211.java package taesik; public class myBurger211 { public static void main(String[] args) { Burger211 Bellevue = new USA(); Bellevue.Menu("Bellevue"); Burger211 Seattle = new USA(); Seattle.Menu("Seattle"); run-time Polymorphism See Slide # 28 (10-05-2020) Burger211 PyeongChang = new KOREA(); PyeongChang.Menu("PyeongChang"); Burger211 Seoul = new KOREA(); Seoul.Menu("Seoul"); } }

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

  25. Next Step Complete the program. Super class: Burger211.java Encapsulation: burger name, topping, and promotion Initialization: burger name, topping, and promotion Sub class: USA and one more country (not Korea) Override: getToping1(), getToping2(), getToping3(), getAdvertising(), getName1(), getName2(), getName3() Override Menu() in details if needed. And more..

More Related Content

giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#