Can't get this to compile, what am I doing wrong?
OK so I can see the "setUniqueType" on line 33 and the "ItemDetails" on line 50 are what need to be corrected, but I can't figure out what's wrong with it and how to fix it. Please help so I can move in with my program...
MAIN
package inventory4;
import java.util.Scanner;
import java.util.Arrays;
import javax.swing.JOptionPane;
public class RunApp
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
ItemDetails theItem = new ItemDetails();
int number;
String Name = "";
String Type = "";
String sNumber = JOptionPane.showInputDialog(null,"How many items are to be put into inventory count?: ");
number = Integer.parseInt(sNumber);
ItemDetails[] inv = new ItemDetails[number];
for (int count = 0; count < inv.length; ++count)
{
Name = JOptionPane.showInputDialog(null,"What is item " + (count + 1) + "'s name?");
theItem.setName(Name);
Type = JOptionPane.showInputDialog(null,"Enter " + Name + "'s product type");
theItem.setUniqueType(Type);
String spNumber = JOptionPane.showInputDialog(null,"Enter " + Name + "'s product number");
double pNumber = Double.parseDouble(spNumber);
theItem.setpNumber(pNumber);
String sUnits = JOptionPane.showInputDialog(null,"How many " + Name + "s are there in inventory?");
double Units = Double.parseDouble(sUnits);
theItem.setUnits(Units);
String sPrice = JOptionPane.showInputDialog(null,Name + "'s cost");
double Price = Double.parseDouble(sPrice);
theItem.setPrice(Price);
inv[count] = new ItemDetails(Name, Price, Units, pNumber, Type);
}
for (int i = 0; i < inv.length; ++i)
{
JOptionPane.showMessageDialog(null, "Product Name" + inv[i].getName());
JOptionPane.showMessageDialog(null, "Product Type" + inv[i].getUniqueType());
JOptionPane.showMessageDialog(null, "Product Number" + inv[i].getpNumber());
JOptionPane.showMessageDialog(null, "Amount of Units in Stock" + inv[i].getUnits());
JOptionPane.showMessageDialog(null, "Price per Unit" + inv[i].getPrice());
JOptionPane.showMessageDialog(null, String.format("Total cost for %s in stock: $%.2f", inv[i].getName(), inv[i].calculateTotalPrice()));
JOptionPane.showMessageDialog(null,String.format("Restocking fee for %s is $%.2f", inv[i].getName(), inv[i].calculateRestock()));
String combinedData = inv[i].toString();
if(i == (inv.length -1)){
String lastItem = String.format("\nTotal Cost for all items entered: $%.2f\n", Items.getCombinedCost(inv));
combinedData = combinedData + lastItem;
JOptionPane.showMessageDialog(null, combinedData);
}else{
JOptionPane.showMessageDialog(null, combinedData);
}
} //end for
} //end main
} //end class
ITEMS
package inventory4;
public class Items implements Comparable
{
private String Name;
public double pNumber, Units, Price;
String allInfo;
public Items()
{
Name = "";
pNumber = 0.0;
Units = 0.0;
Price = 0.0;
}
public int compareTo(Object item)
{
Items tmp = (Items)item;
return this.getName().compareTo(tmp.getName());
} // end compareTo method
public Items(String productName, double productNumber, double unitsInStock, double unitPrice)
{
Name = productName;
pNumber = productNumber;
Units = unitsInStock;
Price = unitPric开发者_运维问答e;
}
public String toString()
{
StringBuffer allInfo = new StringBuffer();
allInfo.append(String.format("Name: %s\n pNumber: %.0f \n Units: %.0f \n Price: %.2f\n",
getName(),getpNumber(),getUnits(),getPrice()));
return allInfo.toString();
}
//setter methods
public void setName(String n)
{
Name = n;
}
public void setpNumber(double no)
{
pNumber = no;
}
public void setUnits(double u)
{
Units = u;
}
public void setPrice(double p)
{
Price = p;
}
//getter methods
public String getName()
{
return Name;
}
public double getpNumber()
{
return pNumber;
}
public double getUnits()
{
return Units;
}
public double getPrice()
{
return Price;
}
public double calculateTotalPrice()
{
return (Units * Price);
}
public static double getCombinedCost(Items[] item)
{
double combined = 0;
for (int i = 0; i < item.length; ++i)
{
combined = combined + item[i].calculateTotalPrice();
} //end loop
return combined;
} //end method
} //end class
ITEM DETAILS
package inventory4;
public class ItemDetails extends Items
{
private String UniqueType;
public ItemDetails()
{
super();
}
public String enterUniqueType()
{
return UniqueType;
}
public String getUniqueType()
{
return UniqueType;
}
public double calculateRestock() //setting up to calculate the restocking fee at 5%
{
return (Price * .05);
}
}
Compile errors:
RunApp.java:31: cannot find symbol
symbol : method setUniqueType(java.lang.String)
location: class ItemDetails
theItem.setUniqueType(Type);
^
RunApp.java:48: cannot find symbol
symbol : constructor ItemDetails(java.lang.String,double,double,double,java.lan
g.String)
location: class ItemDetails
inv[count] = new ItemDetails(Name, Price, Units, pNumber, Type);
^
2 errors
- Your ItemDetails class has no setUniqueType method. You should add one.
- The constructor you're using at :48 is "String, double, double, double, String" but your constructor is really only "String double double double" Either remove
Type
or add a String parameter to the end of your Item constructor, or make an ItemDEtails constructor with the five parameters. - Your ItemDetails has no constructor that matches that argument. If you want to chain the constructor, declare it in ItemDetails
Chaining the constructor:
public ItemDetails(String productName, double productNumber, double unitsInStock, double unitPrice
super(productName,productNumber,unitsInStock,unitPrice);
}
Regarding ItemDetails: it looks like your ItemDetails constructor, inherited from Items, takes only 4 args and you're passing it 5.
精彩评论