Reputation: 5
Ok, seperated my code. Now when I run I am just getting one error as follows:
Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - Erroneous tree type: InventoryPro2.MobilePhone
at InventoryPro2.InventoryPro2.main(InventoryPro2.java:12)
Java Result: 1
What I took from previous replies was that I needed to move the MobilePhone class and the InventoryPro2 class into seperate .java files within the same project. Did I miss the point? As I said before I am brand new to this and it has been terrible trying to learn all of this at a rapid pace while learning another programming language at the same time. Thank you for the help thus far it is greatly appreciated.
package InventoryPro2;
public class InventoryPro2 {
public static void main(String args[]) {
MobilePhone MobilePhoneObject = new MobilePhone();
MobilePhoneObject.MobilePhone();
System.out.println("Mobile Phone Inventory");
System.out.println();//skips a line
MobilePhone[] Phones = new MobilePhone[5];
Phones[0] = new MobilePhone(1, "Motorola", "Electronics", 98, 150.00);
Phones[1] = new MobilePhone(2, "LG", "Electronics", 650, 199.99);
Phones[2] = new MobilePhone(3, "Samsung", "Electronics", 125, 200.25);
Phones[3] = new MobilePhone(4, "Nokia", "Electronics", 200, 100.05);
Phones[4] = new MobilePhone(5, "IPhone", "Electronics", 138, 125.75);
for (int count = 0; count < Phones.length-1; count++) {
System.out.printf("Product Number: %1f\n", Phones[count].getproductNumber());
System.out.printf("Product Name: %s\n", Phones[count].getname());
System.out.printf("Units In Stock: %.2f\n", Phones[count].getunitsInStock());
System.out.printf("Unit Price: $%4.2f\n", Phones[count].getunitPrice());
System.out.printf("Inventory Value: $%4.2f\n", Phones[count].gettotalInv());
System.out.println(); //blank line to seperate products
}
}
}
package inventorypro2;
class MobilePhone { // Create class to store values
private double productNumber; // Variables
private String name;
private String department;
private double unitsInStock;
private double unitPrice;
public MobilePhone() {
this(0.0, "", "", 0.0, 0.0);
}
public MobilePhone(double productNumber, String name, String department,
double unitsInStock, double unitPrice) { //assign variables
this.productNumber = productNumber;
this.name = name;
this.department = department;
this.unitsInStock = unitsInStock;
this.unitPrice = unitPrice;
}
public double getproductNumber() { // retrieve values
return productNumber;
}
public String getname() {
return name;
}
public String getdepartment() {
return department;
}
public double getunitPrice() {
return unitPrice;
}
public double getunitsInStock() {
return unitsInStock;
}
public void setproductNumber(double productNumber) {
this.productNumber = productNumber;
}
public void setname(String name) {
this.name = name;
}
public void setdepartment(String department) {
this.department = department;
}
public void setunitPrice(double unitPrice) {
this.unitPrice = unitPrice;
}
public void setunitsInStock(double unitsInStock) {
this.unitsInStock = unitsInStock;
}
public double gettotalInv() {
return getunitPrice() * getunitsInStock();
}
}
Upvotes: 0
Views: 152
Reputation: 3719
Phones[0] = count + 1;
The left is not an integer, but the right is an integer.
Regarding your most recent edit, I would suggest putting one class per file (and make them public).
Alternatively, make an inner class. But the file should have one outer class (doesn't have to be this way: Java: Multiple class declarations in one file), but I think it will make things simpler.
Upvotes: 3
Reputation: 44464
Phones[0] = count + 1;
What are you trying to do here? You are assigning an integer (int
type)to a MobilePhone (MobilePhone
type)! Remove that line, you'd be good to go.
Upvotes: 0