I also need help with a programming assingment. I think I'm almost there!

I have the following assingment to complete:Once again, you realize that you need to upgrade your Java program with two more features:

Be able to print products which are 揙n Sale?

Use arrays to store the product names so that you can keep track of your inventory.

After some analysis, you notice that printing the products can be achieved by modifying the two classes you have already written. One approach would be to add a Boolean attribute called 揙nSale?to the ToddlerToy and add a print method that print information about a product indicating if it is 揙n Sale?

Update your constructor, taking into account the 揙n Sale?attribute.

Create two more instances: a small train called Train4 and a big train called Train5. Mark both trains 揙n Sale?

Add another method that prints the sale information

Keeping track of the names of products can be achieved by declaring an array of strings in the ToysManager class itself. Each time a new product is created, it is also added to the array. Use a while construct to print the product names in your inventory.

This is the code I have come up with:

public class ToysManager {

private String toyInventory[] = {"Big Train","Small Train"};

public void printInventory() {

System.out.println("List of Items in Toy Inventory");

for (int i=0; i<toyInventory.length; i++)

{ System.out.println(toyInventory)); } // ";"expected - ToysManager.java

}

public static void main(String[] args) {

//System.out.println("This is the main method of class ToysManager.");

//call on ToysManager printInventory method for a listing of all toy types

printInventory();

//

// Create ToddlerToy Objects Train1,Train2,Train3,Train4,Train5

//

ToddlerToy Train1 = new ToddlerToy(489, "Big Train", 19.95,false);

Train1.printOnSale();

ToddlerToy Train2 = new ToddlerToy(489, "Big Train", 19.95,false);

Train2.printOnSale();

ToddlerToy Train3 = new ToddlerToy(477, "Small Train", 12.95,false);

Train3.printOnSale();

ToddlerToy Train4 = new ToddlerToy(477, "Small Train", 12.95,true);

Train4.printOnSale();

ToddlerToy Train5 = new ToddlerToy(489, "Big Train", 19.95,true);

Train5.printOnSale();

}//this is the end bracket for the main method

}//this is the end bracket for the ToysManager class

class ToddlerToy {

//

// Initialize and Assign Data Types to each Variables

//

private int productID;

public String productName;

public double productPrice;

private boolean onSale;

public void ToddlerToy(int a, String b, double c, boolean d) {

//

// Assign Data to Variables

//

productID = a;

productName = b;

productPrice = c;

onSale = d;

//PrintProductPrice(ProductPrice);

} //end of constructor

public void printOnSale(){

if(onSale == true) System.out.println("This item #" + productID + ": " + productName + "is on sale");

}

}

I don't have any problems with class ToddlerToy. I can compile that with no problems. I'm having issues with public class ToysManager. I can't compile that one correctly. It fails at:

{ System.out.println(toyInventory)); } // ";"expected - ToysManager.java

I've looked through the java books I have and also online, but I can't figure this out. I'm new to java so any help would be appreciated.

Thanks in advance.>

[3550 byte] By [Hoss60a] at [2007-10-2 22:13:17]
# 1

should be

for (int i=0; i<toyInventory.length; i++) {

System.out.println(toyInventory); // you wrote 1 bracket more

}

>

maf69a at 2007-7-14 1:30:07 > top of Java-index,Java Essentials,Java Programming...
# 2

Thanks. That got me past that error. I was hung up on that for far too long. I made some changes and when i compile the ToysManager class it shoots a different error. The code now looks like this:

public class ToysManager {

private String toyInventory[] = {"Big Train","Small Train"};

public void printInventory() {

System.out.println("List of Items in Toy Inventory");

for (int i=0; i<toyInventory.length; i++){

System.out.println(toyInventory);

}

public static void main(String[] args) {

//System.out.println("This is the main method of class ToysManager.");

//call on ToysManager printInventory method for a listing of all toy types

printInventory();

//

// Create ToddlerToy Objects Train1,Train2,Train3,Train4,Train5

//

ToddlerToy Train1 = new ToddlerToy(489, "Big Train", 19.95,false);

Train1.printOnSale();

ToddlerToy Train2 = new ToddlerToy(489, "Big Train", 19.95,false);

Train2.printOnSale();

ToddlerToy Train3 = new ToddlerToy(477, "Small Train", 12.95,false);

Train3.printOnSale();

ToddlerToy Train4 = new ToddlerToy(477, "Small Train", 12.95,true);

Train4.printOnSale();

ToddlerToy Train5 = new ToddlerToy(489, "Big Train", 19.95,true);

Train5.printOnSale();

}//this is the end bracket for the main method

}

}//this is the end bracket for the ToysManager class

I get an illegal start of expression for:

public static void main(String[] args) {

and ";" expected for:

}//this is the end bracket for the main method

I looked over my initial code, before the "for" loop?, and the public static void main was a valid statement.>

Hoss60a at 2007-7-14 1:30:07 > top of Java-index,Java Essentials,Java Programming...
# 3

> public void printInventory() {

> System.out.println("List of Items in Toy Inventory");

> for (int i=0; i<toyInventory.length; i++){

> System.out.println(toyInventory);

> }

Count your curly brackets; you forgot one here just before 'main'

is defined:

> public static void main(String[] args) {

kind regards,

Jos

JosAHa at 2007-7-14 1:30:07 > top of Java-index,Java Essentials,Java Programming...
# 4
Thanks for the info. This cleared up that particular error but caused more errors. I was able to figure it out from that point on. My code is complete and working now. Thanks to those who helped.
Hoss60a at 2007-7-14 1:30:07 > top of Java-index,Java Essentials,Java Programming...