

-----------------------------------

fandanstan

Wed Jan 16, 2008 12:35 am


User Input

-----------------------------------

Ok, so i'm doing this project for my Comp Sci class.  Our teacher hasn't taught us anything, and he expects us to know how to do this.  Anyways, i need help on getting the user to input something, and it displays on the screen.  I finally found out how to input numbers and stuff, but when you input a number, i want that number that corresponds with the product to show up with its price.  This is what i have so far:

public class Final_Project
{
	public static void main (String


-----------------------------------

syntax_error

Wed Jan 16, 2008 12:43 am


Re: User Input

-----------------------------------

the wind whispers can you hear it
it says use the case structure ... then its gone...


Edit: it also tell me more... code tags... and stop blaming your problems on your teacher ... the internet is here to help....


-----------------------------------

OneOffDriveByPoster

Wed Jan 16, 2008 9:51 am


Re: User Input

-----------------------------------

use the case structure ...You can use an array too (just check the input first).


-----------------------------------

HeavenAgain

Wed Jan 16, 2008 11:33 am


RE:User Input

-----------------------------------

i believe this man here is asking how to get input, not how to "check" what input, however it will help
and for getting input, i can suggest you to something simple, using the Scanner class, heres an example

import java.util.Scanner;
public class Test
{
 public static void main(String[] args)
  {
   Scanner input = new Scanner (System.in);
   String line = input.nextLine();
   int number = input.nextInt();
   System.out.println(line+number);
   }
}


-----------------------------------

fandanstan

Fri Jan 18, 2008 6:59 pm


Re: User Input

-----------------------------------

Ok, i've used that code, i'm kinda a newb at this.  Say, for example if the user inputted the number 1, how would i make it so that the first product is shown?


import java.util.Scanner;
import java.io.*;
public class Final_Project
{
	public static void main (String str


-----------------------------------

syntax_error

Fri Jan 18, 2008 7:33 pm


Re: User Input

-----------------------------------

err why are you using  BufferedReader?/
you already have a scanner dont you dont need the  BufferedReader


import java.util.Scanner;
//import java.io.*;
public class FinalProject// dont use underscores 
{
public static void main (String str


-----------------------------------

HeavenAgain

Fri Jan 18, 2008 7:35 pm


RE:User Input

-----------------------------------

sigh....
have you even tried out the code? as you can see, when you declear a Scanner class, and use nextInt() method, you can get the integer input from the user
and after that is just simple if statement and how come in your code, you have " BufferedReader read=new BufferedReader(new InputStreamReader(System.in)); " AND Scanner? they are both inputs..... you only need 1....
and please, dont tell me you dont know how to use if statement in java, because this is your "final_project" afterall....

or you can do the array way, all you need is 2 parallel array for the price, and the item, it will save the if statements.... but go with the easy method first....  :?

