Java Programming Coursework: Complete Pizza Order System Code

Verified

Added on  2020/07/23

|11
|1011
|95
Homework Assignment
AI Summary
This assignment provides a Java code solution for a pizza order system, designed to meet the requirements of a coursework project. The code allows users to input their preferences for pizza size (small, medium, large), crust type (deep pan, thin crust, stuffed crust), and toppings (pineapple, anchovy). The program uses conditional statements to process user input and determine the pizza's characteristics. The code includes variables for pizza attributes like crust, sauce, and toppings, along with calculations for cost, tax, and total amount due. The system takes user inputs and provides a customized pizza order. The program also incorporates input validation to handle different user inputs and ensure the system functions correctly. Screenshots of the code and its output are also provided.
Document Page
JAVA COURSEWORK
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
TABLE OF CONTENTS
Pizza Order System.....................................................................................................................................2
Code........................................................................................................................................................2
Document Page
Pizza Order System
The following code covers all the basic requirements that are needed as the users who want to
order a pizza should ensure that the overall size for pizza choices is restricted to 6 whereas the user is free
to choose either zero, one or two toppings. As per the instructions, the toppings that can be used in this
project are either pineapple or anchovy. The base and crust of pizza can also be classified in three types.
So, all the required factors have been involved in the following code.
Code
import java.util.Scanner;
public class Pizza
{
String firstname = "xx";
char crusttype;
String crust;
String sauce;
String base1 = "small";
String base2 = "medium";
String base3 = "large";
int inches = 0;
double cost = 0.0;
final double taxrate=0.00;
double tax;
double total;
double Ltotal;
int numberoftoppings =6;
String Firsttopping = "pineapple";
String Secondtopping = "anchovy";
/**
* Constructor for objects of class Pizza
*/
public Pizza()
{
Document Page
// initScanner keyboard = new Scanner(System.in);
}
public static void main (String[] args) {
Scanner keyboard = new Scanner(System.in);
String firstname = "xx";
char crusttype;
String crust;
String sauce;
String base1 = "small";
String base2 = "medium";
String base3 = "large";
int inches = 0;
double cost = 0.0;
final double taxrate=0.00;
double tax;
double total;
double Ltotal;
int numberoftoppings =6;
String Firsttopping = "pineapple";
String Secondtopping = "anchovy";
System.out.println ("Enter the name :");
double distance = 0;
System.out.println ("What size will you prefer???");
inches = keyboard.nextInt();
if (inches == 10) {
System.out.println("base1");
}
if (inches == 12) {
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
System.out.println("base2");
}
if (inches == 14) {
System.out.println("base3");
}
keyboard.nextLine();
System.out.println ("What type of crust you want, (D)eep Pan, (T)hin crust, (S)tuffed crust ?");
crusttype = keyboard.nextLine().charAt(0);
if (crusttype == 'D' || crusttype == 'd') {
crust = "Deep Pan";
}
else if (crusttype == 'T' || crusttype == 't') {
crust = "Thin crust";
}
else if (crusttype == 'S' || crusttype == 's') {
crust = "Stuffed crust";
}
else if (crusttype != 'D' || crusttype != 'd' && crusttype != 'T' || crusttype != 't'&& crusttype != 'S' ||
crusttype != 's') {
crust = "Deep Pan";
System.out.println("All crusts come with a tomato sauce and mozzarella topping");
System.out.println ("Tomato sauce can be changed to BBQ at 50p, either for topping, choose from
Pineapple or anchovy");
System.out.println("Do you want Pineapple? (Y/N)");
if (numberoftoppings=='Y' || numberoftoppings=='y') {
numberoftoppings = numberoftoppings + 1;
Firsttopping = Firsttopping + " and Pineapple";
}
else {
}
System.out.println("Do you want Anchovy? (Y/N)");
Document Page
if (numberoftoppings=='Y' || numberoftoppings=='y') {
numberoftoppings = numberoftoppings + 1;
Secondtopping = Secondtopping + " and Anchovy";
}
else {
if (numberoftoppings=='N' || numberoftoppings=='n')
System.out.println("you don't want any topping. Thankyou");
}
System.out.println (cost);
System.out.println (numberoftoppings);
total = (cost) + (numberoftoppings * 1.25);
tax = total * taxrate;
Ltotal = total + (1 + taxrate);
System.out.println (firstname + ", your order :)");
System.out.println (inches + "inch pizza");
System.out.println (crust + "toppings");
System.out.println ("Order cost : $ + (total)");
System.out.println ("Tax: $");
System.out.println ("Total Due : $");
}
}
}
The screenshots of the following code with output are represented as under :
Document Page
As the crossed lines have been erased, it means that the program has been compiled successfully. Also, it
means that all the errors have been resolved and the code has been compiled successfully.
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
Document Page
The screenshot represents all the variables that have been included in the code and are essential to be
involved in order to complete the requirements of the pizza order system.
Document Page
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
This output asks the user for their preference so that on the basis of that the pizza can be ordered and then
delivered to the user. As in this case, D is entered by the user, so the pizza order system will order a deep
pan crust for the pizza that has been ordered. If the user will enter any other input which is other than D,
d, T, t, S and s, then by default, the pizza order system will input the deep pan crust to the pizza that has
been ordered by the user.
chevron_up_icon
1 out of 11
circle_padding
hide_on_mobile
zoom_out_icon
[object Object]