Results 1 to 4 of 4

Thread: this code is ticking me off

  1. #1
    Join Date
    Feb 2009
    Posts
    96

    this code is ticking me off

    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");
    }
    }
    }

  2. #2
    Join Date
    Dec 2007
    Posts
    1,736

    Re: this code is ticking me off

    what is this code used for? can you be more specific?

  3. #3
    Join Date
    May 2008
    Posts
    3,971

    Re: this code is ticking me off

    Quote Originally Posted by Daren View Post
    can anyone tell me why the code below is full of errors? just when i thought i fixed it i get incompatible types, etc...
    Hello Daren,

    It would be very difficult (or almost impossible) for me to go through your code and find where exactly you are wrong. It would be great if you can provide me the list of error messages (which you got), so that I could manage to explain the correct solution. I hope to hear from you very soon.

  4. #4
    Join Date
    Feb 2009
    Posts
    96

    Re: this code is ticking me off

    its working now ty though i had a friend of mine in the JAVA industry look at it----

    I had declared my initial 2 arrays in the wrong class when they should have been in the main class.

Similar Threads

  1. s5000pal makes a ticking noise and doesnt boot up
    By tomgom999 in forum Motherboard Processor & RAM
    Replies: 5
    Last Post: 24-04-2011, 11:44 PM
  2. Hard Drive ticking noise.
    By Signify in forum Hardware Peripherals
    Replies: 3
    Last Post: 10-04-2011, 11:28 PM
  3. After changing the motherboard my pc does not starts and produces the ticking sound
    By Giselle Knowles in forum Motherboard Processor & RAM
    Replies: 4
    Last Post: 24-11-2010, 03:02 PM
  4. Replies: 3
    Last Post: 22-05-2010, 03:20 PM
  5. Ticking Sound in Intel Core 2 Quad Q9300
    By pragnesh in forum Motherboard Processor & RAM
    Replies: 1
    Last Post: 27-12-2008, 10:59 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,235,351.23715 seconds with 17 queries