Results 1 to 6 of 6
  1. #1
    tlouvierre is offline Member
    Join Date
    Apr 2009
    Location
    I live Stafford Texas right outside of Houston.
    Posts
    78
    Rep Power
    0

    Default Inventory Program

    Java Code:
    import.java.util.Scanner; 
    import java.util.Arrays; 
    import java.util.Collections; 
    
    
    public class Inventory { 
    
    public static void main(String args []) { 
    //create new object 
    DVD mydvd = new DVD(); 
    //create and intialize arrayof products 
    DVD[] prodArray = new DVD[6]; 
    prodArray[0] = new DVD("Action",15,59,22.00); 
    prodArray[1] = new DVD("Westerns",26,68,16.00); 
    prodArray[2] = new DVD("Drama",22, 71, 15.00); 
    prodArray[3] = new DVD("Comedy",33, 50, 19.00); 
    prodArray[4] = new DVD("Sci-Fi",66, 42, 14.00); 
    prodArray[5] = new DVD("Horror",27, 53, 24.00); 
    
    
    //For each array element, output value 
    for (int counter = 0; counter < prodArray.length; counter++ ) 
    
    
    { 
    System.out.println("Item Number: " + prodArray[counter].getitemNum()); 
    System.out.println("Product Name: " + prodArray[counter].getName()); 
    System.out.println("Quantity: " + prodArray[counter].getunits()); 
    System.out.println("Unit Price: " + prodArray[counter].getprice()); 
    System.out.println("Total Value: " + prodArray[counter].getvalue()); 
    System.out.println(); //blank line to seperate products 
    
    
    }//end array output 
    
    
    
    
    } //end main 
    
    } // end class Inventory 
    
    
    
    // Class DVD holds DVD information 
    
    
    import java.util.Locale; 
    import java.text.NumberFormat; 
    
    
    class DVD 
    { 
    public String name; 
    public Integer itemNum; 
    public Integer units; 
    public Double price; 
    //default constructor 
    public DVD() 
    { 
    name = ""; 
    itemNum = 0; 
    units = 0; 
    price = 0.00; 
    }//end default constructor 
    //Parameterized Constructor 
    public DVD(String name, Integer itemNum, Integer units, Double price) 
    { 
    this.name = name; 
    this.itemNum = itemNum; 
    this.units = units; 
    this.price = price; 
    }//end constructor 
    
    //Set product information 
    public void setName(String name) { 
    this.name = name; 
    } 
    public String getName() 
    { 
    return name; 
    
    } 
    
    public void setitemNum ( int itemNum ) 
    { 
    this.itemNum = itemNum; 
    } 
    
    public Integer getitemNum() 
    { 
    return itemNum; 
    } 
    public void setunits ( int units ) 
    { 
    this.units = units; 
    } 
    public Integer getunits() 
    { 
    return units; 
    } 
    public void setprice ( Double price ) 
    { 
    this.price = price; 
    } 
    public Double getprice() 
    { 
    return price; 
    } 
    public Double getvalue() 
    { 
    return (units * price); 
    } 
    
    
    // the compareTo method is used to implement the Comparable interface. This enables us to sort a list of Products using Arrays.sort() 
    // this method returns -1, 0, or 1 depending on if the compared to object should appear before, the same, or after the current item 
    public int compareTo (Object o) 
    { 
    DVD d = (DVD) o; 
    return name.compareTo(getName()); 
    } 
    
    // returns a string representation of the DVD 
    public String toString() 
    { 
    return "DVD Name : " + getName() + " " 
    + "DVD Number : " + getitemNum() + " " 
    + "DVD Price : " + NumberFormat.getCurrencyInstance(Locale.US).format(getprice()) + " " 
    + "Number in Stock : " + getunits() + " " 
    + "Value of inventory : " + NumberFormat.getCurrencyInstance(Locale.US).format(getvalue()); 
    } 
    
    }//end Class DVD
    E:\IT 215 Java Programming\Inventory.java:1: class, interface, or enum expected
    java.util.Scanner;
    ^
    E:\IT 215 Java Programming\Inventory.java:22: not a statement
    for (int counter = 0; counter < prodArray.length; counter++ )
    ^
    E:\IT 215 Java Programming\Inventory.java:22: ')' expected
    for (int counter = 0; counter < prodArray.length; counter++ )
    ^
    E:\IT 215 Java Programming\Inventory.java:22: ';' expected
    for (int counter = 0; counter < prodArray.length; counter++ )
    ^
    E:\IT 215 Java Programming\Inventory.java:48: class, interface, or enum expected
    import java.util.Locale;
    ^
    E:\IT 215 Java Programming\Inventory.java:49: class, interface, or enum expected
    import java.text.NumberFormat;
    ^
    6 errors

    Tool completed with exit code 1

    These are the errors that i am getting. Can you help me solve these problems before Friday of this week.
    Last edited by Fubarable; 05-17-2009 at 04:54 AM. Reason: corrected code tags

  2. #2
    tlouvierre is offline Member
    Join Date
    Apr 2009
    Location
    I live Stafford Texas right outside of Houston.
    Posts
    78
    Rep Power
    0

    Default

    New application with some corrections expect two errors
    import java.util.Scanner;
    import java.util.Arrays;
    import java.util.Collections;


    public class Inventory {

    public static void main(String args []) {
    //create new object
    DVD mydvd = new DVD();
    //create and intialize arrayof products
    DVD[] prodArray = new DVD[6];
    prodArray[0] = new DVD("Action",15,59,22.00);
    prodArray[1] = new DVD("Westerns",26,68,16.00);
    prodArray[2] = new DVD("Drama",22, 71, 15.00);
    prodArray[3] = new DVD("Comedy",33, 50, 19.00);
    prodArray[4] = new DVD("Sci-Fi",66, 42, 14.00);
    prodArray[5] = new DVD("Horror",27, 53, 24.00);


    //For each array element, output value
    for (x = 1; x<10000; counter++ )


    {
    System.out.println("Item Number: " + prodArray[counter].getitemNum());
    System.out.println("Product Name: " + prodArray[counter].getName());
    System.out.println("Quantity: " + prodArray[counter].getunits());
    System.out.println("Unit Price: " + prodArray[counter].getprice());
    System.out.println("Total Value: " + prodArray[counter].getvalue());
    System.out.println(); //blank line to seperate products
    }//end array output
    } //end main

    } // end class Inventory
    // Class DVD holds DVD information
    import java.util.Locale;
    import java.text.NumberFormat;


    class DVD
    {
    public String name;
    public Integer itemNum;
    public Integer units;
    public Double price;
    //default constructor
    public DVD()
    {
    name = "";
    itemNum = 0;
    units = 0;
    price = 0.00;
    }//end default constructor
    //Parameterized Constructor
    public DVD(String name, Integer itemNum, Integer units, Double price)
    {
    this.name = name;
    this.itemNum = itemNum;
    this.units = units;
    this.price = price;
    }//end constructor

    //Set product information
    public void setName(String name) {
    this.name = name;
    }
    public String getName()
    {
    return name;

    }

    public void setitemNum ( int itemNum )
    {
    this.itemNum = itemNum;
    }

    public Integer getitemNum()
    {
    return itemNum;
    }
    public void setunits ( int units )
    {
    this.units = units;
    }
    public Integer getunits()
    {
    return units;
    }
    public void setprice ( Double price )
    {
    this.price = price;
    }
    public Double getprice()
    {
    return price;
    }
    public Double getvalue()
    {
    return (units * price);
    }


    // the compareTo method is used to implement the Comparable interface. This enables us to sort a list of Products using Arrays.sort()
    // this method returns -1, 0, or 1 depending on if the compared to object should appear before, the same, or after the current item
    public int compareTo (Object o)
    {
    DVD d = (DVD) o;
    return name.compareTo(getName());
    }

    // returns a string representation of the DVD
    public String toString()
    {
    return "DVD Name : " + getName() + " "
    + "DVD Number : " + getitemNum() + " "
    + "DVD Price : " + NumberFormat.getCurrencyInstance(Locale.US).format (getprice()) + " "
    + "Number in Stock : " + getunits() + " "
    + "Value of inventory : " + NumberFormat.getCurrencyInstance(Locale.US).format (getvalue());
    }

    }//end Class DVD

  3. #3
    tlouvierre is offline Member
    Join Date
    Apr 2009
    Location
    I live Stafford Texas right outside of Houston.
    Posts
    78
    Rep Power
    0

    Default

    With the second application this is what it says.
    :\IT 215 Java Programming\Inventory.java:37: class, interface, or enum expected
    import java.util.Locale;
    ^
    E:\IT 215 Java Programming\Inventory.java:38: class, interface, or enum expected
    import java.text.NumberFormat;
    ^
    2 errors

    Tool completed with exit code 1

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    when posting code here, you'll want to use correct code tags so that your code will retain its formatting and thus will be readable -- after all, your goal is to get as many people to read your post and understand your code as possible, right?

    To do this, highlight your pasted code (please be sure that it is already formatted when you paste it into the forum; the code tags don't magically format unformatted code) and then press the code button, and your code will have tags.

    Another way to do this is to manually place the tags into your code by placing the tag [cod&#101;] above your pasted code and the tag [/cod&#101;] below your pasted code like so:

    Java Code:
    [cod&#101;]
      // your code goes here
      // notice how the top and bottom tags are different
    [/cod&#101;]
    Also, you've appeared to have corrected the error in your import statement What is your current question?

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    Put each class into its own file.

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    Interesting how this exact same program has made the rounds, several posts months apart. I mean it is word for word the same program. Look here:

    It even has the same question and requires the same answer. Strange.

Similar Threads

  1. [SOLVED] GUI Inventory Program
    By marMcD in forum New To Java
    Replies: 5
    Last Post: 03-03-2009, 07:12 AM
  2. Help with Errors in Inventory Program
    By ljk8950 in forum AWT / Swing
    Replies: 3
    Last Post: 08-09-2008, 12:49 AM
  3. Inventory Program modification help
    By badness in forum Java Applets
    Replies: 1
    Last Post: 01-17-2008, 06:24 AM
  4. Inventory program
    By Nexcompac in forum New To Java
    Replies: 3
    Last Post: 07-27-2007, 06:51 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
  •