Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- String filename = "pizza.txt";
- TextFileReader in = new TextFileReader("src\\leefinalproject\\pizza.txt");
- String line;
- String code = "";
- String linesToWrite = "";
- while (in.hasNext()) {
- line = in.nextLine();
- linesToWrite += line + "\n";
- System.out.println(line);
- switch (line) {
- case "*crusts*":
- code = "*crusts*";
- break;
- case "*sauces*":
- code = "*sauces*";
- break;
- case "*toppings*":
- code = "*toppings*";
- break;
- case "*cheeses*":
- code = "*cheeses*";
- break;
- case "*pizzas*":
- code = "*pizzas*";
- break;
- default:
- StringTokenizer st = new StringTokenizer(line, ",");
- String name = st.nextToken();
- double price = Double.parseDouble(st.nextToken());
- String desc = st.nextToken();
- if (code.equals("*crusts*")) {
- Crust newCrust = new Crust(name, price, desc);
- crusts.add(newCrust);
- } else if (code.equals("*sauces*")) {
- Sauce newSauce = new Sauce(name, price, desc);
- sauces.add(newSauce);
- } else if (code.equals("*toppings*")) {
- Topping newTopping = new Topping(name, price, desc);
- toppings.add(newTopping);
- } else if (code.equals("*cheeses*")) {
- Cheese newCheese = new Cheese(name, price, desc);
- cheeses.add(newCheese);
- } else if (code.equals("*pizzas*")) {
- Pizza newPizza = new Pizza(name, price, desc);
- pizzas.add(newPizza);
- }
- }
- }
- in.close();
- TextFileWriter out = new TextFileWriter("out.txt");
- out.write(linesToWrite);
- out.close();
- initComponents();
- }
- // Convert arrayList into an array for a dropdown menu
- String[] convertToArray(ArrayList<Pizza> list) {
- // Get the size of the ArrayList.
- int size = list.size();
- // Create the new array of strings to be displayed.
- String[] arr = new String[size];
- // Iterate over all of the items in the list, and add their names and
- // prices to the new array.
- for (int i = 0; i < size; i++) {
- String twoDeciPlaces = String.format("%.02f", list.get(i).price);
- arr[i] = list.get(i).name + " $" + twoDeciPlaces;
- }
- return arr;
- }
- // Convert arrayList into an array for a dropdown menu
- String[] convertToArrayCrust(ArrayList<Crust> list) {
- // Get the size of the ArrayList.
- int size = list.size();
- // Create the new array of strings to be displayed.
- String[] arr = new String[size];
- // Iterate over all of the items in the list, and add their names and
- // prices to the new array.
- for (int i = 0; i < size; i++) {
- String twoDeciPlaces = String.format("%.02f", list.get(i).price);
- arr[i] = list.get(i).name + " $" + twoDeciPlaces;
- }
- return arr;
- }
- String[] convertToArraySauce(ArrayList<Sauce> list) {
- // Get the size of the ArrayList.
- int size = list.size();
- // Create the new array of strings to be displayed.
- String[] arr = new String[size];
- // Iterate over all of the items in the list, and add their names and
- // prices to the new array.
- for (int i = 0; i < size; i++) {
- String twoDeciPlaces = String.format("%.02f", list.get(i).price);
- arr[i] = list.get(i).name + " $" + twoDeciPlaces;
- }
- return arr;
- }
- String[] convertToArrayCheese(ArrayList<Cheese> list) {
- // Get the size of the ArrayList.
- int size = list.size();
- // Create the new array of strings to be displayed.
- String[] arr = new String[size];
- // Iterate over all of the items in the list, and add their names and
- // prices to the new array.
- for (int i = 0; i < size; i++) {
- String twoDeciPlaces = String.format("%.02f", list.get(i).price);
- arr[i] = list.get(i).name + " $" + twoDeciPlaces;
- }
- return arr;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement