import java.util.Scanner;
public class PizzaOrder_Demo {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
String size1;
int cheese1, pepp1, ham1, cheese2, pepp2, ham2, num;
System.out.println("Enter the size of pizza for pizza1 for pizza1 ");
size1 = input.nextLine();
System.out.println("Enter the number of cheese toppings for pizza1");
cheese1 = input.nextInt();
System.out.println("the number of pepperoni toppings for pizza1");
pepp1 = input.nextInt();
System.out.println("the number of ham toppings for pizza1");
ham1 = input.nextInt();
System.out.println("Enter the size of pizza for pizza1 for pizza2");
input.nextLine();
String size2;
size2 = input.nextLine();
System.out.println("Enter the number of cheese toppings for pizza2");
cheese2 = input.nextInt();
System.out.println("the number of pepperoni toppings for pizza2");
pepp2 = input.nextInt();
System.out.println("the number of ham toppings for pizza2");
ham2 = input.nextInt();
Pizza pizza1 = new Pizza(size1, cheese1, pepp1, ham1);
Pizza pizza2 = new Pizza(size2, cheese2, pepp2, ham2);
Pizza pizza3 = new Pizza("small", 0, 0, 0);
PizzaOrder order = new PizzaOrder(1, pizza1, pizza2, pizza3);
num = input.nextInt();
order.SetNumPizzas(num);
order.setPizza1(pizza1);
order.setPizza2(pizza2);
double total = order.calcTotal();
System.out.println("The total cost is "+ total);
input.close();
}
}
class PizzaOrder {
private int numPizzas;
private Pizza pizza1;
private Pizza pizza2;
private Pizza pizza3;
// constructor
public PizzaOrder(int numPizzas, Pizza pizza1, Pizza pizza2, Pizza pizza3) {
this.numPizzas = numPizzas;
this.pizza1 = pizza1;
this.pizza2 = pizza2;
this.pizza3 = pizza3;
}
public void SetNumPizzas(int numPizzas) {
if (numPizzas > 3)
this.numPizzas = 3;
else if (numPizzas < 1)
this.numPizzas = 0;
}
public int getNumpizzas() {
return numPizzas;
}
public void setPizza1(Pizza pizza1) {
this.pizza1 = pizza1;
}
public Pizza getPizza1() {
return pizza1;
}
public void setPizza2(Pizza pizza2) {
this.pizza2 = pizza2;
}
public Pizza getPizza2() {
return pizza2;
}
public void setPizza3(Pizza pizza3) {
this.pizza3 = pizza3;
}
public Pizza getPizza3() {
return pizza3;
}
public double calcTotal() {
double total = pizza1.CalCost();
if (numPizzas >= 2)
total += pizza2.CalCost();
if (numPizzas == 3)
total += pizza3.CalCost();
return total;
}
}
class Pizza {
private String sofpizza;
private int nofcheese, nofpepperoni, nofham;
// construtor
public Pizza(String sofpizza, int nofcheese, int nofpepperoni, int nofham) {
this.sofpizza = sofpizza;
this.nofcheese = nofcheese;
this.nofpepperoni = nofpepperoni;
this.nofham = nofham;
}
// method
public void set_sofpizza(String l) {
this.sofpizza = l;
}
public String get_sofpizza() {
return sofpizza;
}
public void set_nofcheese(int b) {
this.nofcheese = b;
}
public int get_nofcheese() {
return nofcheese;
}
public void set_nofpepperoni(int p) {
this.nofpepperoni = p;
}
public int get_nofpepperoni() {
return nofpepperoni;
}
public void set_nofham(int h) {
this.nofham = h;
}
public int get_nofham() {
return nofham;
}
public double CalCost() {
if (sofpizza.equalsIgnoreCase("small"))
return (10 + (2 * nofcheese) + (2 * nofpepperoni) + (2 * nofham));
else if (sofpizza.equalsIgnoreCase("medium"))
return (12 + (2 * nofcheese) + (2 * nofpepperoni) + (2 * nofham));
else
return (14 + (2 * nofcheese) + (2 * nofpepperoni) + (2 * nofham));
}
public String getDiscription() {
return (" Size of pizza= " + sofpizza + "\n number of cheese= " + nofcheese + "\n number of pepperoni= "
+ nofpepperoni + "\n number of ham=" + nofham);
}
}
//////////////////////////////////
I put all the three files in one file and then compiled them all......
According to your program this is the output that I got..........
/////////////////////
Let me tell you all the errors that i corrected.......
public void set_nofcheese(int b) {
this.nofcheese = b;
}
//You had written
public void set_nofcheese(int b) {
this.nofcheese = nofcheese;
//Same error here..
public void set_nofpepperoni(int p) {
this.nofpepperoni = p;
}
//Same error here too
public void set_nofham(int h) {
this.nofham = h;
}
//Another error
public void SetNumPizzas(int numPizzas) {
if (numPizzas > 3)
this.numPizzas = 3;
else if (numPizzas < 1)
this.numPizzas = 0;
//You had simply given an extra else condition which wasnt needed;
//After changing that the code runs......
//Hope this helps you
Happy Coding :) :)
Using Java, I created 3 files, Pizza,PizzaOrder, and PizzaOrder_Demo that I attached down below. But I...
Create a class named Pizza that scores information about a single pizza. It should contain the following: Private instance variable to store the size of the pizza (either small, medium, or larger), the number of cheese toppings, the number of pepperoni toppings, and the number of ham toppings. Constructor(s) that set all of the instance variables. Public methods to get and set the instance variables. A public method named calsCost( ) that returns a double that...
Q1. rewrite the exercise on April 4 by adding the
following operations:
1) In the php script, create an associative array named
$order that stores the following values:
- the number of cheese toppings;
- the number of pepperoni toppings;
- the number of
ham
toppings;
- the size of the ordered pizza;
- the number of the ordered pizza;
- the total cost of the order;
- the discount rate;
- the total cost after the discount.
2) the...
Consider the class as partially defined here: //class Pizzaorder class Pizzaorder // static public members public static final int MAX TOPPINGS 20: // instance members private String toppings[]; private int numToppings; // constructor public PizzaOrder () { numToppings toppings 0; String[MAX TOPPINGS]; new // accessor tells # toppings on pizza, i.e., #toppings in array public int getNum Toppings ()return numToppings; // etc. We want to write an instance method, addTopping) that will take a String parameter, topping, and add it...
Hello can someone help me in my code I left it as comment task #0, task#1, task#2a and task#2b the things that I am missing I'm using java domain class public class Pizza { private String pizzaCustomerName; private int pizzaSize; // 10, 12, 14, or 16 inches in diameter private char handThinDeep; // 'H' or 'T' or 'D' for hand tossed, thin crust, or deep dish, respecitively private boolean cheeseTopping; private boolean pepperoniTopping; private boolean sausageTopping; private boolean onionTopping; private boolean...
Java. Java is a new programming language I am learning, and so far I am a bit troubled about it. Hopefully, I can explain it right. For my assignment, we have to create a class called Student with three private attributes of Name (String), Grade (int), and CName(String). In the driver class, I am suppose to have a total of 3 objects of type Student. Also, the user have to input the data. My problem is that I can get...
After pillaging for a few weeks with our new cargo bay upgrade, we decide to branch out into a new sector of space to explore and hopefully find new targets. We travel to the next star system over, another low-security sector. After exploring the new star system for a few hours, we are hailed by a strange vessel. He sends us a message stating that he is a traveling merchant looking to purchase goods, and asks us if we would...
Below are the Car class and Dealership class that I
created In the previous lab
import java.util.ArrayList;
class Car
{
private String make;
private String model;
private int year;
private double transmission;
private int seats;
private int maxSpeed;
private int wheels;
private String type;
public Car()
{
}
public Car(String make, String model, int year, double transmission, int seats, int maxSpeed, int wheels, String type) {
this.make = make;
this.model = model;
this.year = year;
this.transmission = transmission;
this.seats =...
Solve this using Java for an Intro To Java Class.
Provided files:
Person.java
/**
* Models a person
*/
public class Person
{
private String name;
private String gender;
private int age;
/**
* Consructs a Person object
* @param name the name of the person
* @param gender the gender of the person either
* m for male or f for female
* @param age the age of the person
*/
public Person(String name, String gender, int age)
{...
How to build Java test class? I am supposed to create both a recipe class, and then a class tester to test the recipe class. Below is what I have for the recipe class, but I have no idea what/or how I am supposed to go about creating the test class. Am I supposed to somehow call the recipe class within the test class? if so, how? Thanks in advance! This is my recipe class: package steppingstone5_recipe; /** * *...
using C# language This program will demonstrate inheritance. Your Pizza Shop expands and now handles delivery orders and sit down orders in a restaurant setting. There are differences in a SeatedPizzaOrder and a DeliveryPizzaOrder. These are more specialized versions of the PizzaOrders you have been creating all along and you decide to write a program that handles them the same as much as possible and reuses the code of a general PizzaOrder class as much as possible to demonstrate inheritance....