This is the code that I have so far. I am using string methods to represent the taco names and double to represent the price. However, I have no clue how to start the array of taco names and prices. I need the array to produce an output that looks like this:
Sorted Tacos are
Taco Prices Crispy Potato Soft Taco 0.99
Taco Prices Crunchy Taco 1.19
Taco Prices Soft Taco 1.19
Taco Prices Doritos Locos Taco (Nacho Cheese) 1.49
Taco Prices Crunchy Taco Supreme 1.59
Taco Prices Soft Taco Supreme 1.59
Taco Prices Chicken Soft Taco 1.79
Taco Prices Double Decker Taco 1.89
Taco Prices Doritos Locs Tacos(Fiery) Supreme 1.89
Taco Prices Double Decker Taco Supreme 2.29
Someone please help.
import java.util.Scanner;
public class TacoSortProgram {
public static void main(String[] args) {
// TODO Auto-generated method stub
//Write a program that sorts prices of 10 tacos in ascending order based on the price, using arrays
System.out.println ("Welcome to the taco price sorter! Enter 10 taco names and prices and I'll sort it!");
Scanner keyboard = new Scanner(System.in);
// System.out.printf("$%4.2f for each %s ", price, item);
// System.out.printf("
The total is: $%4.2f ", total);
//process for item one
System.out.println("Enter the name of taco 1");
String taco = keyboard.nextLine();
System.out.println("Enter taco's price");
double price = Double.parseDouble(keyboard.nextLine());
System.out.println("Enter the name of taco 2");
String taco2 = keyboard.nextLine();
System.out.print("Enter taco's price
");
double price2 = Double.parseDouble(keyboard.nextLine());
System.out.println("Enter the name of taco 3");
String taco3 = keyboard.nextLine();
System.out.println("Enter taco's price");
double price3 = Double.parseDouble(keyboard.nextLine());
System.out.println("Enter the name of taco 4");
String taco4 = keyboard.nextLine();
System.out.println("Enter taco's price");
double price4 = Double.parseDouble(keyboard.nextLine());
System.out.println("Enter the name of taco 5");
String taco5 = keyboard.nextLine();
System.out.print("Enter taco's price
");
double price5 = Double.parseDouble(keyboard.nextLine());
System.out.println("Enter the name of taco 6");
String taco6 = keyboard.nextLine();
System.out.println("Enter taco's price");
double price6 = Double.parseDouble(keyboard.nextLine());
System.out.println("Enter the name of taco 7");
String taco7 = keyboard.nextLine();
System.out.println("Enter taco's price");
double price7 = Double.parseDouble(keyboard.nextLine());
System.out.println("Enter the name of taco 8");
String taco8 = keyboard.nextLine();
System.out.print("Enter taco's price
");
double price8 = Double.parseDouble(keyboard.nextLine());
System.out.println("Enter the name of taco 9");
String taco9 = keyboard.nextLine();
System.out.println("Enter taco's price");
double price9 = Double.parseDouble(keyboard.nextLine());
System.out.println("Enter the name of taco 10");
String taco10 = keyboard.nextLine();
System.out.println("Enter taco's price");
double price10 = Double.parseDouble(keyboard.nextLine());
System.out.println("Sorted tacos are");
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…