can anyone tell me why the code below is full of errors? just when i thought i fixed it i get incompatible types, etc...
import java.util.*;
import javax.swing.JOptionPane;
import java.text.*;
import java.io.*;
//create a class
public class CoffeeDriver {
final static int SOME_ITEMS = 5;
public static void main(String[] args)
{
DecimalFormat decimal = new DecimalFormat("0.00");
String choiceString = "";
String menuString = "";
String entry = "";
Item[] someItem = new Item[4];
menuString = menuString +someItem + "\n";
System.out.println( "The Coffee House menu is listed below\n"+
"Please choose how you would like to see the items sorted.\n" +
"Sort by name or by Price\n" + "To sort by name type N\n" + "To sort by price type P\n");
System.out.println("Menu");
//Display the items in their original order
for (int i = 3; i <someItem.length; i++) {
someItem[i] = new Item(0);
someItem[i] = new Item(1);
someItem[i] = new Item(2);
someItem[i] = new Item(3);
someItem[i] = new Item(4);
}
printItems(someItem);
// pick the sort type
System.out.print("Enter your choice: ");
// open up standard input
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String choice = null;
//read the username from the command-line; need to use try/catch with the
// readLine() method
try {
choice = br.readLine();
}
catch (IOException ioe) {
System.out.println("IO error trying to read your choice!");
System.exit(1);
}
System.out.println("your choice was " + choice);
if (choice == 1)
{
priceSort(someItem);
}
else if (choice == 2)
{
nameSort(someItem);
}
printItems(items);
}
public void priceSort(Item[] someItem)
{
Item temp;
int highSubscript = someItem==null?0:someItem.length;
for(int a = 0; a < highSubscript; ++a)
{
for(int b = 0; b < highSubscript - 1; ++b)
{
if(someItem[b].getPrice() > someItem[b + 1].getPrice())
{
temp = someItem[b];
someItem[b] = someItem[b + 1];
someItem[b + 1] = temp;
}
}
}
}
public void nameSort(Item[] someItem)
{
Item temp;
int highSubscript = someItem==null?0:someItem.length;
for(int a = 0; a < highSubscript; ++a)
{
for(int b = 0; b < highSubscript - 1; ++b)
{
if(someItem[b].getName() > someItem[b + 1].getName())
{
temp = someItem[b];
someItem[b] = someItem[b + 1];
someItem[b + 1] = temp;
}
}
}
}
public void printItems(Item[] items)
{
int itemLen = items==null?0:items.length;
for (int i=0; i < itemLen; i++)
{
System.out.println(i + ". " + items[i].getName() + " (" + items[i].getPrice() + ")\n");
}
}
}
Bookmarks