Hello everyone. I am new to java and new to this forum. I am having troubles with finishing this program. I am getting the following errors when trying to compile the program:
"Line 276: <identifier> expected
Line 334: reached end of file while parsing"
I am using a program called JCreatorLE workspace. Here is the code:
[code=java]
/*W6D4:ShowInven tory.java
*
* Mike McGrady, May 17, 2007, 6:00 pm
*
* List item number, product name, quantity, price per unit, value of product, and total value of inventory.
*/
import java.util.Scann er;//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(ite mCode);
setItemQuantity (itemQuantity);
setItemPrice(it emPrice);
}
//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.itemQuanti ty = itemQuantity;
}
//set price of item
private void setItemPrice (double itemPrice)
{
this.itemPrice = itemPrice;
}
//calculate value of item on-hand
public double getItemValue()
{
return this.itemQuanti ty * 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(ite mCode);
setItemQuantity (itemQuantity);
setItemPrice(it emPrice);
}
//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.itemQuanti ty = itemQuantity;
}
//set price of item
private void setItemPrice (double itemPrice)
{
this.itemPrice = itemPrice;
}
//calculate value of item on-hand
public double getItemValue()
{
return this.itemQuanti ty * 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(ite mCode);
setItemQuantity (itemQuantity);
setItemPrice(it emPrice);
}
//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.itemQuanti ty = itemQuantity;
}
//set price of item
private void setItemPrice (double itemPrice)
{
this.itemPrice = itemPrice;
}
//calculate value of item on-hand
public double getItemValue()
{
return this.itemQuanti ty * this.itemPrice;
}
//calculate combined value of all inventory
double inventoryValue = cdItemPrice + dvdItemPrice + bookItemPrice;
//build array to house data
//InitInventory.j ava
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.prin tf("%s&s\n", "Index", "Value");//column headings
//output each array elements value
for (String counter = 0; counter < array.length; counter ++)
System.out.prin tf("%5d%8d\n", counter, array[counter]);
for (int counter = 0; counter < array.length; counter ++)
System.out.prin tf("%5d%8d\n", counter, array[counter]);
for (double counter = 0; counter < array.length; counter ++)
System.out.prin tf("%5d%8d\n", counter, array[counter]);
}//end class InitInventory
}//end main
}//end ShowInventory
[/code]
"Line 276: <identifier> expected
Line 334: reached end of file while parsing"
I am using a program called JCreatorLE workspace. Here is the code:
[code=java]
/*W6D4:ShowInven tory.java
*
* Mike McGrady, May 17, 2007, 6:00 pm
*
* List item number, product name, quantity, price per unit, value of product, and total value of inventory.
*/
import java.util.Scann er;//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(ite mCode);
setItemQuantity (itemQuantity);
setItemPrice(it emPrice);
}
//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.itemQuanti ty = itemQuantity;
}
//set price of item
private void setItemPrice (double itemPrice)
{
this.itemPrice = itemPrice;
}
//calculate value of item on-hand
public double getItemValue()
{
return this.itemQuanti ty * 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(ite mCode);
setItemQuantity (itemQuantity);
setItemPrice(it emPrice);
}
//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.itemQuanti ty = itemQuantity;
}
//set price of item
private void setItemPrice (double itemPrice)
{
this.itemPrice = itemPrice;
}
//calculate value of item on-hand
public double getItemValue()
{
return this.itemQuanti ty * 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(ite mCode);
setItemQuantity (itemQuantity);
setItemPrice(it emPrice);
}
//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.itemQuanti ty = itemQuantity;
}
//set price of item
private void setItemPrice (double itemPrice)
{
this.itemPrice = itemPrice;
}
//calculate value of item on-hand
public double getItemValue()
{
return this.itemQuanti ty * this.itemPrice;
}
//calculate combined value of all inventory
double inventoryValue = cdItemPrice + dvdItemPrice + bookItemPrice;
//build array to house data
//InitInventory.j ava
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.prin tf("%s&s\n", "Index", "Value");//column headings
//output each array elements value
for (String counter = 0; counter < array.length; counter ++)
System.out.prin tf("%5d%8d\n", counter, array[counter]);
for (int counter = 0; counter < array.length; counter ++)
System.out.prin tf("%5d%8d\n", counter, array[counter]);
for (double counter = 0; counter < array.length; counter ++)
System.out.prin tf("%5d%8d\n", counter, array[counter]);
}//end class InitInventory
}//end main
}//end ShowInventory
[/code]
Comment