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.>

