I have asked my instructor to help me with this error so I can move on to the next part of the program which is due Sunday, but no help to give I guess my problem is that when i try to compile my program I get a class, interface,enum expected error on lines 217 and 218.
import javax.swing.*;
import java.awt.event.*;
my code is posted all help will be greatly appreciated.
public class Inventory
{
public static void main(String args[])
{
Cameras[] Cameras = new Cameras[4];
// objects call class
Cameras [0] = new Cameras( 0, "Nikon D300", "Electronics", 2, 429.00 );
Cameras [1] = new Cameras( 1, "Canon Power Shot", "Electronics", 4, 139.00 );
Cameras [2] = new Cameras( 2, "Kodak EasyShare", "Electronics", 6, 135.00 );
Cameras [3] = new Cameras( 3, "Nikon Coolpix", "Electronics", 1, 199.00 );
// outputs product
for (int i = 0; i < 4; i++)
{
System.out.println( "Item number: " + Cameras[i].getitemnumber() );
System.out.println( "Camera name: " + Cameras[i].getCameras() );
System.out.println( "Department: " + Cameras[i].getdepartment() );
System.out.println( "Units in stock: " + Cameras[i].getinstock() );
System.out.println( "Price: $" + Cameras[i].getprice() );
System.out.println( "Total value: $" + Cameras[i].inv_value() );
System.out.println();
}
DigitalCameras[] DigitalCameras = new DigitalCameras[2];
DigitalCameras [0] = new DigitalCameras( 0, "Nikon Digital", "Electronics", 8,
2, 529.00 );
DigitalCameras [1] = new DigitalCameras( 1, "Canon Digital", "Electronics",
10, 4, 639.00 );
for (int i = 0; i < 2; i++)
{
System.out.println( "Item number: " + DigitalCameras[i].getitemnumber() );
System.out.println( "Camera name: " + DigitalCameras[i].getDigitalCameras()
);
System.out.println( "Department: " + DigitalCameras[i].getdepartment() );
System.out.println( "Resolution: " + DigitalCameras[i].getimageResolution()
);
System.out.println( "Units in stock: " + DigitalCameras[i].getinstock() );
System.out.println( "Price: $" + DigitalCameras[i].getprice() );
System.out.println( "Total value: $" + DigitalCameras[i].inv_value() );
System.out.println();
}
}
}// End class
class Cameras
{
private String Cameras;
private String department;
private float itemnumber;
private float instock;
private double price;
public Cameras()
{
Cameras = " Cameras ";
department = " Electronics ";
itemnumber = 0;
instock = 0;
price = 0;
}
public Cameras( float itemnumber, String Cameras, String department, float instock,
double price )
{
this.itemnumber = itemnumber;
this.Cameras = Cameras;
this.department = department;
this.instock = instock;
this.price = price;
}
public void setitemnumber( float itemnumber )
{
this.itemnumber = itemnumber;
}
public float getitemnumber()
{
return itemnumber;
}
public void setCameras( String Cameras )
{
this.Cameras = Cameras;
}
String getCameras()
{
return Cameras;
}
public void setdepartment( String department )
{
this.department = department;
}
String getdepartment()
{
return department;
}
public void setinstock( float instock )
{
this.instock = instock;
}
public float getinstock()
{
return instock;
}
public void setprice( double price )
{
this.price = price;
}
public double getprice()
{
return price;
}
public double inv_value()
{
return ( instock * price );
}
}// end class
class DigitalCameras extends Cameras
{
private String DigitalCameras;
private String department;
private float itemnumber;
private float imageResolution;
private float instock;
private double price;
public DigitalCameras()
{
DigitalCameras = " DigitalCameras ";
department = " Electronics ";
itemnumber = 0;
imageResolution = 0;
instock = 0;
price = 0;
}
public DigitalCameras( float itemnumber, String DigitalCameras, String department,
float imageResolution, float instock, double price )
{
this.itemnumber = itemnumber;
this.DigitalCameras = DigitalCameras;
this.department = department;
this.imageResolution = imageResolution;
this.instock = instock;
this.price = price;
}
public void setitemnumber( float itemnumber )
{
this.itemnumber = itemnumber;
}
public float getitemnumber()
{
return itemnumber;
}
public void setDigitalCameras( String DigitalCameras )
{
this.DigitalCameras = DigitalCameras;
}
String getDigitalCameras()
{
return DigitalCameras;
}
public void setdepartment( String department )
{
this.department = department;
}
String getdepartment()
{
return department;
}
public void setimageResolution( float imageResolution )
{
this.imageResolution = imageResolution;
}
public float getimageResolution()
{
return imageResolution;
}
public void setinstock( float instock )
{
this.instock = instock;
}
public float getinstock()
{
return instock;
}
public void setprice( double price )
{
this.price = price;
}
public double getprice()
{
return price;
}
public double inv_value()
{
return ( instock * price + price * 0.05 );
}
}// end class
import javax.swing.*;
import java.awt.event.*;
//Stores and gets Camera info
class Inventory_Gui extends JFrame
{
private JTextArea txt;
private Inventory inv;
private int currentDisplay = 0;
public Inventory_Gui()
{
super("Cameras");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // quit if the window is
closed
init();
}
public void init() {
// Incorprate feed back from instructor
DigitalCameras p1 = new DigitalCameras( 0, "Digi Fast", "Electronics", 6, 3,
199.00 );
DigitalCameras p2 = new DigitalCameras( 1, "Aqua Clear Digital",
"Electronics", 4, 1, 180.00 );
// Create inventory add objects
inv = new Inventory();
inv.add(p1);
inv.add(p2);
inv.sort();
// output the
for (int i = 0; i < 2; i++)
{
System.out.println( "Item number: " + DigitalCameras[i].getitemnumber() );
System.out.println( "Camera name: " + DigitalCameras[i].getDigitalCameras()
);
System.out.println( "Department: " + DigitalCameras[i].getdepartment() );
System.out.println( "Resolution: " + DigitalCameras[i].getimageResolution()
);
System.out.println( "Units in stock: " + DigitalCameras[i].getinstock() );
System.out.println( "Price: $" + DigitalCameras[i].getprice() );
System.out.println( "Total value: $" + DigitalCameras[i].inv_value() );
System.out.println();
}
System.out.println("Total value: $" + String.format("%.2f",inv.value()));
// set interface
JPanel panel = new JPanel();
txt = new JTextArea(15,40);
txt.setEditable(false);
panel.add(txt);
JButton next = new JButton("Next");
next.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (currentDisplay < inv.size()-1) currentDisplay++; //advance
to the end
displayCameras();
}
});
panel.add(next);
getContentPane().add(panel);
displayCameras();
}
// view software
public void displayCameras() {
txt.setText( "Details" );
txt.append( "Item number: " + inv.get(currentDisplay).getItem() );
txt.append( "Camera name: " + inv.get(currentDisplay).getName() );
txt.append( "Department: " + inv.get(currentDisplay).getdepartment() );
txt.append( "Resolution: " + inv.get(currentDisplay).getimageResolution() );
txt.append( "Units in stock: " + inv.get(currentDisplay).getinstock() );
txt.append( "Price: $" + String.format("%.2f",inv.get
(currentDisplay).getprice()) );
txt.append( "Total value: $" + String.format("%.2f",inv.get
(currentDisplay).inv_value()) );
txt.append( "Total value: $" + String.format("%.2f",inv_value()) );
}
public static void main(String args[]) {
Inventory gui = new Inventory();
gui.pack();
gui.setVisible(true);
}
//
}