Results 1 to 4 of 4
  1. #1
    Nexcompac is offline Member
    Join Date
    Jul 2007
    Posts
    5
    Rep Power
    0

    Default Inventory program

    Still getting used to the whole java world and I am trying to compile a program using TextPad. Here is what I have so far.

    Java Code:
    /*
     * Main.java
     *
     * Created on July 19, 2007, 5:54 PM
     *
     * To change this template, choose Tools | Template Manager
     * and open the template in the editor.
     *
     *List item number, product name, quantity, price per unit, value of product, and total value of inventory.
     */
    
    
    import java.util.Scanner;//program uses class Scanner
    
    //ShowInventory program
    public class ShowInventory
    
    { //main method begins execution of java application
    	public static void main (String args[])
    		{
    			Scanner myScanner = new Scanner (System.in);
    
    			//item name variable
    			String itemName1 = cd;//item name for inventory of music cd
    			String itemName2 = dvd;//item name for inventory of video media
    			String itemName3 = book;//item name for inventory of printed media
    
    			//item code variable
    			int code1 = 1000;//item code assigned to music cds
    			int code2 = 2000;//item code assigned to video media
    			int code3 = 3000;//item code assigned to printed media
    
    			//item quantity variable
    			int quantity1 = 15;//number of music cds on-hand
    			int quantity2 = 11;//number of video media on-hand
    			int quantity3 = 27;//number of printed media on-hand
    
    			//price of media variable
    			double price1 = 14.99;//assigned price of music cd
    			double price2 = 19.99;//assigned price of video media
    			double price3 = 12.99;//assigned price of printed media
    
    
    			//cd
    
    			class CD
    			{
    			  private String name;
    			  private int itemCode;
    			  private int itemQuantity;
    			  private double itemPrice;
    
    			  //constructor to initialize the item with the information provided
    			  public CD(String name, int itemCode, int itemQuantity, double itemPrice)
    			  {
    			  	setName(name);
    			  	setItemCode(itemCode);
    			  	setItemQuantity(itemQuantity);
    			  	setItemPrice(itemPrice);
    			  }
    
    			  //get item name
    			  public String getName()
    			  {
    			  	return this.name;
    			  }
    
    			  //set item name
    			  private void setName(String name)
    			  {
    			  	this.name = name;
    			  }
    
    			  //set item code
    			  private void setItemCode(int itemCode)
    			  {
    			  	this.itemCode = itemCode;
    			  }
    
    			  //set item quantity
    			  private void setItemQuantity(int itemQuantity)
    			  {
    			  	this.itemQuantity = itemQuantity;
    			  }
    
    			  //set price of item
    			  private void setItemPrice (double itemPrice)
    			  {
    			  	this.itemPrice = itemPrice;
    			  }
    
    			  //calculate value of item on-hand
    			  public double getItemValue()
    			  {
    			  	return this.itemQuantity * this.itemPrice;
    			  }
    
    
    			//DVD
    			class DVD
    			{
    			  private String name;
    			  private int itemCode;
    			  private int itemQuantity;
    			  private double itemPrice;
    
    			  //constructor to initialize the item with the information provided
    			  public DVD(String name, int itemCode, int itemQuantity, double itemPrice)
    			  {
    			  	setName(name);
    			  	setItemCode(itemCode);
    			  	setItemQuantity(itemQuantity);
    			  	setItemPrice(itemPrice);
    			  }
    
    			  //get item name
    			  public String getName()
    			  {
    			  	return this.name;
    			  }
    
    			  //set item name
    			  private void setName(String name)
    			  {
    			  	this.name = name;
    			  }
    
    			  //set item code
    			  private void setItemCode(int itemCode)
    			  {
    			  	this.itemCode = itemCode;
    			  }
    
    			  //set item quantity
    			  private void setItemQuantity(int itemQuantity)
    			  {
    			  	this.itemQuantity = itemQuantity;
    			  }
    
    			  //set price of item
    			  private void setItemPrice (double itemPrice)
    			  {
    			  	this.itemPrice = itemPrice;
    			  }
    
    			  //calculate value of item on-hand
    			  public double getItemValue()
    			  {
    			  	return this.itemQuantity * this.itemPrice;
    			  }
    
    			//book
    			class Book
    			{
    			  private String name;
    			  private int itemCode;
    			  private int itemQuantity;
    			  private double itemPrice;
    
    			  //constructor to initialize the item with the information provided
    			  public Book(String name, int itemCode, int itemQuantity, double itemPrice)
    			  {
    			  	setName(name);
    			  	setItemCode(itemCode);
    			  	setItemQuantity(itemQuantity);
    			  	setItemPrice(itemPrice);
    			  }
    
    			  //get item name
    			  public String getName()
    			  {
    			  	return this.name;
    			  }
    
    			  //set item name
    			  private void setName(String name)
    			  {
    			  	this.name = name;
    			  }
    
    			  //set item code
    			  private void setItemCode(int itemCode)
    			  {
    			  	this.itemCode = itemCode;
    			  }
    
    			  //set item quantity
    			  private void setItemQuantity(int itemQuantity)
    			  {
    			  	this.itemQuantity = itemQuantity;
    			  }
    
    			  //set price of item
    			  private void setItemPrice (double itemPrice)
    			  {
    			  	this.itemPrice = itemPrice;
    			  }
    
    			  //calculate value of item on-hand
    			  public double getItemValue()
    			  {
    			  	return this.itemQuantity * this.itemPrice;
    			  }
    
    			  //calculate combined value of all inventory
    			  double inventoryValue = cdItemPrice + dvdItemPrice + bookItemPrice;
    
    
    
    			  //build array to house data
    			  //InitInventory.java
    		public class InitInventory
    
    		//initializer list specifies the value for each element
    		{
    		 String inventory[] = {CD, DVD, Book};
    		 int itemcode [] = {1000, 2000, 3000};
    		 int itemquantity [] = {15,11,27};
    		 double itemprice [] = {14.99, 19.99, 12.99};
    		 double itemvalue [] = {15*14.99, 11*19.99, 27*12.99};
    
    		 System.out.printf("%s&s\n", "Index", "Value");//column headings
    
    		 //output each array elements value
    		 for (String counter = 0; counter < array.length; counter ++)
    		 	System.out.printf("%5d%8d\n", counter, array[counter]);
    
    		 for (int counter = 0; counter < array.length; counter ++)
    		 	System.out.printf("%5d%8d\n", counter, array[counter]);
    
    		 for (double counter = 0; counter < array.length; counter ++)
    		 	System.out.printf("%5d%8d\n", counter, array[counter]);
    		 }//end class InitInventory
    
    	}//end main
    
    
    }//end ShowInventory

    Now I seem to be getting 18 errors. Which sucks. Here are the errors.

    Here are the errors in more detail.

    Java Code:
    C:\Users\Brian\Documents\ShowInventory.java:222: <identifier> expected
    		 System.out.printf("%s&s\n", "Index", "Value");//column headings
    		                  ^
    C:\Users\Brian\Documents\ShowInventory.java:222: illegal start of type
    		 System.out.printf("%s&s\n", "Index", "Value");//column headings
    		                   ^
    C:\Users\Brian\Documents\ShowInventory.java:225: illegal start of type
    		 for (String counter = 0; counter < array.length; counter ++)
    		 ^
    C:\Users\Brian\Documents\ShowInventory.java:225: > expected
    		 for (String counter = 0; counter < array.length; counter ++)
    		                                                ^
    C:\Users\Brian\Documents\ShowInventory.java:225: <identifier> expected
    		 for (String counter = 0; counter < array.length; counter ++)
    		                                                         ^
    C:\Users\Brian\Documents\ShowInventory.java:226: <identifier> expected
    		 	System.out.printf("%5d%8d\n", counter, array[counter]);
    		 	                 ^
    C:\Users\Brian\Documents\ShowInventory.java:226: illegal start of type
    		 	System.out.printf("%5d%8d\n", counter, array[counter]);
    		 	                  ^
    C:\Users\Brian\Documents\ShowInventory.java:228: illegal start of type
    		 for (int counter = 0; counter < array.length; counter ++)
    		 ^
    C:\Users\Brian\Documents\ShowInventory.java:228: > expected
    		 for (int counter = 0; counter < array.length; counter ++)
    		                                             ^
    C:\Users\Brian\Documents\ShowInventory.java:228: <identifier> expected
    		 for (int counter = 0; counter < array.length; counter ++)
    		                                                      ^
    C:\Users\Brian\Documents\ShowInventory.java:229: <identifier> expected
    		 	System.out.printf("%5d%8d\n", counter, array[counter]);
    		 	                 ^
    C:\Users\Brian\Documents\ShowInventory.java:229: illegal start of type
    		 	System.out.printf("%5d%8d\n", counter, array[counter]);
    		 	                  ^
    C:\Users\Brian\Documents\ShowInventory.java:231: illegal start of type
    		 for (double counter = 0; counter < array.length; counter ++)
    		 ^
    C:\Users\Brian\Documents\ShowInventory.java:231: > expected
    		 for (double counter = 0; counter < array.length; counter ++)
    		                                                ^
    C:\Users\Brian\Documents\ShowInventory.java:231: <identifier> expected
    		 for (double counter = 0; counter < array.length; counter ++)
    		                                                         ^
    C:\Users\Brian\Documents\ShowInventory.java:232: <identifier> expected
    		 	System.out.printf("%5d%8d\n", counter, array[counter]);
    		 	                 ^
    C:\Users\Brian\Documents\ShowInventory.java:232: illegal start of type
    		 	System.out.printf("%5d%8d\n", counter, array[counter]);
    		 	                  ^
    C:\Users\Brian\Documents\ShowInventory.java:238: reached end of file while parsing
    }//end ShowInventory
     ^
    18 errors
    
    Tool completed with exit code 1
    Any help would be welcome :confused:

  2. #2
    levent Guest

    Default

    As far as i know, the method was not System.out.printf. It was System.out.println?

  3. #3
    Nexcompac is offline Member
    Join Date
    Jul 2007
    Posts
    5
    Rep Power
    0

    Default

    Quote Originally Posted by levent View Post
    As far as i know, the method was not System.out.printf. It was System.out.println?
    Where can I go to get the key words to define what I want specificly?

    I will try changing that up and see what results. Thanks

  4. #4
    levent Guest

    Default

    Where can I go to get the key words to define what I want specificly?
    As far as i understand what you said, you are looking for javadoc of Java SE. You can find it here. It will give you which classes you can use and which methods these classes have in addition to brief descriptions of them.

Similar Threads

  1. Final Inventory tweeks
    By badness in forum New To Java
    Replies: 1
    Last Post: 01-20-2008, 09:18 AM
  2. Inventory Program modification help
    By badness in forum Java Applets
    Replies: 1
    Last Post: 01-17-2008, 06:24 AM
  3. Inventory part 3 program problems
    By badness in forum New To Java
    Replies: 1
    Last Post: 12-17-2007, 08:00 AM
  4. Inventory part 2 help please
    By badness in forum New To Java
    Replies: 1
    Last Post: 12-12-2007, 08:51 AM
  5. Replies: 0
    Last Post: 10-04-2007, 10:33 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •