I have several files and am receiving errors message when compiling and would appreciate any help. Thank you in advance.
Model class file:
class Model extends Product5
{
String genre; //add product to product inventory
double restockFee; //fee for restocking
//initialize constructor
public Model( String genre, String name, int identificationNumber, String printerName, String productNumber, double unitsInStock, double unitPriceInDollars, double restockFee )
{
super(name, identificationNumber, printerName, productNumber, unitsInStock, unitPriceInDollars);
this.genre = genre;
this.restockFee = 0.05;
}
public void setgenre(String genre)
{
genre = genre;
}
public String getgenre()
{
return genre;
}
public double getRestockFee()//calculats restocking fees
{
return super.getInventoryValue() * restockFee;
}
public double getInventoryValue() //total inventory of all products
{
return super.getInventoryValue() + (super.get.InventoryValue() * restockFee);
}
public String toString()
{
StringBuffer sb = new StringBuffer("\ngenre: ").append(genre).append("\n");
sb.append(super.toString());
return sb.toString();
}
}//End Model Class
Model Class receives the following errors:
----jGRASP exec: javac -g C:\Java\New Folder\Model.java
Model.java:15: cannot find symbol
symbol : constructor Product5(java.lang.String,int,java.lang.String,java.lang.String,double,double)
location: class Product5
super(name, identificationNumber, printerName, productNumber, unitsInStock, unitPriceInDollars);
^
Model.java:32: cannot find symbol
symbol : method getInventoryValue()
location: class Product5
return super.getInventoryValue() * restockFee;
^
Model.java:37: cannot find symbol
symbol : method getInventoryValue()
location: class Product5
return super.getInventoryValue() + (super.get.InventoryValue() * restockFee);
^
Model.java:37: cannot find symbol
symbol : variable get
location: class Product5
return super.getInventoryValue() + (super.get.InventoryValue() * restockFee);
^
Model.java:37: operator + cannot be applied to Product5.getInventoryValue,double
return super.getInventoryValue() + (super.get.InventoryValue() * restockFee);
^
Model.java:37: incompatible types
found : <nulltype>
required: double
return super.getInventoryValue() + (super.get.InventoryValue() * restockFee);
^
6 errors
----jGRASP wedge2: exit code for process is 1.
----jGRASP: operation complete.
Inventory5 file:
class Inventory5
{
Product5[] inventory; //stores inventory products
int number_of_products_in_inventory = 0; //stores number of inventory
public Inventory5( int maximum_number_of_products )
{
inventory = new Product5[maximum_number_of_products];
}
public void addProduct5( Inventory5_adds_products_to_inventory )
{
inventory[number_of_products_in_inventory] = Inventory5_adds_products_to_inventory;
number_of_products_in_inventory++;
}
public Inventory5 getProduct5( int index )
{
return inventory[index];
}
public int getSize()
{
return number_of_products_in_inventory;
}
public double getTotalValueOfAllInventory()
{
double totalValue = 0.00;
for(int i = 0; i < number_of_products_in_inventory; i++)
{
totalValue += inventory[i].getInventoryValue();
}
return totalValue;
}
public void sortProduct5()//sorts product inventory by name
{
//sorts inventory information
for(int j = 0; < number_of_products_in_inventory - 1; j++)
{
for(int k = 0; k < number_of_products_in_inventory - 1; k++)
{
if(inventory[k].getName().compareToIgnoreCase(inventory[k+1].getName()) > 0)
{
Product5 temp = inventory[k];
inventory[k] = inventory[k+1];
inventory[k+1] = temp;
}
}
}
}
}//Ends Inventory5 class
Inventory5 receives the following errors:
----jGRASP exec: javac -g C:\Java\New Folder\Inventory5.java
Inventory5.java:18: <identifier> expected
public void addProduct5( Inventory5_adds_products_to_inventory )
^
Inventory5.java:48: > expected
for(int j = 0; < number_of_products_in_inventory - 1; j++)
^
Inventory5.java:48: illegal start of expression
for(int j = 0; < number_of_products_in_inventory - 1; j++)
^
Inventory5.java:48: ';' expected
for(int j = 0; < number_of_products_in_inventory - 1; j++)
^
Inventory5.java:48: illegal start of expression
for(int j = 0; < number_of_products_in_inventory - 1; j++)
^
Inventory5.java:48: ')' expected
for(int j = 0; < number_of_products_in_inventory - 1; j++)
^
Inventory5.java:48: illegal start of expression
for(int j = 0; < number_of_products_in_inventory - 1; j++)
^
7 errors
----jGRASP wedge2: exit code for process is 1.
----jGRASP: operation complete.
Product5 class file: This one compiles without any errors
class Product5
{
String name; //Product name
String printerName; //Printer Model Name
int identificationNumber; //The product identification number
String productNumber; //class variable that stores cartridge number
int unitsInStock; //Number of units in stock
double unitPriceInDollars; //The price of each unit in dollars
double restockFee; //price for restocking units
//Initialization constructor
public Product5(
String nameIn, String printerName, int identificationNumberIn, String productNumberIn,
int unitsInStockIn, double unitPriceInDollarsIn, double restockFeeIn
)
{
name = "";
printerName = "";
identificationNumber = 0;
productNumber = "";
unitsInStock = 0;
unitPriceInDollars = 0.00;
restockFee = 0.00;
}//End Inventory constructor
//Stores the item name
public void setName( String nameIn )
{
name = nameIn; //Store the item name
}//End setName
public String getName()
{
return name;
}
//Stores the printer model name
public void setPrinterName( String printerNameIn )
{
printerName = printerNameIn; //Store the item name
}//End setPrinterModelName
public String getPrinterName()
{
return printerName;
}
//Stores the product identification number
public void setIdentificationNumber( int identificationNumberIn )
{
//Store the item identification number
// If the value is negative, then store 0
identificationNumber = ( (identificationNumberIn > 0) ? identificationNumberIn : 0 );
}//End setID
public int getIdentificationNumber()
{
return ( identificationNumber ); //Return the identification number
}//End getIdentificationNumber
//Stores cartridge product number
public void setProductNumber( String productNumberIn )
{
productNumber = productNumber;
}//End setProductNumber
public String getProductNumber()
{
return productNumber;
}
//Stores the number of units in stock
public void setUnitsInStock( int unitsInStockIn )
{
//Store the number of units in stock
// If the value is negative, then store 0
unitsInStock = ( (unitsInStockIn > 0)?unitsInStockIn:0 );
}//End setUnitsInStock
public int getUnitsInStock()
{
return unitsInStock;
}
//Stores the price of each unit in dollars
public void setUnitPriceInDollars( double unitPriceInDollarsIn )
{
//Store the unit price
// If the value is negative, then store 0.0
unitPriceInDollars = ( (unitPriceInDollarsIn > 0.0)?unitPriceInDollarsIn:0.0);
}//End setUnitPriceInDollars
public double getUnitPriceInDollars()
{
return unitPriceInDollars;
}
//Stores the item restock fee
public void setRestockFee( double restockFeeIn )
{
restockFee = ( (restockFeeIn > 0.0)?restockFeeIn:0.0 ); //Store the item restock fee
}//End setRestockFee
//Returns the restocking fee
public double getRestockFee()
{
return( restockFee );
}
//Other Methods
//Returns the total value of the inventory in dollars
public double stockValueInDollars()
{
return ( unitsInStock * unitPriceInDollars );
}//End stockValueInDollars
//Returns a formatted String for output purposes
public String toString()
{
String formatString = "Identification Number : %d\n";
formatString += "Cartridge Name : %s\n";
formatString += "Printer Model : %s\n";
formatString += "Product Number : %s\n";
formatString += "Units In Stock : %d\n";
formatString += "Unit Price : $%.2f\n";
formatString += "Stock Value : $%.2f\n";
formatString += "Restocking Fee : $%.2f\n";
return ( String.format( formatString, identificationNumber, name, printerName, productNumber, unitsInStock,
unitPriceInDollars, stockValueInDollars(), restockFee )
);
}//End toString()
}//End Product5 class
Inventory5GUI file:
//Inventory5GUI.java works with Product5, Model, Inventory5 java files
import java.util.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.FlowLayout;
import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.util.Scanner; // program uses class Scanner
public class Inventory5GUI extends JFrame
{
//create inventory for the Printer Cartridge Products
Product5 Inventory;
public static final int WIDTH = 400;
public static final int HEIGHT = 200;
int index = 0;
// displays Product's information
private final JLabel nameLabel = new JLabel("Product name: ");
private JTextField nameText;
private final JLabel printerNameLabel = new JLabel("Printer Name: ");
private JTextField printerNameText;
private final JLabel productNumberLabel = new JLabel("Product Number: ");
private JTextField productNumberText;
private final JLabel genreLabel = new JLabel("Genre: ");
private JTextField genreText;
private final JLabel unitpriceLabel = new JLabel("Unit Price: ");
private JTextField unitpriceText;
private final JLabel stockquantityLabel = new JLabel("Quantity in Stock: ");
private JTextField stockquantityText;
private final JLabel stockvalueLabel = new JLabel("Stock Value: ");
private JTextField stockvalueText;
private final JLabel restockFeeLabel = new JLabel("Fee for Restocking: ");
private JTextField restockFeeText;
private final JLabel totalValueLabel = new JLabel("Inventory Total: ");
private JLabel totalValueText;
// go to the next Cartridge Product in the list
private Action nextAction = new AbstractAction("Next")
{
public void actionPerformed(ActionEvent evt)
{
// check to see if there is a next Printer Cartridge
if (index = Inventory5.getSize() - 1)
{
// last of cartridges in the list, can not go any further
// so go to the front of the list
index = 0;
}
else
{
index++;
}
// repaint();
}
};
private JButton nextButton = new JButton(nextAction);
// go to the previous Cartridge in the list
private Action previousAction = new AbstractAction("Previous")
{
public void actionPerformed(ActionEvent evt)
{
// first Cartrdige, then go to the last Cartridge in the list
if (index == 0)
{
index = Product5.getSize() - 1;
}
else
{
index--;
}
repaint();
}
};
private JButton previousButton = new JButton(previousAction);
// go to the first Cartridge in the list
private Action firstAction = new AbstractAction("First")
{
public void actionPerformed(ActionEvent evt)
{
index = 0;
repaint();
}
};
private JButton firstButton = new JButton(firstAction);
// go to the last Cartridge in the list
private Action lastAction = new AbstractAction("Last")
{
public void actionPerformed(ActionEvent evt)
{
index = Product5.getSize() - 1;
repaint();
}
};
private JButton lastButton = new JButton(lastAction);
public void addCartridgeToInventory(Product5 temp)
{
Product5.addProduct5(temp);
repaint();
}
public void sortProduct5()
{
Product5.sortInventory();
repaint();
}
public Inventory5GUI(int maximum_number_of_Cartridges)
{
//Header for Inventory
super("My Printer Cartridge Inventory");
// create the inventory object to hold the printer cartridge information
Product5 = new Inventory(maximum_number_of_Cartridges);
// setup the GUI
// add the next button to the top of the GUI
// setup a panel to collect all the buttons in a FlowLayout
JPanel navButtonPanel = new JPanel();
navButtonPanel.add(firstButton);
navButtonPanel.add(previousButton);
navButtonPanel.add(nextButton);
navButtonPanel.add(lastButton);
getContentPane().add(navButtonPanel, BorderLayout.NORTH);
ImageIcon icon = new ImageIcon( "cartridge.jpg" );
imageLabel = new JLabel( "Cartridges", icon, JLabel.CENTER );
cp.add( imageLabel,BorderLayout.EAST );
this.setContentPane( cp );
this.setTitle( " Week 8: Inventory Program Part Five - Printer Cartridge Inventory " );
Image img = Toolkit.getDefaultToolkit().getImage();
Image scaledImage = img.getScaledInstance(225, 200, Image.SCALE_AREA_AVERAGING);
JLabel logoLabel = new JLabel(new ImageIcon(scaledImage));
// add the logo
getContentPane().add(logoLabel, BorderLayout.WEST);
// setup a panel to collect all the components.
JPanel centerPanel = new JPanel(new GridLayout(8, 2, 0, 4));
centerPanel.add(nameLabel);
nameText = new JTextField("");
nameText.setEditable(false);
centerPanel.add(nameText);
centerPanel.add(printerNameLabel);
printerNameText = new JTextField("");
printerNameText.setEditable(false);
centerPanel.add(printerNameText);
centerPanel.add(productNumberLabel);
productNumberText = new JTextField("");
productNumberText.setEditable(false);
centerPanel.add(productNumberText);
centerPanel.add(genreLabel);
genreText = new JTextField("");
genreText.setEditable(false);
centerPanel.add(genreText);
centerPanel.add(UnitPriceInDollarsLabel);
unitpriceindollarsText = new JTextField("");
unitpriceindollarsText.setEditable(false);
centerPanel.add(UnitPriceInDollarsText);
centerPanel.add(UnitsInStockLabel);
UnitsInStockText = new JTextField("");
UnitsInStockText.setEditable(false);
centerPanel.add(UnitsInStockText);
centerPanel.add(InventoryValueLabel);
inventoryValueText = new JTextField("");
inventoryValueText.setEditable(false);
centerPanel.add(InventoryValueText);
centerPanel.add(restockFeeLabel);
restockFeeText = new JTextField("");
restockFeeText.setEditable(false);
centerPanel.add(restockFeeText);
// add the overall inventory information to the panel
centerPanel.add(totalValueLabel);
totalValueText = new JLabel("");
centerPanel.add(totalValueText);
// add the panel to the center of the GUI's window
getContentPane().add(centerPanel, BorderLayout.CENTER);
repaint();
}
// repaint the GUI with new Printer Cartridge information
public void repaint()
{
Product5 temp = Product5.getProduct5(index);
if (temp != null)
{
nameText.setText( temp.getName() );
printerNameText.setText( temp.getPrinterName() );
productNumberText.setText( ""+temp.getProductNumber() );
genreText.setText( temp.getGenre() );
UnitPriceInDollarsText.setText( String.format("$%.2f", temp.getUnitPriceInDollars()) );
UnitsInStockText.setText( ""+temp.getUnitsInStock() );
InventoryValueText.setText( String.format("$%.2f", temp.getUnitPriceInDollars() * temp.getUnitsInStock() ) );
restockFeeText.setText( String.format("$%.2f", temp.getRestockFee() ) );
}
totalValueText.setText( String.format("$%.2f", Product5.getTotalValueOfAllInventory() ) );
}
public static void main(String args[])
{
// create a new GUI object
Inventory5GUI Cartridge_GUI = new Product5(5);
// Add the DVD's to the inventory
Cartridge_GUI.addCartridgeToInventory(new Product5("HP BLACK", 1, "LaserJet_4", "92298x", 3, 72.91, 3.65));
Cartridge_GUI.addCartridgeToInventory(new Product5("HP 41 COLOR", 2, "Deskjet_820CXI", "51641a", 2, 21.29, 1.06));
Cartridge_GUI.addCartridgeToInventory(new Product5("HP 78 TRI_COLOR", 3, "Deskjet_1220C", "c6578dn", 4, 22.45, 1.12));
Cartridge_GUI.addCartridgeToInventory(new Product5("HP 102 Gray", 4,"Photosmart_8700", "c9360an", 16, 22.99, 1.15));
Cartridge_GUI.addCartridgeToInventory(new Product5("HP Black", 5, "Deskjet_9650", "c6656an", 14, 13.60, 0.68));
// sort the Products by name
Cartridge_GUI.sortProduct5();
// Get the GUI to show up on the screen
Cartridge_GUI.setDefaultCloseOperation( EXIT_ON_CLOSE );
Cartridge_GUI.pack();
Cartridge_GUI.setSize(625, 325);
Cartridge_GUI.setResizable(false);
Cartridge_GUI.setLocationRelativeTo( null );
Cartridge_GUI.setVisible(true);
return;
}
} // End Inventory5GUI class
Of course, Inventory5GUI will not compile due to the other errors. Can someone please look at it and tell me what I have done.
Thank you.