Results 1 to 6 of 6
Thread: Inventory Program
- 05-17-2009, 03:49 AM #1
Member
- Join Date
- Apr 2009
- Location
- I live Stafford Texas right outside of Houston.
- Posts
- 78
- Rep Power
- 0
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
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 03:54 AM. Reason: corrected code tags
- 05-17-2009, 03:58 AM #2
Member
- Join Date
- Apr 2009
- Location
- I live Stafford Texas right outside of Houston.
- Posts
- 78
- Rep Power
- 0
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
- 05-17-2009, 03:59 AM #3
Member
- Join Date
- Apr 2009
- Location
- I live Stafford Texas right outside of Houston.
- Posts
- 78
- Rep Power
- 0
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
-
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 [code] above your pasted code and the tag [/code] below your pasted code like so:
Java Code:[code] // your code goes here // notice how the top and bottom tags are different [/code]
-
Put each class into its own file.
-
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
-
[SOLVED] GUI Inventory Program
By marMcD in forum New To JavaReplies: 5Last Post: 03-03-2009, 06:12 AM -
Help with Errors in Inventory Program
By ljk8950 in forum AWT / SwingReplies: 3Last Post: 08-08-2008, 11:49 PM -
Inventory Program modification help
By badness in forum Java AppletsReplies: 1Last Post: 01-17-2008, 05:24 AM -
Inventory program
By Nexcompac in forum New To JavaReplies: 3Last Post: 07-27-2007, 05:51 PM
Bookmarks