Join 149,493 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 1,332 people online right now. Registration is fast and FREE... Join Now!
Hello...of course as you can all see I am a newbie. I will cut straight to the point to prevent waisting any of your time. I am working on this inventory program for one of my classes. Unfortunately I am having a few issues that I just can't seem to figure out. I have listed below in great detail the issues that I am having. If someone could take a few minutes and help me figure out how to fix this, it would be greatly appreciated. This is my last resort...my brain hurts.
CODE
// DVDInventoryProgram.java // Inventory program that uses an array to store DVD name, DVD number, amount in // stock, DVD price, DVD value, value of complete inventory, and uses a GUI.
public class DVDInventoryValue { private string ProductName; private int stock[]
// constuctor initializes inventoryName and stock array public InventoryValue( String name, int stockArray[] ) {
InventoryName = name; // initialize inventory name stock = stockArray; // store stock } // end InventoryValue constructor
// method to set the inventory name public void setInventoryName( string name) { inventoryName = name; // store the inventory name } // end method setInventoryName
// method to retrieve the inventory name public string getInventoryName() { return InventoryName; } // end method get InventoryName
// display a message to the DVD Inventory Value user public void displayMessage() { // get InventoryName gets the name of the inventory System.out.printf( "This is the inventory for\n%s!\n\n", getInventoryName() ); } // end method display message to DVD Inventory Value user
public class DVDArtist { private String DVDName; private integer DVDNumber; private double DVDStockAmount; // amount in stock private double DVDPrice; // price of CD private double DVDRestockingFeeRate; // restocking percentage private double DVDInventoryValue; // value of inventory
// seven-argument constructor public DVDArtist(String name, int number, double stock, double price, double rate, double value ) { DVDName = name; // validate and store DVD name DVDNumber = number; // validate and store DVD number setDVDPrice( price ); // validate and store DVD price setDVDRestockingFeeRate( rate ); // validate and store DVD restocking fee rate setDVDInventoryValue( value ); // validate and store DVD inventory value } // end DVDArtist constructor
// set DVD name public void setDVDName( String name ) { DVDName = name; } // end method set DVD Name
// return DVD name public String getDVDName();{ return DVDName; } // end method return DVD Name
// set DVD number public void setDVDNumber( String number ) { DVDNumber = number; // should validate } // end method set DVD Number
// return DVD number public String getDVDNumber() { return DVDNumber; } // end method return DVD Number
// set amount of DVDs in stock public void setDVDStockAmount( double stock ) { stockAmount = ( stock < 0.0 ) ? 0.0 : stock; } // end method setDVDStockAmount
// return amount in of DVDs in stock public double getDVDStockAmount() { return DVDStockAmount; } // end method getDVDStockAmount
// set DVD price public void setDVDPrice( double rate ) { DVDPrice = ( price < 0.0 ) ? 0.0 : price; } // end method setDVDPrice
// return DVD price public double getDVDPrice() { return DVDPrice; } // end method getDVDPrice
// set DVD restocking fee rate public void setDVDRestockingFeeRate( double rate ) { DVDRestockingFeeRate = ( rate o.5 ) rate : 0.5; } // end method set DVD restocking fee rate
// return DVD restocking fee rate public double getDVDRestockingFeeRate() { return DVDRestockingFeeRate; } // end method get DVD restocking fee rate
// set DVD inventory value public void setDVDInventoryValue( double value ) { DVDInventoryValue = ( value < 0.0 ) ? 0.0 : value; } // end method set DVD inventory value
// return DVD inventory value public double getDVDInventoryValue() { return DVDInventoryValue; } // end method get DVD inventory value
// calculate feeinventory public double feeinventory() { return DVDInventoryValue + ( restockingFeeRate * stock ); } // end method feeinventory
// return String representation of ArtistName public String toString() { return String.format( "%s: %s %s\n%s: %s\n%s: %.2f\n%s: %.2f\n%s: %.2f", "DVD Name", DVDname, "DVD Number", DVDNumber, "DVDs in Stock", DVDStockAmount, "DVD Price",DVDPrice, "DVD Restocking Fee Rate", DVDRestockingFeeRate, "Value of DVD Inventory", DVDInventoryValue ); } // end method toString
// perform various operations on the data public void processStock() { // output Stock array outputStock();
// call method getValue to calculate the value of product System.out.printf( "Product value is %.2f\n",getValue() );
// call method getInventory to calculate entire value of inventory System.out.printf( "Inventory value is %d\n",getInventory() );
} // end method processStock
{ int total = 0; // initialize total // sum stock for one product for ( int stock : stock ) total += stock; }
// output the contents of the stock array public void outputStock() { System.out.println( "The stock is :\n" );
// output each product name's stock for ( int product = 0; product < stock.length; product++ ) System.out.printf( "Product %2d: %3d\n", product + 1, stock[ product ] ); } // end method outputStock
// use of JOption Pane for input and output
import javax.swing.JOptionPane;
public class Display {
public static void main( String args[] ) { // obtain user input from JOptionPane input dialogs String DVDNumber = JOptionPane.showInputDialog( "Enter DVD Number" );
if ( DVDNumber < 0 ) { System.out.println(" DVD Number invalid, please enter a positive number" ); } else {
String DVDName = JOptionPane.showInputDialog( "Enter DVD Name" ); String DVDStockAmount = JOptionPane.showInputDialog( "Enter amount of DVDs in stock" );
if ( DVDStockAmount < 0 ) { System.out.println(" Amount of DVDs in Stock is Invalid, please enter a positive number" ); } else {
String DVDPrice = JOptionPane.showInputDialog( "Enter DVD Price" );
if ( DVDPrice < 0 ) { System.out.println(" DVD Price is Invalid, please enter a positive number" ); } else {
// convert String inputs to int values for use in calculation int number1 = Integer.parseInt( DVDStockAmount ); int number2 = Integer.parseInt( DVDPrice );
// create DVDInventoryValue object DVDInventoryValue DVDInventoryValue1 = new DVDInventoryValue( "DVD Number", "DVD Name", "Amount of DVDs in Stock", "DVD Price" );
// display initial value of DVD number for DVDInventoryValue System.out.printf( "DVDInventoryValue1 DVD Number is: %d\n", DVDInventoryValue1.getDVDNumber() ); System.out.printf( "DVDInventoryValue1 DVD Name is %s\n", DVDInventoryValue1.getDVDName() ); System.out.printf( "DVDInventoryValue1 Amount of DVDs in Stock is %d\n", DVDInventoryValue1.getDVDStockAmount() ); System.out.print( "DVDInventoryValue1 DVD Price is %d/n", DVDInventoryValue1.getDVDPrice() );
public class RadioButtonFrame extends JFrame { private JTextField textField; // used to display field changes private field DVDNumber; // field for DVD number private field DVDName; // field for DVD name private field DVDStockAmount; // field for amount of DVDs in stock private field DVDPrice; // field for DVD price private field DVDInventoryValue; // field for DVD inventory value private field previous; // field for previous selection private field next; // field for next selection private JRadioButton DVDNumberJRadioButton; // selects DVD number field private JRadioButton DVDNameJRadioButton; // selects DVD name field private JRadioButton DVDStockAmountJRadioButton; // selects amount of DVDs in stock field private JRadioButton DVDPriceJRadioButton; // selects DVD price field private JRadioButton DVDInventoryValueJRadioButton; // selects DVD inventory value field private JRadioButton previousJRadioButton; // selects previous selection field private JRadioButton nextJRadioButton; // selects next selection field
// RadioButtonFrame constructor adds JRadioButtons to JFrame public RadioButtonFrame() { super( "RadioButton Test"); setLayout( new FlowLayout() ); // set frame layout
textfield = new JTextField( "Watch the field change", 25 ); add( textField ); // add textField to JFrame
// create radio buttons DVDNumberJRadioButton = new JRadioButton( "DVDNumber", true ); DVDNameJRadioButton = new JRadioButton( "DVDName", false ); DVDStockAmountJRadioButton = new JRadioButton( "DVDStockAmount", false ); DVDPriceJRadioButton = new JRadioButton( "DVDPrice", false ); DVDInventoryValueJRadioButton = new JRadioButton( "DVDInventoryValue", false ); previousJRadioButton = new JRadioButton( "previous", false ); nextJRadioButton = new JRadioButton( "next", false ); add( DVDNumberJRadioButton ); // add DVD number button to JFrame367 add( DVDNameJRadioButton ); // add DVD name button to JFrame add( DVDStockAmountJRadioButton ); // add DVD stock amount button to JFrame add( DVDPriceJRadioButton ); // add DVD price button to JFrame add( DVDInventoryValueJRadioButton ); // add DVD inventory value button to JFrame add( previousJRadioButton ); // add previous button to JFrame add( nextJRadioButton ); // add next button to JFrame
// create logical relationship between JRadioButtons radioGroup = new ButtonGroup(); // create ButtonGroup radioGroup.add( DVDNumberJRadioButton ); // add DVD number to group radioGroup.add( DVDNameJRadioButton ); // add DVD name to group radioGroup.add( DVDStockAmountJRadioButton ); // add DVD stock amount to group radioGroup.add( DVDPriceJRadioButton ); // add DVD price to group radioGroup.add( DVDInventoryValueJRadioButton ); // add DVD inventory value to group radioGroup.add( previousJRadioButton ); // add previous to group radioGroup.add( nextJRadioButton ); // add next to group
// create field objects DVDNumber = new number( "%d\n" ); DVDName = new name( "%s\n" ); DVDStockAmount = new amount( "%d\n" ); DVDPrice = new price( "%d\n" ); DVDInventoryValue = new value( "%d/n" ); previous = new previous( "%d/n" ); next = new next( "%d/n" ); textField.setfield( DVDNumber ); // set initial field to DVD number
// RadioButtonFrame constructor DVDNumberJRadioButton.addItemListener( new RadioButtonHandler( DVDNumber ) ); DVDNameJRadioButton.addItemListener( new RadioButtonHandler( DVDName ) ); DVDStockAmountJRadioButton.addItemListener( new RadioButtonHandler( DVDStockAmount ) ); DVDPriceJRadioButton.addItemListener( new RadioButtonHandler( DVDPrice ) ); DVDInventoryValueJRadioButton.addItemListener( new RadioButtonHandler( DVDInventoryValue ) ); previousJRadioButton.addItemListener( new RadioButtonHandler( previous ) ); nextJRadioButton.addItemListener( new RadioButtonHandler( next ) ); } // end RadioButtonFrame constructor
// private inner class to handle radio button events private class RadioButtonHandler implements ItemListener { private Field field; // field associated with this listener
public RadioButtonHandler( Field f ) { field = f; // set the field of this listener } // end constructor RadioButtonHandler
// handle radio button events public void itemStateChanged( ItemEvent event ) { textField.setField( field ); // set field of textField } // end method itemStateChanged } // end private inner class RadioButtonHandler } // end class RadioButtonFrame // Testing RadioButtonFrame. // import javax.swing.JFrame
public class RadioButtonTest { public static void main( string [] args ) { RadioButtonFrame radioButtonFrame = new RadioButtonFrame(); radioButtonFrame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE ); radioButtonFrame.setSize( 300, 100 ); // set frame size radioButtonFrame.setVisible( true ); // display frame } // end main } // end class RadioButtonTest
// Using class MouseMotionAdapter import java.awt.Point; import java.awt.Graphics; import java.awt.event.MouseEvent; import java.awt.event.MouseMotionAdapter; import javax.swing.JPanel;
public class PaintPanel extends JPanel { private int pointCount = 0; // count number of points
// array of 1000 java.awt.Point references private Point points[] = new Point[ 10000 ];
// set up GUI and register mouse event handler public PaintPanel() { // handle frame mouse motion event addMouseMotionListener(
new MouseMotionAdapter() // anonymous inner class { // store drag coordinates and repaint public void mouseDragged( MouseEvent event ) { if ( pointCount < points.length ) { points[ pointCount ] = event.getPoint(); // find point pointCount++; // increment number of points in array repaint(); // repaint JFrame } // end if } // end method mouseDragged } // end anonymous inner class ); // end call to addMouseMotionListener } // end PaintPanel constructor
// draw company logo in a 4-by4- bounding box at specified location on window public void paintComponent( Graphics g ) { &
sorry here is the code with the errors...sorry about that!!!!! I listed the errors right after the code for that line...
CODE
// DVDInventoryProgram.java // Inventory program that uses an array to store DVD name, DVD number, amount in // stock, DVD price, DVD value, value of complete inventory, and uses a GUI.
public class DVDInventoryValue { private string ProductName; private int stock[]// error is: ';' expected
// constuctor initializes inventoryName and stock array public InventoryValue( String name, int stockArray[] ) {
InventoryName = name; // initialize inventory name stock = stockArray; // store stock } // end InventoryValue constructor
// method to set the inventory name public void setInventoryName( string name) { inventoryName = name; // store the inventory name } // end method setInventoryName
// method to retrieve the inventory name public string getInventoryName() { return InventoryName; } // end method get InventoryName
// display a message to the DVD Inventory Value user public void displayMessage() { // get InventoryName gets the name of the inventory System.out.printf( "This is the inventory for\n%s!\n\n", getInventoryName() ); } // end method display message to DVD Inventory Value user
public class DVDArtist { private String DVDName; private integer DVDNumber; private double DVDStockAmount; // amount in stock private double DVDPrice; // price of CD private double DVDRestockingFeeRate; // restocking percentage private double DVDInventoryValue; // value of inventory
// seven-argument constructor public DVDArtist(String name, int number, double stock, double price, double rate, double value ) { DVDName = name; // validate and store DVD name DVDNumber = number; // validate and store DVD number setDVDPrice( price ); // validate and store DVD price setDVDRestockingFeeRate( rate ); // validate and store DVD restocking fee rate setDVDInventoryValue( value ); // validate and store DVD inventory value } // end DVDArtist constructor
// set DVD name public void setDVDName( String name ) { DVDName = name; } // end method set DVD Name
// return DVD name public String getDVDName();{ return DVDName; } // end method return DVD Name
// set DVD number public void setDVDNumber( String number ) { DVDNumber = number; // should validate } // end method set DVD Number
// return DVD number public String getDVDNumber() { return DVDNumber; } // end method return DVD Number
// set amount of DVDs in stock public void setDVDStockAmount( double stock ) { stockAmount = ( stock < 0.0 ) ? 0.0 : stock; } // end method setDVDStockAmount
// return amount in of DVDs in stock public double getDVDStockAmount() { return DVDStockAmount; } // end method getDVDStockAmount
// set DVD price public void setDVDPrice( double rate ) { DVDPrice = ( price < 0.0 ) ? 0.0 : price; } // end method setDVDPrice
// return DVD price public double getDVDPrice() { return DVDPrice; } // end method getDVDPrice
// set DVD restocking fee rate public void setDVDRestockingFeeRate( double rate ) { DVDRestockingFeeRate = ( rate o.5 ) rate : 0.5;// error is ")" expected } // end method set DVD restocking fee rate
// return DVD restocking fee rate public double getDVDRestockingFeeRate() { return DVDRestockingFeeRate; } // end method get DVD restocking fee rate
// set DVD inventory value public void setDVDInventoryValue( double value ) { DVDInventoryValue = ( value < 0.0 ) ? 0.0 : value; } // end method set DVD inventory value
// return DVD inventory value public double getDVDInventoryValue() { return DVDInventoryValue; } // end method get DVD inventory value
// calculate feeinventory public double feeinventory() { return DVDInventoryValue + ( restockingFeeRate * stock ); } // end method feeinventory
// return String representation of ArtistName public String toString() { return String.format( "%s: %s %s\n%s: %s\n%s: %.2f\n%s: %.2f\n%s: %.2f", "DVD Name", DVDname, "DVD Number", DVDNumber, "DVDs in Stock", DVDStockAmount, "DVD Price",DVDPrice, "DVD Restocking Fee Rate", DVDRestockingFeeRate, "Value of DVD Inventory", DVDInventoryValue ); } // end method toString
// perform various operations on the data public void processStock() { // output Stock array outputStock();
// call method getValue to calculate the value of product System.out.printf( "Product value is %.2f\n",getValue() );
// call method getInventory to calculate entire value of inventory System.out.printf( "Inventory value is %d\n",getInventory() );
} // end method processStock
{ int total = 0; // initialize total // sum stock for one product for ( int stock : stock ) total += stock; }
// output the contents of the stock array public void outputStock() { System.out.println( "The stock is :\n" );
// output each product name's stock for ( int product = 0; product < stock.length; product++ ) System.out.printf( "Product %2d: %3d\n", product + 1, stock[ product ] ); } // end method outputStock
// use of JOption Pane for input and output
import javax.swing.JOptionPane; // error is: illegal start of type and <identifier> expected
public class Display {
public static void main( String args[] ) { // obtain user input from JOptionPane input dialogs String DVDNumber = JOptionPane.showInputDialog( "Enter DVD Number" );
if ( DVDNumber < 0 ) { System.out.println(" DVD Number invalid, please enter a positive number" ); } else {
String DVDName = JOptionPane.showInputDialog( "Enter DVD Name" ); String DVDStockAmount = JOptionPane.showInputDialog( "Enter amount of DVDs in stock" );
if ( DVDStockAmount < 0 ) { System.out.println(" Amount of DVDs in Stock is Invalid, please enter a positive number" ); } else {
String DVDPrice = JOptionPane.showInputDialog( "Enter DVD Price" );
if ( DVDPrice < 0 ) { System.out.println(" DVD Price is Invalid, please enter a positive number" ); } else {
// convert String inputs to int values for use in calculation int number1 = Integer.parseInt( DVDStockAmount ); int number2 = Integer.parseInt( DVDPrice );
// create DVDInventoryValue object DVDInventoryValue DVDInventoryValue1 = new DVDInventoryValue( "DVD Number", "DVD Name", "Amount of DVDs in Stock", "DVD Price" );
// display initial value of DVD number for DVDInventoryValue System.out.printf( "DVDInventoryValue1 DVD Number is: %d\n", DVDInventoryValue1.getDVDNumber() ); System.out.printf( "DVDInventoryValue1 DVD Name is %s\n", DVDInventoryValue1.getDVDName() ); System.out.printf( "DVDInventoryValue1 Amount of DVDs in Stock is %d\n", DVDInventoryValue1.getDVDStockAmount() ); System.out.print( "DVDInventoryValue1 DVD Price is %d/n", DVDInventoryValue1.getDVDPrice() );
while ( DVDNumber <= 0 ) { System.out.printf( "DVDInventoryValue is %d\n", DVDInventoryValue ); // display // DVD Inventory Value } // end while
//Creating radio buttons using ButtonGroup and JRadioButton.
import java.awt.FlowLayout; //error is: everyone of these next 8 imports has the error: illegal start of expression import java.awt.DVDs; import java.awt.event.ItemListener; import java.awt.event.ItemEvent; import javax.swing.JFrame; import javax.swing.JTextField; import javax.swing.JRadioButton; import javax.swing.ButtonGroup;
public class RadioButtonFrame extends JFrame { // error is: illegal start of expression and ';' expected private JTextField textField; // used to display field changes private field DVDNumber; // field for DVD number private field DVDName; // field for DVD name private field DVDStockAmount; // field for amount of DVDs in stock private field DVDPrice; // field for DVD price private field DVDInventoryValue; // field for DVD inventory value private field previous; // field for previous selection private field next; // field for next selection private JRadioButton DVDNumberJRadioButton; // selects DVD number field private JRadioButton DVDNameJRadioButton; // selects DVD name field private JRadioButton DVDStockAmountJRadioButton; // selects amount of DVDs in stock field private JRadioButton DVDPriceJRadioButton; // selects DVD price field private JRadioButton DVDInventoryValueJRadioButton; // selects DVD inventory value field private JRadioButton previousJRadioButton; // selects previous selection field &n