Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Noodle {
- protected double lengthInCentimeters;
- protected double widthInCentimeters;
- protected String shape;
- protected String ingredients;
- protected String texture = "brittle";
- //Constructor
- Noodle(double lenInCent, double wthInCent, String shp, String ingr) {
- this.lengthInCentimeters = lenInCent;
- this.widthInCentimeters = wthInCent;
- this.shape = shp;
- this.ingredients = ingr;
- }
- public String getCookPrep() {
- return "Boil noodle for 7 minutes and add sauce.";
- }
- public static void main(String[] args) {
- Noodle spaghetti, ramen, pho; // put instances of different classes that share a parent class together in an array
- spaghetti = new Spaghetti();
- ramen = new Ramen();
- pho = new Pho();
- // Add your code below:
- Noodle[] allTheNoodles = {spaghetti, ramen, pho}; //declare and initialize array of Noodle class type here
- for (Noodle nood: allTheNoodles){ //loop through each noodle in the array to print the method of the child class
- System.out.println(nood.getCookPrep());
- }
- }
- }
- ============================================================================================================================
- class Spaghetti extends Noodle {
- Spaghetti() {
- super(30.0, 0.2, "round", "semolina flour");
- }
- @Override
- public String getCookPrep() { //Method will be printed
- return "Boil spaghetti for 8 - 12 minutes and add sauce, cheese, or oil and garlic.";
- }
- }
- ============================================================================================================================
- class Ramen extends Noodle {
- Ramen() {
- super(30.0, 0.3, "flat", "wheat flour");
- }
- @Override
- public String getCookPrep() { //Method will be printed
- return "Boil ramen for 5 minutes in broth, then add meat, mushrooms, egg, and vegetables.";
- }
- }
- ============================================================================================================================
- class Pho extends Noodle {
- Pho() {
- super(30.0, 0.64, "flat", "rice flour");
- }
- @Override
- public String getCookPrep() { //Method will be printed
- return "Soak pho for 1 hour, then boil for 1 minute in broth. Then garnish with cilantro and jalapeno.";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement