Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

class, interface, or emun expected.

807601Feb 4 2008 — edited Feb 4 2008
When I compile to code I get 60 "class, interface, or emun expected errors. I know that this error usual means that there is a bracket out of place or missing. I went through and add line comments that link the opening and closing brackets together. Can anyone take a look and let me know what I am missing. Thanks.



{code}

// Inventory4.java
// Program will track total inventory items in stock.

import java.io.*;
import javax.swing.JFrame;

public class Inventory4
{//1
public class Item
{//2
private double unitPrice;
private double quantityStock;
private double inventoryValue;
private double totalInventory;
private int itemNumber;
private String itemName;

/** Create a new instance of Item Name */
public Item(double UnitPrice,double QuantityStock,int ItemNumber,String ItemName)
{//3
itemName = ItemName;
itemNumber = itemNumber;
unitPrice = UnitPrice;
quantityStock = QuantityStock;
}//3
public void setItemName(String ItemName)
{//4
itemName = ItemName;
}//4

public void setItemNumber(int ItemNumber)
{//5
itemNumber = ItemNumber;
}//5

public void setUnitPrice(String InventoryHardware)
{//6
inventoryHardware=InventoryHardware;
}//6

public void setUnitPrice(double UnitPrice)
{//7

unitPrice = UnitPrice;
}//7

public void setQuantityStock(double QuantityStock)
{//8
quantityStock = QuantityStock;
}//8

public String getItemName()
{//9
return itemName;
}//9

public int getItemNumber()
{//10
return itemNumber;
}//10
public String getInvetoryHardware()
{//11
return inventoryHardware;
}//11

public double getUnitPrice()
{//12
return unitPrice;
}//12

public double getQuantityStock()
{//13
return quantityStock;
}//13

public String getInventoryHardware()
{//14
return inventoryHardware;
}//14

public double computeinventoryValue()
{//15
return quantityStock * unitPrice;
}//15

public double computetotalInventory()
{//16
return totalInventory = totalInventory + inventoryValue;
}//16

public String toString()
{//17
return (itemName);
}//17
}//2
}//1

// SubItem.java
// Sub class to main program
public class SubItem extends Item
{//18

private String inventoryHardware;
private double restockingFee = .05;

public SubItem(double UnitPrice,double QuantityStock,int InventoryWriteoffs,int
ItemNumber,String ItemName)
{//19

setUnitPrice(UnitPrice);
setQuantityStock(QuantityStock);
setItemNumber(ItemNumber);
setItemName(ItemName);

inventoryWriteoffs = InventoryWriteoffs;

}//19





public void setInventoryHardware(String InventoryHardware)
{//20
inventoryHardware = InventoryHardware;
}//20


public int getInventoryHardware()
{//21
return inventoryWriteoffs;
}//21


public double computeRestockingFee()
{//22
return ((getUnitPrice() * getQuantityStock()) * restockingFee);
}//22
}//18



private static BufferedReader stdin = new BufferedReader( new InputStreamReader( System.in ) );


private static int totalCount = 5;


public Inventory4()
{//23


double unitPrice; // Unit price of each item
double quantityStock; // Number of items in stock
double inventoryValue; // Place holder for calculated inventory value
double totalInventory; // Place holder for calculated total inventory value
int itemNumber; // Item Number
String itemName = ""; // Name of each item
}//23


public static void main(String[] args)throws IOException
{//24


SubItem myItem[];

myItem = new SubItem[5];


myItem[0] = new SubItem(10.35,20,4,1,"Traxx");
myItem[1] = new SubItem(176.34,10,5,2,"Panels");
myItem[2] = new SubItem(85.34,4,4,3,"Surfaces");
myItem[3] = new SubItem(1.95,56,6,4,"Brackets");
myItem[4] = new SubItem(82.34,8,1,5,"Overheads");



printArray(myItem);

myItem = sortArray(myItem);
System.out.println(" Inventory List Sorted by Items \n\n");
printArray(myItem);


ItemButton itemButton = new ItemButton(myItem,totalCount); // Make ItemButton
itemButton.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
itemButton.setSize( 350,390 ); // Window size
itemButton.setVisible( true ); // display window

} //24 End Main Method



private static SubItem[] printArray(SubItem[] myItem)
{//25
double totalInventory = 0;
double restockingFee = 0;


for (int i = 0; i<5;++i)
{//26
System.out.println("\n The Item Number is " + i + myItem.getItemNumber() );
System.out.println("\n Item Name is " + myItem.getItemName() );
System.out.println("\n Quantity in Stock is " + myItem.getQuantityStock() );
System.out.println("\n Inventory Write-off is " + myItem.getInventoryWriteoffs() );
System.out.println("\n Inventory Value is $" + myItem.computeinventoryValue ());

totalInventory = totalInventory + myItem.computeinventoryValue();
restockingFee = totalInventory + myItem.computeRestockingFee();

} //26 End For Loop

System.out.println("\n Total Value of all inventory is " + totalInventory);
System.out.println("\n Total Value of all inventory with restock fee $" + restockingFee);
return myItem;

}//25


private static SubItem[] sortArray(SubItem[] myItem)
{//27

SubItem temp = new SubItem();

int i, j;
int array_size = 5;
for (i = (array_size - 1); i >= 0; i--)
{//28
for (j = 1; j <= i; j++)
{//29
if (myItem[j-1].getItemName().compareTo(myItem[j].getItemName()) > 1)
{//30
temp = myItem[j-1];
myItem[j-1] = myItem[j];
myItem[j] = temp;
} //30 End if
} //29 End inner for loop
} //28 End outer for loop
return myItem;
} //27 End Method



// ItemButton.java
// This will create GUI buttons.

// Display the Items.
import java.awt.FlowLayout;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;
import javax.swing.SwingConstants;
public class ItemButton extends JFrame
{//31

private JButton nextJButton; // text button
private JButton prevJButton; // icon button
private JLabel lblItemName; // text field with set size
private JTextField txtItemName; // text field constructed with text
private JTextField textField3; // text field with text and size
private JLabel lblItemNumber; // text field with set size
private JTextField txtItemNumber; // text field constructed with text
private JLabel lblUnitPrice; // text field with set size
private JTextField txtUnitPrice; // text field constructed with text
private JLabel lblQuantityStock; // text field with set size
private JTextField txtQuantityStock; // text field constructed with text
private JLabel lblInventoryWriteoffs; // text field with set size
private JTextField txtInventoryWriteoffs; // text field constructed with text
private JLabel lblcomputeRestockingFee; // text field with set size
private JTextField txtcomputeRestockingFee; // text field constructed with text
private JLabel lblcomputeinventoryValue; // text field with set size
private JTextField txtcomputeinventoryValue; // text field constructed with text
private JLabel lblcomputetotalInventory; // text field with set size
private JTextField txtcomputetotalInventory; // text field constructed with text

SubItem[] arraySubItem;
private int currentArrayCounter;
private int arrayCount;


public ItemButton(SubItem[] myItem, int totalArrayCount)
{//32
super ( "Inventory" );
arraySubItem = myItem;

arrayCount = totalArrayCount;
currentArrayCounter = 0;


setLayout( new FlowLayout() ); // set frame layout


Icon iconNext = new ImageIcon( getClass().getResource( "" ) );
Icon iconPrev = new ImageIcon( getClass().getResource( "" ) );


lblItemName = new JLabel( "Item Name ");
add( lblItemName ); // textField3 to JFrame
txtItemName = new JTextField( "", 15 );
add( txtItemName ); // add textField3 to JFrame

lblItemNumber = new JLabel( "Item Number ");
add( lblItemNumber ); // textField3 to JFrame
txtItemNumber = new JTextField( "", 15 );
add( txtItemNumber ); // add textField3 to JFrame

lblUnitPrice = new JLabel( "Unit Price ");
add( lblUnitPrice ); // textField3 to JFrame
txtUnitPrice = new JTextField( "", 15 );
add( txtUnitPrice ); // add textField3 to JFrame

lblQuantityStock = new JLabel( "Quantity Stock " );
add( lblQuantityStock ); // textField3 to JFrame
txtQuantityStock = new JTextField( "", 15 );
add( txtQuantityStock ); // add textField3 to JFrame

lblInventoryHardware = new JLabel( "Inventory Hardware " );
add( lblInventoryHardware ); // textField3 to JFrame
txtInventoryHardware = new JTextField( "", 15 );
add( txtInventoryHardware ); // add textField3 to JFrame

lblcomputeRestockingFee = new JLabel( "Restocking Fee ");
add( lblcomputeRestockingFee ); // textField3 to JFrame
txtcomputeRestockingFee = new JTextField( "", 15 );
add( txtcomputeRestockingFee ); // add textField3 to JFrame

lblcomputeinventoryValue = new JLabel( "Inventory Value " );
add( lblcomputeinventoryValue ); // textField3 to JFrame
txtcomputeinventoryValue = new JTextField( "", 15 );
add( txtcomputeinventoryValue ); // add textField3 to JFrame

lblcomputetotalInventory = new JLabel( "Total Inventory ");
add( lblcomputetotalInventory ); // textField3 to JFrame
txtcomputetotalInventory = new JTextField( "", 15 );
add( txtcomputetotalInventory ); // add textField3 to JFrame

nextJButton = new JButton( "Next" ); // button with Next
prevJButton = new JButton( "Previous"); // button with Prev
add(prevJButton);
add(nextJButton); // add plainJButton to JFrame


ButtonHandler handler = new ButtonHandler();
nextJButton.addActionListener( handler );
prevJButton.addActionListener( handler );


setTextFields();

} //32 End ButtonFrame constructor

private class ButtonHandler implements ActionListener
{//33

public void actionPerformed( ActionEvent event )
{//34
if (event.getActionCommand()== "prevJButton")
{//35
currentArrayCounter++;
}//35
else
{//36
currentArrayCounter++;
}//36

setTextFields();

} //34 End Method ActionPerformed
} //33 End Private inner class ButtonHandler
private void setTextFields()
{//37

if (currentArrayCounter == arrayCount)
{//38
currentArrayCounter = 0;
}//38


if (currentArrayCounter < 0)
{//39
currentArrayCounter = arrayCount;
}//39

txtItemName.setText(arraySubItem[currentArrayCounter].getItemName());
txtItemNumber.setText(arraySubItem[currentArrayCounter].getItemNumber() +"");
txtUnitPrice.setText(arraySubItem[currentArrayCounter].getUnitPrice()+"");
txtQuantityStock.setText(arraySubItem[currentArrayCounter].getQuantityStock ()+"");
txtInventoryWriteoffs.setText(arraySubItem [currentArrayCounter].getInventoryWriteoffs()+"");
txtcomputeRestockingFee.setText(arraySubItem [currentArrayCounter].computeRestockingFee()+"");
txtcomputeinventoryValue.setText(arraySubItem [currentArrayCounter].computeinventoryValue()+"");
txtcomputetotalInventory.setText(arraySubItem [currentArrayCounter].computetotalInventory()+"");
}//37

} //31 End class ItemButton
{code}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 3 2008
Added on Feb 4 2008
4 comments
124 views