Hello...I am new to this forum so I am hoping that I can get this all together and possibly get a little help in figuring out these errors. I am working on an inventory program for one of my classes. I have listed below the code and the errors within the line that they occured. If someone could take a second and look this over and shoot me some advice, it would be greatly appreciated. Thanks in advance to anyone who replies.
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 float 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; // 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 );
DVDInventoryValue = number1 * number2; // multiply numbers
// 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() );
DVDInventoryValue = amount * price; // multiply numbers
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; // all 8 imports have an error of 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
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 { // error is: illegal start of expression and ';' expected
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; // again all imports have error of illegal start of expression
import java.awt.Graphics;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionAdapter;
import javax.swing.JPanel;
public class PaintPanel extends JPanel { // illegal start of expression and ';' expected
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 ) {
super.paintComponent( g ); // clears drawing area
// draw all points in array
for ( int i = 0; i < pointCount; i++ )
g.fillLogo( points[ i ].x, points[ i ].y, 4, 4 );
} // end method paintComponent
} // end class PaintPanel
// display result in a JOPtionPane message dialog
JOptionPane.showMessageDialog( null, "The DVD Number is",
JOptionPane,PLAIN_MESSAGE );
JOptionPane.showMessageDialog( null, "The DVD Name is",
JOptionPane,PLAIN_MESSAGE );
JOptionPane.showMessageDialog( null, "The Amount of DVDs in Stock is",
JOptionPane,PLAIN_MESSAGE );
JOptionPane.showMessageDialog( null, "The DVD Price is",
JOptionPane.PLAIN_MESSAGE );
JOptionPane.showMessageDialog( null, "The DVD Inventory Value is",
JOptionPane.PLAIN_MESSAGE );
// get cd artist data
System.out.println(
"DVD information obtained by get methods: \n" );
System.out.printf( "%s %s\n", "DVD Name is",
DVDArtist.getDVDName() );
System.out.printf( "%s %s\n", "DVD Number is",
DVDArtist.getDVDNumber() );
System.out.print( "%s %.2f\n", "DVD Price is",
DVDArtist.getDVDPrice() );
System.out.prinf( "%s %.2f\n", "DVD Restocking Fee Rate is",
DVDArtist.getDVDRestockingFeeRate() );
System.out.printf( "%s %.2f\n", "DVD Inventory Value is",
DVDArtist.getDVDInventoryValue() );
DVDArtist.setDVDInventoryValue( 1000 ); // set inventory value
System.out.printf( "\n%s:\n\n%s\n",
"Updated DVD Information obtained by toString",
DVDArtist.toString());
} // end else
} // end else
} // end else
} // end main
} // end public class display
} // end class DVDArtist
} // end class DVD Inventory Value