got rid of all errors but it will not print what it is suposed to it runs and prints out
Welcome to Coffee Driver! Do you want to see our menu sorted by item name or price?/nEnter 'p' for price and 'n' for item name:
p
null $0.0
null $0.0
null $0.0
null $0.0
null $0.0
null $0.0
null $0.0
null $0.0
null $0.0
null $0.0
null $0.0
null $0.0
null $0.0
null $0.0
here are my codes
///"ITEM.JAVA"
public class Item{
//delcare instance fields
private String itemName;
private double itemPrice;
//declare constructor
public Item(String itemName){
itemName = itemName;
}
public Item(double itemPrice){
itemPrice = itemPrice;
}
//delcare setters
public void setItemName (String itemName){
itemName = itemName;
}
public void setItemPrice (double itemPrice){
itemPrice = itemPrice;
}
//declare getters
public String getItemName(){
return itemName;
}
public double getItemPrice(){
return itemPrice;
}
}//ends class
////"COFFEEDRIVER.JAVA"
import java.util.*;
public class CoffeeDriver{
public static void main(String[] args){
Scanner keyboard = new Scanner(System.in);
Item[] item = new Item[5];
Item[] price = new Item[5];
String answer;
String itemName;
double itemPrice;
//load array
item[0] = new Item("Coffee");
item[1] = new Item("Water");
item[2] = new Item("Milk");
item[3] = new Item("Bagel");
item[4] = new Item("Donut");
price[0] = new Item(1.00);
price[1] = new Item(2.00);
price[2] = new Item(1.50);
price[3] = new Item(1.25);
price[4] = new Item(0.75);
//get user input
System.out.println("Welcome to Coffee Driver! Do you want to see our menu sorted by item name or price?" +
"/nEnter 'p' for price and 'n' for item name: ");
answer = keyboard.nextLine();
if(answer.equalsIgnoreCase("p")){
sortPrice(item);
displayItems(item);
} else {
displayItems(item);
}//ends if..else
displayItems(item);
sortPrice(item);
displayItems(item);
}//ends main
public static void sortPrice(Item[] p){
Item temp;
for(int a = 0; a < p.length-1; a++){
for(int b = 0; b < p.length-1; b++){
if(p[b].getItemPrice() >= p[b+1].getItemPrice()){
temp=p[b];
p[b]=p[b+1];
p[b+1]=temp;
}//end if
}//end for
}//end for
}//end sortUnits method
public static void displayItems(Item[] n){
for(int i=0; i < n.length; i++){
System.out.println(n[i].getItemName() + "\t" + "$" + n[i].getItemPrice());
System.out.println();
}//end for
}//end displayItems method
}//ends class