Help, still trying to get the basics of Java

OK, I'm still trying to figure out the basics and on this program decided to write small amounts of code at a time and compile them so I could learn where I was making the mistakes. I keep getting stuckI am getting 5 cannot find symbols on the following code. I've made sure I have imported the Scanner class, checked my brackets, but can't figure out why it is still giving these errors. Can you please help? Why will it not recognize "input"?

import java.util.Scanner;

publicclass Inventory

{

publicstaticvoid main( String args[] )

{

String productNum ="";

String name ="";

int units = 0;

double amount = 0;

Scanner scan =new Scanner( System.in );

System.out.println ("Please enter product #" );

productNum = input.next();

System.out.println ("Please enter color name" );

name = input.next();

System.out.println ("Please enter units on hand" );

units = input.nextInt();

System.out.println ("Please enter dollar amount for each unit" );

amount = input.nextDouble();

System.out.println (productNum, name, units, amount);

}

}

[1722 byte] By [Back2Schoola] at [2007-11-26 23:40:44]
# 1
You haven't declared a variable called input! You have declared one called scan though.
floundera at 2007-7-11 15:07:38 > top of Java-index,Java Essentials,New To Java...
# 2
Also, the println method accepts a single parameter, not a comma separated list.
floundera at 2007-7-11 15:07:38 > top of Java-index,Java Essentials,New To Java...
# 3
Instead of that non-working println, try [url= http://java.sun.com/javase/6/docs/api/java/io/PrintStream.html#format(java.lang.String,%20java.lang.Object...)]format[/url].
DrLaszloJamfa at 2007-7-11 15:07:38 > top of Java-index,Java Essentials,New To Java...
# 4
Da-ding. And the light comes on. Ok the input thing was it. You're the bomb!!!! Thanks.
Back2Schoola at 2007-7-11 15:07:38 > top of Java-index,Java Essentials,New To Java...
# 5

Ok, I am just using this line to test my input, but I like this feature. How do I use it properly though? I put this in as System.out.format(String productNum, String name, int units, double amount); and it several errors...I first typed it in without the types and it simply printed off the first variable...where am I going wrong?

Denise

Back2Schoola at 2007-7-11 15:07:38 > top of Java-index,Java Essentials,New To Java...
# 6

TryString outputStr = String.format(

"%s %s %d %.2f",

productNum, name, units, amount);

System.out.println(outputStr);

// or, the equivalent

System.out.printf("%s %s %d %.2f%n", productNum, name, units, amount);

Check the String API documentation for format() and the java.util.Formatter

documentation for how the format strings work. They take a bit of getting used to.

pbrockway2a at 2007-7-11 15:07:38 > top of Java-index,Java Essentials,New To Java...
# 7

OK, I have 2 classes. In my second class, I have created an object. I want to use a method call to an object from my first class that will add productNum, name, units and amount) . Would this be the correct statement...(Sorry, I do not know how to test variables in second class when I can't get the main class to run).

AlbumInventory.addAlbum(productNum, name, units, amount);

I then want to print a list using the toString report from the second class. I am a little confused...how do I call the toString back into my first class(that has the main).

Denise Comer

Thanks

Back2Schoola at 2007-7-11 15:07:38 > top of Java-index,Java Essentials,New To Java...
# 8

With the above, I am getting this error, can anyone tell me why?

Inventory.java:15: cannot find symbol

symbol : class Albuminventory

location: class Inventory

Albuminventory scrapbook = new AlbumInventory ();

I am trying to create this to send a report back to with

Back2Schoola at 2007-7-11 15:07:38 > top of Java-index,Java Essentials,New To Java...
# 9

> Albuminventory scrapbook = new AlbumInventory ();

It looks like Albuminventory should be AlbumInventory.

The description of your problem is not all that clear. Some code would

help.

It's a good idea to do one small thing at a time, making sure the

program compiles at each step. What you are doing with each class,

and with each method of each class should be documented in the

code.

pbrockway2a at 2007-7-11 15:07:38 > top of Java-index,Java Essentials,New To Java...
# 10

Doesn't it not mean that your AlbumInventory class does not define a constructor that takes zero arguments?

e.g

public class AlbumInventory {

public static void main(String [] args) {

AlbumInventory brokenInventory = new AlbumInventory(); // This will produce compile error

AlbumInventory workingInventory = new AlbumInventory(5098) // This will compile

}

private int id;

public AlbumInventory (int id) {

this.id = id;

}

}

JonlWrighta at 2007-7-11 15:07:38 > top of Java-index,Java Essentials,New To Java...
# 11
> Doesn't it not mean that your AlbumInventory class does not define a > constructor that takes zero arguments?I would have thought it means that the symboladdinventory^|i not Icannot be found.
pbrockway2a at 2007-7-11 15:07:38 > top of Java-index,Java Essentials,New To Java...