Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Im working on a project and im posting what i have so far, however I am missing some components required and I am unsure how

Im working on a project and im posting what i have so far, however I am missing some components required and I am unsure how to add the missing ones. Also i may have a issue with what i have already. I will post the pages i have below along with the requirements, please can you help me with finishing this project.

Main.java

import java.util.ArrayList; import java.util.Scanner;

public class Main {

// main method public static void main(String[] args) {

// Creating arraylist to keep pizza ArrayList pizza = new ArrayList<>();

// Creating pizza reg crust using different constructors PizzaRegCrust1 pizza1 =new PizzaRegCrust1("Cheese Pizza"); PizzaRegCrust2 pizza2 = new PizzaRegCrust2("Pepperoni Pizza");

// Creating pizza thin crust using different constructors PizzaThinCrust1 pizzathin1 = new PizzaThinCrust1("Cheese Pizza"); PizzaThinCrust2 pizzathin2 = new PizzaThinCrust2("Pepperoni Pizza");

// Adding pizza regCrust and thinCrust to arraylist pizza.add(pizza1); pizza.add(pizza2); pizza.add(pizzathin1); pizza.add(pizzathin2);

// Creating scanner object to read input from user Scanner scanner = new Scanner(System.in);

// Showing option to choose System.out.println("Choose what pizza you want to create: "); System.out.println("1. Regular crust pizza"); System.out.println("2. Thin crust pizza"); System.out.println("Enter your choice (1 or 2): "); System.out.println("Enter your topping (1. cheese or 2. pepperoni): "); try { // Creating pizza after reading choice from user Pizza newPizza = createPizza(scanner.nextLine(), scanner); pizzas.add(newPizza); // adding newly created pizza to arraylist

} catch (Exception ex) { // catching exception if any exception occurred during pizza creation System.out.println("Exception handled: " + ex.getMessage()); }

// Printing details of all pizzas by iterating over the arraylist System.out.println("Printing all pizzas.. "); for (int i = 0; i < pizzas.size(); i++) { Pizza pizza = pizzas.get(i); // getting pizza by index pizza.displayDetails(); // displaying details System.out.println(); // printing a new line }

private static Pizza createPizza(String choice, Scanner scanner) throws Exception { switch (choice) { case "1": { System.out.println("Enter selection: ");

Int selection1 = scanner.nextInt(); PizzaRegCrust1 = new Pizza1 ("Pizza Crust Selected"); Int selection2 = scanner.nextInt(); PizzaRegCrust2 = new Pizza2 ("Pizza Topping Selected"); return PizzaRegCrust; } case "2": { System.out.println("Enter selection: "); Int selection3 = scanner.nextInt(); PizzaThinCrust1 = new Pizza3 ("Pizza Crust Selected"); Int selection4 = scanner.nextInt(); PizzaThinCrust2 = new Pizza4 ("Pizza Topping Selected"); return PizzaThinCrust; } default: throw new Exception("Invalid selection"); } } }

Pizza.java

// Abstract class Pizza public abstract class Pizza {

// instance variables protected String crusts; protected String toppings;

// Constructor 1 public Pizza() { this.crust = "Regular"; this.topping = "Cheese"; }

// Constructor 2 public Pizza() { this.crust = "Regular"; this.topping = "Pepperoni"; }

// Constructor 3 public Pizza() { this.crust = "Thin"; this.topping = "Cheese"; } // Constructor 4 public Pizza() { this.crust = "Thin"; this.topping = "Pepperoni"; }

// Getters and Setters

public String getCrust() { return crust; }

public void setCrust(String crust) { this.crust = crust; }

public String getTopping() { return topping; }

public void setTopping(String topping) { this.topping = topping; }

// Method to display details public void displayDetails() {

System.out.println("Crust: " + getCrust()); System.out.println("Topping: " + getTopping());

}

}

PizzaRegCrust.java

// Class PizzaRegCrust inheriting Pizza class public class PizzaRegCrust extends Pizza { private int pizza;

// Constructor 1 public PizzaRegCrust1() { super("Pizza Regular Crust"); this.pizza = "Cheese"; }

// Constructor 2 public PizzaRegCrust2() { super("Pizza Regular Crust"); this.pizza = "Pepperoni"; }

}

// Implementing abstract method, needed below unsure how to create one //@Override

PizzaThinCrust.java

public class PizzaThinCrust extends Pizza { private int pizza;

// Constructor 1 public PizzaThinCrust1() { super("Pizza Regular Crust"); this.pizza = "Cheese"; }

// Constructor 2 public PizzaThinCrust() { super("Pizza Regular Crust"); this.pizza = "Peperoni"; }

}

// Implementing abstract method, needed below unsure how to create one //@Override

Requirements for project:

4 Pillars of OOP

Inheritance, Polymorphism (overloading or overriding), Encapsulation, Abstraction (Abstract class or Interface)

Must create and use at least 3 Constructors

Must create and invoke at least four methods.

the main method does not count towards the method count

Two methods must not be getter or setter methods

The method must have a purpose

//This will not count public void methodOne(){ System.out.println("method one"); }

Use a Scanner to get responses from the user

Must contain a switch statement

Must handle at least one exception

The project must include at least 3 Classes

Use one of the Collections structures.

ArrayList, HashSet, Queue, Stack, LinkedList, HashMap (One of these Data Structures will count)

Use a loop to traverse through the Collection structure you chose and modify, organize or return values from the iteration.

The project must have a cohesive flow. Meaning the mentors need to understand what your project's purpose is. (i.e. Ice Cream Shop project should not have SpagehettiSauce class).

Each part of your code should be meaningful and used at least once. i.e. if any line of code in any class is deleted, this should result in a compiler error.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

2. Describe why we form relationships

Answered: 1 week ago

Question

5. Outline the predictable stages of most relationships

Answered: 1 week ago