Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 12-03-2009
Member
 
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");
}
}
}
Reply With Quote
  #2  
Old 12-03-2009
Member
 
Join Date: Dec 2007
Posts: 1,728
Re: this code is ticking me off

what is this code used for? can you be more specific?
Reply With Quote
  #3  
Old 12-03-2009
Member
 
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.
Reply With Quote
  #4  
Old 13-03-2009
Member
 
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.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags:



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "this code is ticking me off"
Thread Thread Starter Forum Replies Last Post
s5000pal makes a ticking noise and doesnt boot up tomgom999 Motherboard Processor & RAM 5 24-04-2011 11:44 PM
Hard Drive ticking noise. Signify Hardware Peripherals 3 10-04-2011 11:28 PM
After changing the motherboard my pc does not starts and produces the ticking sound Giselle Knowles Motherboard Processor & RAM 4 24-11-2010 03:02 PM
Clicking/Ticking noise while iMac is sleep mode or turned off?! Brandon67 Portable Devices 3 22-05-2010 03:20 PM
Ticking Sound in Intel Core 2 Quad Q9300 pragnesh Motherboard Processor & RAM 1 27-12-2008 10:59 PM


All times are GMT +5.5. The time now is 03:05 PM.