0

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();
    }
}
SadNoob
  • 5
  • 3

2 Answers2

3

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.

Community
  • 1
  • 1
Kirby
  • 3,649
  • 3
  • 26
  • 28
  • I think I did this correctly just getting one error now. I updated my question with the one compile error. – SadNoob Apr 13 '13 at 04:50
  • What is on line 12 of InventoryPro2.java? – Kirby Apr 13 '13 at 04:57
  • I also just updated the code to reflect the changes I made. Still getting the same compile error. Trying to look it up via google/youtube/ other help sites has been my all day event and not finding answers very quickly. – SadNoob Apr 13 '13 at 05:08
  • Remove this line: `MobilePhoneObject.MobilePhone();` – Kirby Apr 13 '13 at 05:11
  • By the way, with the code in separate files, I don't know if you're still using the packages, but the casing is different on the package declarations. – Kirby Apr 13 '13 at 05:12
  • Meaning the source code not containing the main should have a different package name? – SadNoob Apr 13 '13 at 05:21
  • Bingo. Just realized you meant they were different and shouldn't be. Corrected that and I have a running program. Thank you very much for the help. Might actually get my assignment in on time after all. – SadNoob Apr 13 '13 at 05:27
0

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.

UltraInstinct
  • 43,308
  • 12
  • 81
  • 104
  • java.lang.NoClassDefFoundError: inventorypro2/InventoryPro2 (wrong name: InventoryPro2/InventoryPro2) at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631) at java.lang.ClassLoader.defineClass(ClassLoader.java:615) at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141) at java.net.URLClassLoader.defineClass(URLClassLoader.java:283) at java.net.URLClassLoader.access$000 – SadNoob Apr 13 '13 at 03:56
  • sorry for formatting couldn't get it all to fit. That's about half of the errors I got but nothing showing red on source editor. (using netbeans). – SadNoob Apr 13 '13 at 03:57
  • Also didn't have a comment to go with that mess did I? those are the compile errors I get after correcting the above mistake. – SadNoob Apr 13 '13 at 03:57
  • @user2276604 Update your original question with those errors. Include all the relevant descriptions, only then we can help you.. – UltraInstinct Apr 13 '13 at 04:00
  • I added a comment to my answer above, user2276604. – Kirby Apr 13 '13 at 04:06