Hello,
I have been working on this aspect of the for about 5 days, I have read the course material which is some instances does not make any sense, maybe it's me. Anyway, I need to create a GUI to display the IO, the problem I am having is being able to code the existing code into a GUI. Here's the part I have done. The program compiled before I started to make the changes. Any help will be appreciated. Thanks.
ERROR CODES:
--------------------Configuration: ListFiles - JDK version 1.6.0_03 <Default> - <Default>--------------------
C:\Users\Debbie\Documents\JCreator LE\MyProjects\ListFiles\src\Inventory.java:54: incompatible types
found : double
required: java.lang.String
units = Double.parseDouble( units);
^
C:\Users\Debbie\Documents\JCreator LE\MyProjects\ListFiles\src\Inventory.java:60: incompatible types
found : double
required: java.lang.String
price = Double.parseDouble(price);
^
C:\Users\Debbie\Documents\JCreator LE\MyProjects\ListFiles\src\Inventory.java:67: cannot find symbol
symbol : method showMessageDialog(java.lang.String)
location: class javax.swing.JOptionPane
ProductValue=JOptionPane.showMessageDialog("Product grand total value ");
^
C:\Users\Debbie\Documents\JCreator LE\MyProjects\ListFiles\src\Inventory.java:68: parseDouble(java.lang.String) in java.lang.Double cannot be applied to ()
ProductValue = Double.parseDouble();
^
C:\Users\Debbie\Documents\JCreator LE\MyProjects\ListFiles\src\Inventory.java:74: cannot find symbol
symbol : method showMessageDialog(java.lang.String)
location: class javax.swing.JOptionPane
ReStkFee =JOptionPane.showMessageDialog("Product restocking fee");
^
C:\Users\Debbie\Documents\JCreator LE\MyProjects\ListFiles\src\Inventory.java:75: parseDouble(java.lang.String) in java.lang.Double cannot be applied to ()
ReStkFee = Double.parseDouble();
^
C:\Users\Debbie\Documents\JCreator LE\MyProjects\ListFiles\src\Inventory.java:82: cannot find symbol
symbol : constructor Product(java.lang.String,java.lang.String,java.lang.String,java.lang.String,java.lang.String,java.lang.String)
location: class Product
products[i] = new Product(id, name, units, price, ProductValue, ReStkFee);
^
C:\Users\Debbie\Documents\JCreator LE\MyProjects\ListFiles\src\Inventory.java:94: incompatible types
found : double
required: java.lang.String
InventoryValue=Double.parseDouble(InventoryValue );
^
C:\Users\Debbie\Documents\JCreator LE\MyProjects\ListFiles\src\Inventory.java:97: parseDouble(java.lang.String) in java.lang.Double cannot be applied to (double)
InventoryReStockFee=Double.parseDouble(InventoryReStockFee);
^
9 errors
Process completed.
/Inventory.java
import javax.swing.JOptionPane;
import java.util.Arrays;
import java.io.PrintStream;
import java.text.NumberFormat;
import java.util.Scanner;
public class Inventory
{
/*Prompts user to make another selection or exit program*/
private static final String YES = "Y";
/*parameters defining maximun numbers of products available for storing in */
private static final int MAX_NUM_OF_PRODUCTS = 100;
/*Declaration of products[] and the maximum storing capacity*/
private Product products[] = new Product[MAX_NUM_OF_PRODUCTS];
private int numProducts = 0;
public static String getInputValue(Scanner scanner, String prompt)
{/*Constructor defining the input and output values*/
String inputValue = null;
System.out.println(prompt);
inputValue = scanner.next();
return inputValue;
}
/*Means to request and display user input*/
public void inputProductInfo()
{ /*Default value prompt to enter new product or terminate program*/
String answer = YES;
/*Declaration of the Scanner for IO means*/
Scanner input = new Scanner(System.in);
/*Condition statement*/
for (int i = 0; (YES.equalsIgnoreCase(answer) && (i < MAX_NUM_OF_PRODUCTS)); i++)
{
String name = name;
name = JOptionPane.showInputDialog("Enter the products name");
/*means for creating white space*/
System.out.println();
/*Declaration of variable "ID" to ID product(s) of the Inventory*/
String id = id;
id = JOptionPane.showInputDialog("Enter the products ID");
/*means for creating white space*/
System.out.println();
/*Declaration of variable "UNITS" relative to product(s) nStock*/
String units= units;
units=JOptionPane.showInputDialog("Enter units in stock");
units = Double.parseDouble( units);
/*means for creating white space*/
System.out.println();
/*Declaration of variable "PRICE"- UNIT PRICE of Stock*/
String price = price;
price = Double.parseDouble(price);
price=JOptionPane.showInputDialog("Enter the products price", JOptionPane.PLAIN_MESSAGE);
System.out.println(); /*means for creating white space*/
String ProductValue = ProductValue;/*Means for calculating product value*/
ProductValue = JOptionPane.showMessageDialog("Product grand total value ");
System.out.println(); /*means for creating white space*/
String ReStkFee = ReStkFee;/*means for calculating reStockingFee*/
/*Means for displaying restocking fee of units of product*/
ReStkFee =JOptionPane.showMessageDialog("Product restocking fee");
System.out.println();/*means for creating white space*/
DecimalFormat Currency=new DecimalFormat("0.00");
/*Means for stringing variables elements of products[i]*/
products[i] = new Product(id, name, units, price, ProductValue, ReStkFee);
++numProducts;
/*Prompt display for user input*/
answer = getInputValue(input, "Would you like to enter another product? [Y/N]: ");
}/*End for statment*/
}/*End of input variables*/
/*Beginning of the display input data utilizing PrintStream*/
public void displayProductInfo(PrintStream ps)
{ /*Initialization of the variable total inventory value*/
String InventoryValue = InventoryValue;
InventoryValue=Double.parse(InventoryValue );
/*Initialization of the variable total inventory value reStock fee*/
double InventoryReStockFee =InventoryReStockFee;
InventoryReStockFee=int.parse(InventoryReStockFee);
/*Condition statement*/
for (int i = 0; i < numProducts; ++i)
{*null pointer defining product[i] values*/
if (products[i] != null)
{*Means for printing product[i]total inventory value*/
ps.println(products[i]);
/*Means for defining the get method for TtlInventoryValue in [i]*/
InventoryValue += products[i].getProductValue();
/*Means for defining the get method for TtlInventoryValue reStock fee in [i]*/
InventoryReStockFee += products[i].getInventoryReStockFee();
}
/*Means for displaying the value of the the TtlIventoryValue reStocking fee*/
ps.println("Total Inventory reStocking fee: " + Product.MONEY_FORMAT.format(InventoryReStockFee));
/*Means for displaying the value of the the TtlIventoryValue*/
ps.println("Total Inventory Value: " + Product.MONEY_FORMAT.format(InventoryValue));
JOptionPane.showMessageDialog("Total Inventory Value" + DecimalFormat(InventoryValue), JOptionPane.PLAIN_MESSAGE);
}
}/*Beginning of method main*/
public static void main(String[] args)
{/*Message*/
System.out.print("Welcome to the Inventory Program\n");
/*Means for creating white space*/
System.out.println();
/*Means for retrieving and storing new data input into inventory program*/
Inventory inventory = new Inventory();
inventory.inputProductInfo();
inventory.displayProductInfo(System.out);
}
}
class Product
{
/*Declaration of and default value of specified variables*/
public static final NumberFormat MONEY_FORMAT = NumberFormat.getCurrencyInstance();
private static final String DEFAULT_ID = "NO ID";
private static final String DEFAULT_NAME = "NO PRODUCTNAME";
/*Declaration of the variables in class Product*/
private String id;
String name;
private double units;
private double price;
private double ProductValue;
private double ReStkFee;
/*Default value of the string Product array*/
Product()
{/*Default value of the string Product*/
this(DEFAULT_ID, DEFAULT_NAME, 0.0, 0.0, 0.0, 0.0);
}
/*Element of the string Product array*/
Product(String id, String name, double units, double price, double ProductValue, double ReStkFee)
{/*Means for setting the variables of the string*/
this.setId(id);
this.setName(name);
this.setUnits(units);
this.setPrice(price);
this.setProductValue(ProductValue);
this.setReStkFee(ReStkFee);
}
/*method defining the get and set values of each individual variable*/
public String getName()
{/*Mean for storing and retrieving input of name*/
return name;
}/*Means for setting the product name*/
public void setName(String name)
{/*null pointer argument exception defining metod for obtainng product name*/
if (name == null)
/*Error message displayed to user referencing invalid input*/
throw new IllegalArgumentException("name cannot be null");
this.name = name;
}/*Means for getting the units identifcation number inputted by the user*/
public String getId()
{/*Means for returning the user input*/
return id;
}/*Means for setting the units identifcation */
public void setId(String id)
{/*null pointer argument exception for setting the product identification number*/
if (id == null)
/*Error message displayed to user referencing invalid input*/
throw new IllegalArgumentException("id cannot be null");
this.id = id;
}/*Means for getting the units value input*/
public double getUnits()
{/*Means for returning the variable of the units*/
return units;
}/*Means for setting the units value*/
public void setUnits(double units)
{/*null pointer argument exception*/
if (units < 0.0)
/*Error message displayed to user referencing invalid input*/
throw new IllegalArgumentException("units cannot be negative");
this.units = units;
}/*Means for getting price of the units in nStock*/
public double getPrice()
{/*Means for returning the dollar value of the price of the unit(s)*/
return price;
}/*Means for setting and requesting user to input + dollar amt*/
public void setPrice(double price)
{/*null pointer argument exception*/
if (price < 0.0)
/*Error message displayed to user referencing invalid input*/
throw new IllegalArgumentException("price cannot be negative");
this.price = price ;
}/*Means for setting the value of the total product value*/
public void setProductValue(double Value)
{/*Means for computing the total value of the units of the product(s)*/
this.ProductValue = units*price;
}/*Means for getting the value of the product*/
public double getProductValue()
{/*Means for returning the value*/
return ProductValue;
}/*Means for getting the TtlInventoryValue of products entered*/
public double getInventoryValue()
{/*Means for returning the value*/
return ProductValue;
}
public double getInventoryReStockFee()
{
return ReStkFee;
}
/*Means for setting restockin fee of the total products*/
public void setReStkFee(double ReStkFee)
{/*Means for calculating the restocking fee of each products units nStock*/
this.ReStkFee += price*1.05
;
}/*Means for getting the fee*/
public double getReStkfee()
{/*Means for returning the restocking fee of the product(s)*/
return ReStkFee;
}/*Method for string the elements in [i] for display*/
public String toString()
{*Means for returning defined string of elements in [i]*/
return "Product{" +
"id="+ id +
", name="+ name +
", units="+ units +
", price="+ MONEY_FORMAT.format(price) +
", ProductValue="+ MONEY_FORMAT.format(ProductValue) +
", ReStkFee="+ MONEY_FORMAT.format(ReStkFee) +
'}';
}/*End set and get method*/
}/*End of class Product*/
public class sortproductNames implements Comparable
{
protected String name;
public sortproductNames()
{
}
public void setName(String name)
{
this.name = name;
}
public String getname()
{
return name;
}
public int compareTo(Object object)
{ // for sorting by product name
Product anotherProduct = (Product) object;
return name.compareTo( anotherProduct.name);