Java
Software Originals, Inc., has been hired by Eaton Wright, the "pizza king", to help automate a new chain of pizza delivery stores. SOI's system engineering staff have asked you to implement a prototype for the telephone operator's console. To start the project they have assigned you to implement the following two static methods (the first of which will be used to read files containing menus of pizza sizes and their prices, and pizza toppings and their prices; and the second of which will be used to read the first order from a file containing pizza orders whose total prices are to be calculated). They haven't had time to write formal specifications; hence the informal nature of the descriptions.
Implement the static method getPriceMap declared as follows:
/** * Inputs a "menu" of words (items) and their prices from the given file and * stores them in the given {@code Map}. * * @param fileName * the name of the input file * @param priceMap * the word -> price map * @replaces priceMap * @requires <pre> * [file named fileName exists but is not open, and has the * format of one "word" (unique in the file) and one price (in cents) * per line, with word and price separated by ','; the "word" may * contain whitespace but no ','] * </pre> * @ensures [priceMap contains word -> price mapping from file fileName] */ private static void getPriceMap(String fileName, Map<String, Integer> priceMap) {...} |
You may find some String methods (e.g., substring(int, int) and indexOf(char)) as well as the Integer class parseInt(String) static method to be useful in coding this method.
Implement the static method getOneOrder declared as follows:
/** * Input one pizza order and compute and return the total price. * * @param input * the input stream * @param sizePriceMap * the size -> price map * @param toppingPriceMap * the topping -> price map * @return the total price (in cents) * @updates input * @requires <pre> * input.is_open and * [input.content begins with a pizza order consisting of a size * (something defined in sizePriceMap) on the first line, followed * by zero or more toppings (something defined in toppingPriceMap) * each on a separate line, followed by an empty line] * </pre> * @ensures <pre> * input.is_open and * #input.content = [one pizza order (as described * in the requires clause)] * input.content and * getOneOrder = [total price (in cents) of that pizza order] * </pre> */ private static int getOneOrder(SimpleReader input, Map<String, Integer> sizePriceMap, Map<String, Integer> toppingPriceMap) {...} |
//PizzaOrderManager.java
import components.map.Map;
import components.map.Map1L;
import components.simplereader.SimpleReader;
import components.simplereader.SimpleReader1L;
import components.simplewriter.SimpleWriter;
import components.simplewriter.SimpleWriter1L;
/**
* Simple pizza order manager: inputs orders from a file and
computes and
* displays the total price for each order.
*
*/
public final class PizzaOrderManager {
/**
* Private constructor so this utility
class cannot be instantiated.
*/
private PizzaOrderManager() {
}
/**
* Inputs a "menu" of words (items) and
their prices from the given file and
* stores them in the given {@code
Map}.
*
* @param fileName
*
the name of the input file
* @param priceMap
*
the word -> price map
* @replaces {@code priceMap}
* @requires <pre>
* {@code [file named fileName exists but
is not open, and has the
* format of one "word" (unique in the
file) and one price (in cents)
* per line, with word and price separated
by ','; the "word" may
* contain whitespace but not ',']}
* </pre>
* @ensures <pre>
* {@code [priceMap contains word ->
price mapping from file fileName]}
* </pre>
*/
private static void getPriceMap(String
fileName,
Map<String, Integer> priceMap) {
assert fileName != null
: "Violation of: fileName is not null";
assert priceMap != null
: "Violation of: priceMap is not null";
/*
* Note:
Precondition not checked!
*/
SimpleReader input =
new SimpleReader1L(fileName);
while (!input.atEOS())
{
String thisLine = input.nextLine();
String thisKey = thisLine.substring(0,
thisLine.indexOf(','));
String thisValue = thisLine.substring(thisLine.indexOf(',') +
1,
thisLine.length());
int value = Integer.parseInt(thisValue);
priceMap.add(thisKey, value);
}
input.close();
}
/**
* Input one pizza order and compute and
return the total price.
*
* @param input
*
the input stream
* @param sizePriceMap
*
the size -> price map
* @param toppingPriceMap
*
the topping -> price map
* @return the total price (in cents)
* @updates {@code input}
* @requires <pre>
* {@code input.is_open and
* [input.content begins with a pizza order
consisting of a size
* (something defined in sizePriceMap) on
the first line, followed
* by zero or more toppings (something
defined in toppingPriceMap)
* each on a separate line, followed by an
empty line]}
* </pre>
* @ensures <pre>
* {@code input.is_open and
* #input.content = [one pizza order (as
described
*
in the requires clause)] * input.content and
* getOneOrder = [total price (in cents) of
that pizza order]}
* </pre>
*/
private static int getOneOrder(SimpleReader
input,
Map<String, Integer> sizePriceMap,
Map<String, Integer> toppingPriceMap) {
assert input != null :
"Violation of: input is not null";
assert sizePriceMap !=
null : "Violation of: sizePriceMap is not null";
assert toppingPriceMap
!= null : "Violation of: toppingPriceMap is not null";
assert input.isOpen() :
"Violation of: input.is_open";
int price = 0;
int size =
sizePriceMap.value(input.nextLine());
price = price +
size;
String toppingSTR =
input.nextLine();
int topping = 0;
while
(!toppingSTR.isEmpty()) {
topping = toppingPriceMap.value(toppingSTR);
price += topping;
toppingSTR = input.nextLine();
}
return price;
}
/**
* Output the given price formatted in
dollars and cents.
*
* @param output
*
the output stream
* @param price
*
the price to output
* @updates {@code output}
* @requires <pre>
* {@code output.is_open = true and 0 <=
price}
* </pre>
* @ensures <pre>
* {@code output.is_open and
* output.content = #output.content *
* [display of price, where price is in
cents but
* display is formatted in
dollars and cents]}
* </pre>
*/
private static void putPrice(SimpleWriter
output, int price) {
assert output != null :
"Violation of: output is not null";
assert output.isOpen() :
"Violation of: output.is_open";
assert 0 <= price :
"Violation of: 0 <= price";
int cents = price %
100;
price /= 100;
if (cents < 10)
{
output.println("$" + price + ".0" + cents);
} else {
output.println("$" + price + "." + cents);
}
}
/**
* Main method.
*
* @param args
*
the command line arguments
*/
public static void main(String[] args) {
SimpleReader in = new
SimpleReader1L("data/orders.txt");
SimpleWriter out = new
SimpleWriter1L();
Map<String,
Integer> sizeMenu = new Map1L<String, Integer>();
Map<String,
Integer> toppingMenu = new Map1L<String, Integer>();
int orderNumber =
1;
/*
* Get menus of
sizes with prices and toppings with prices
*/
getPriceMap("data/sizes.txt", sizeMenu);
getPriceMap("data/toppings.txt", toppingMenu);
/*
* Output heading
for report of pizza orders
*/
out.println();
out.println("Order");
out.println("Number
Price");
out.println("------
------");
/*
* Process orders,
one at a time, from input file
*/
while (!in.atEOS())
{
int price = getOneOrder(in, sizeMenu, toppingMenu);
out.print(orderNumber + " ");
putPrice(out, price);
out.println();
orderNumber++;
}
out.println();
/*
* Close input and
output streams
*/
in.close();
out.close();
}
}
Java Software Originals, Inc., has been hired by Eaton Wright, the "pizza king", to help automate...
complete this in java import java.io.File; import java.io.FileNotFoundException; import java.util.ArrayList; import java.util.Random; import java.util.Scanner; public class WordDetective { /** * Finds the specified set of words in the specified file and returns them * as an ArrayList. This finds the specified set in the file which is on the * line number of the set. The first line and set in the file is 1. * * This returns an ArrayList with the keyword first, then : and then followed...
I need help running this code. import java.util.*; import java.io.*; public class wordcount2 { public static void main(String[] args) { if (args.length !=1) { System.out.println( "Usage: java wordcount2 fullfilename"); System.exit(1); } String filename = args[0]; // Create a tree map to hold words as key and count as value Map<String, Integer> treeMap = new TreeMap<String, Integer>(); try { @SuppressWarnings("resource") Scanner input = new Scanner(new File(filename));...
Please write a code in Java where it says your // your code here to run the code smoothly. Import statements are not allowed. _ A Java method is a collection of statements that are grouped together to perform an operation. Some languages also call this operation a Function. When you call the System.out.println() method, for example, the system actually executes several statements in order to display a message on the console. Please write the code according to functions assigned...
Please write a code in Java where it says your // your code here to run the code smoothly. Import statements are not allowed for this assignment, so don't use them. _ A Java method is a collection of statements that are grouped together to perform an operation. Some languages also call this operation a Function. When you call the System.out.println() method, for example, the system actually executes several statements in order to display a message on the console. Please...
create a new Java application called "CheckString" (without the quotation marks) according to the following guidelines. ** Each method below, including main, should handle (catch) any Exceptions that are thrown. ** ** If an Exception is thrown and caught, print the Exception's message to the command line. ** Write a complete Java method called checkWord that takes a String parameter called word, returns nothing, and is declared to throw an Exception of type Exception. In the method, check if the...
Given java code is below, please use it! import java.util.Scanner; public class LA2a { /** * Number of digits in a valid value sequence */ public static final int SEQ_DIGITS = 10; /** * Error for an invalid sequence * (not correct number of characters * or not made only of digits) */ public static final String ERR_SEQ = "Invalid sequence"; /** * Error for...
For this lab you will write a Java program that plays a simple Guess The Word game. The program will prompt the user to enter the name of a file containing a list of words. These words mustbe stored in an ArrayList, and the program will not know how many words are in the file before it starts putting them in the list. When all of the words have been read from the file, the program randomly chooses one word...
The Acme Trucking company has hired you to write software to help dispatch its trucks. One important element of this software is knowing the distance between any two cities that it services. Design and implement a Distance class that stores the distances between cities in a two-dimensional array. This class contains the following required data members and methods: Required Data Members: String[] cities; //it is used to store city names int[][] distance; // this 2-D array repreents distance between two...
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...
In java write a command-line program that helps to decrypt a message that has been encrypted using a Caesar cipher1. Using this method, a string may contain letters, numbers, and other ASCII characters, but only the letters (upper- and lower-case) are encrypted – a constant number, the shift, is added to the ASCII value of each letter and when letters are shifted beyond ‘z’ or ‘Z’ they are wrapped around (e.g. “Crazy?” becomes “Etcba?” when shifted by 2). When your...