Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I am having difficulity in making this program with to work. This problems are counting out number of Toppings from the textfile,and calculating the price,

I am having difficulity in making this program with to work. This problems are counting out number of Toppings from the textfile,and calculating the price, next i having difficulty in sorting the pizza in descending order and displaying it in java.The other two works perfectly fine, it is pizzaArrayList is the challenging one.

Here is the assignment:

Design a class named Pizza which has three fields: crust, size, and toppings. You decide the data types and values which can be assigned to these fields. In addition to the constructor and three instance methods, each returning one of the fields, there is also a method called costOfPizza which returns the cost of the pizza based on the size, crust, and toppings of that pizza.Write a program to assist the manager at Pizza Delight in processing the order stored in the textfile. An order may consist of more than one pizza. The program displays the detail information about each pizza in the order followed by the amount due. The output of the pizza is arranged in descending order on cost of each pizza. The program also displays the total cost of the order with a 10% tax rate.

textfile:

...............................................

Hand-tossed, Large

pineapple mushroom, spinach, tomato

thick, small Sausage, Tomato, Mushroom

pizza.java

............................

public class Pizza {

private String Crust; private String Size; private String Toppings; /**Initializes the members of Pizza object object. @param crust a string representing the type of crust on the pizza. @param size string representing the size of the pizz @param toppings string representing the toppings of the pizza **/ public Pizza (String Crust, String Size, String Toppings) { this.Crust= Crust; this.Size = Size; this.Toppings= Toppings; } // constructor

/** Assigns a new type of crust @param Crust a string representing the type of crust */ public void setCrust(String Crust) { this.Crust = Crust; } // method setCrust

/** Assigns a new size to the pizza. @param Size a string representing the size of pizza */ public void setSize(String Size) { this.Size = Size; } // method setSize

/** Assigns a new toppings to the pizza. @param topping a string representing the toppings of the pizza */ public void setToppings(String Toppings) { this.Toppings = Toppings; } // method setToppings

/** Returns the type of crust of the pizza. @return crust tyoe */ public String getCrust() { return Crust; } // method getCrust

/** Returns the size of the pizza @return pizza size */ public String getSize() { return Size; } // method getSize

/** Returns the pizza toppings. @return pizza toppings */ public String getToppings() { return Toppings; } // method getToppings

}//pizza

pizzaArraylist.java

.................................

import java.io.*; import java.util.*; /** This program shows how to read in the pizza orders from an input data fle and store them in an array list. Pizza are stored using an ArrayList object. */ public class PizzaArrayList { private ArrayList pizzas; private Scanner infile;

public static void main(String[] args) throws IOException { PizzaArrayList current;

current = new PizzaArrayList(); current.getStarted(); } // method main /** Starts the program */ public void getStarted() throws FileNotFoundException, IOException { openFile(); readData(); calculateData(); sortData(); displayResults(); infile.close(); } // method getStarted /** Opens the input data file for read access. */ public void openFile() throws FileNotFoundException, IOException { Scanner input; String infile_name; File file;

Utility.clearScreen(); Runtime.getRuntime().exec("ls"); input = new Scanner(System.in); do { System.out.print("Enter the input file name: "); infile_name = input.next();

// open the input data file file = new File(infile_name); if (file.exists()) infile = new Scanner(new File(infile_name)); else System.out.println(infile_name + " does not exist"); } while (!file.exists()); } // method openFile

/** Reads in text from file and save them in an array list. @param infile the file which has been open successfully */ public void readData() { Pizza who; String Crust, Size, Toppings;

// instantiate an ArrayList object pizza = new ArrayList();

// read in values from the file and assign them to the elements

while (infile.hasNext()) { Crust = infile.next(); Size = infile.next(); Toppings= infile.next(); int arrayLength = Toppings.length; who = new Pizza (Crust, Size, Toppings); pizzas.add(who); } } // method readData /** Calcalute the price of the pizza from text file.

*/ public void calculateData() { /** define the constants **/ private final double Topping_Cost=1.50; //constant per topping private final double Small_Cost=9.50; // cost for small sized pizza private final double Medium_Cost= 12.25;// cost for medium sized pizza private final double Large_Cost=14.50; //cost for large size pizza. int Toppings_Num;// number of toppings of the pizza int Sum_Toppings;// the total cost of toppings int Total_Cost;// total cost of pizza if (Size.equalsIgnoreCase("small")) { Sum_Toppings= arrayLength*Topping_Cost; return Total_Cost= (Sum_Toppings + Small_Cost) ;

} else if (Size.equalsIgnoreCase(medium)) { Sum_Toppings= arrayLength*Topping_Cost; return Total_Cost= (Sum_Toppings + Medium_Cost) ; } if (Size.equalsIgnoreCase(large) { Sum_Toppings= arrayLength*Topping_Cost; return Total_Cost= (Sum_Toppings + Large_Cost);

} else { return 0; } public void sortData(Pizza pizza, int n) { for (int i=0; i

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_2

Step: 3

blur-text-image_3

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

Databases Illuminated

Authors: Catherine M. Ricardo, Susan D. Urban, Karen C. Davis

4th Edition

1284231585, 978-1284231588

More Books

Students also viewed these Databases questions