Where did I go wrong on this code?
Errors
import javax.swing.*;
import java.util.*;
import java.text.*;
public class CoffeeDriver
{
public static void sortName(Items arr[]) {
Arrays.sort(arr, Items.NAME_ORDER);
String out="";
for(Items item : arr){
out+= item.toString()+"\n";
}
JOptionPane.showMessageDialog(null, out); }
public static void sortPrice(Items arr[]){
Arrays.sort(arr, Items.PRICE_ORDER);
String out="";
for(Items item : arr){
out+= item.toString()+"\n";
}
JOptionPane.showMessageDialog(null, out);
}
public static void main(String []args)
{
String userSorted;
int x;
Items arr[] = new Items[5];
arr[0] = new Items();
arr[0].setItemName("Coffee");
arr[0].setItemPrice(1.00);
arr[1] = new Items();
arr[1].setItemName("Water");
arr[1].setItemPrice(2.00);
arr[2] = new Items();
arr[2].setItemName("Milk");
arr[2].setItemPrice(1.50);
arr[3] = new Items();
arr[3].setItemName("Bagel");
arr[3].setItemPrice(1.25);
arr[4] = new Items();
arr[4].setItemName("Donut");
arr[4].setItemPrice(0.75);
int selectSort;
JOptionPane.showMessageDialog(null, "Welcome to The Coffee Shop!");
userSorted = JOptionPane.showInputDialog(null, "We have a great list items on our menu. Would you like to see these items sorted by name or by price? (n / p)");
selectSort = Integer.parseInt(userSorted);
if (selectSort == n)
sortPrice(arr);
if (selectSort == p)
sortName(arr);
System.exit(0);
}
}
Errors
CoffeeDriver.java:54: error: cannot find symbol if (selectSort == n) ^ symbol: variable n location: class CoffeeDriver CoffeeDriver.java:56: error: cannot find symbol if (selectSort == p) ^ symbol: variable p location: class CoffeeDriver