java errors - what does this mean??

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Kiamari
    New Member
    • Nov 2007
    • 17

    java errors - what does this mean??

    class, interface, or enum expected
    DVD CLASS
    ^

    class, interface, or enum expected
    DVDINVENTORY CLASS
    ^

    HOW DO I FIX THESE TWO ERRORS WITHOUT GETTING OTHER ERRORS???

    here is my code:

    DVD CLASS


    public class Dvd {

    private String productNumber;
    private String itemName;
    private int numberOfUnits;
    private double pricePerUnit;

    public Dvd(String prodNo, String name, int noUnits, double price) {
    productNumber = prodNo;
    itemName = name;
    numberOfUnits = noUnits;
    pricePerUnit = price;
    }

    public String getProductNumbe r() { return productNumber; }
    public String getItemName() { return itemName; }
    public int getNumberOfUnit s() { return numberOfUnits; }
    public double getPricePerUnit () { return pricePerUnit; }

    public double calculateInvent oryValue() {
    return numberOfUnits*p ricePerUnit;
    }

    }


    DVDINVENTORY CLASS


    import java.util.Scann er;

    public class DvdInventory {

    public static void main(String[] args) {
    int SIZE = 100;
    Dvd[] myDvds = new Dvd[SIZE];
    int numberOfDvds = 0;
    while (numberOfDvds < SIZE) {
    Dvd dvd = readDvd();
    if(dvd == null) { break; }
    myDvds[numberOfDvds++] = dvd;
    }
    for(Dvd dvd : myDvds) { System.out.prin tln(dvd); }
    System.out.prin tln("Value of Inventory: $ "+calculateInve ntoryValue(myDv ds));
    }

    private static Dvd readDvd() {
    Scanner in = new Scanner(System. in);
    System.out.prin t("Enter item name or \"quit\" to stop: ");
    String itemName = in.nextLine();
    if(itemName.equ alsIgnoreCase(" quit")) { return null; }
    System.out.prin t("Enter product number: ");
    String productNumber = in.nextLine();
    System.out.prin t("Enter number of units: ");
    int numberOfUnits = in.nextInt();
    System.out.prin t("Enter price per unit: ");
    double pricePerUnit = in.nextDouble() ;
    return new Dvd(productNumb er,itemName,num berOfUnits);
    }

    private static double calculateInvent oryValue(Dvd[] dvds) {
    double result = 0;
    for(Dvd dvd : dvds) { result += dvd.calculateIn ventoryValue(); }
    return result;
    }

    }
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    Originally posted by Kiamari
    here is my code:

    [code=java]
    DVD CLASS
    [/code]
    I think you should get rid of that preamble. Why did you prepend it to your source
    code in the first place?

    kind regards,

    Jos

    Comment

    • Kiamari
      New Member
      • Nov 2007
      • 17

      #3
      Originally posted by JosAH
      I think you should get rid of that preamble. Why did you prepend it to your source
      code in the first place?

      kind regards,

      Jos
      im new to java...umm i dont know what you mean??

      Comment

      • JosAH
        Recognized Expert MVP
        • Mar 2007
        • 11453

        #4
        Originally posted by Kiamari
        im new to java...umm i dont know what you mean??
        Remove the lines "DVD CLASS" and "DVDINVENTO RY CLASS".

        kind regards,

        Jos

        Comment

        • Kiamari
          New Member
          • Nov 2007
          • 17

          #5
          Originally posted by JosAH
          Remove the lines "DVD CLASS" and "DVDINVENTO RY CLASS".

          kind regards,

          Jos
          ok, so i did what you said about removing the two lines and now i get these errors:

          in the build output window it says: class, interface, or enum expected
          import java.util.Scann er;
          ^
          1 error

          in the general output window it says: java.lang.NoCla ssDefFoundError : DvdInventory
          Exception in thread "main"
          Process completed.

          now how do i fix these two errors?

          it seems when i try to fix errors...others occur...*sighs* .....is my code not right or something????

          Comment

          • JosAH
            Recognized Expert MVP
            • Mar 2007
            • 11453

            #6
            Originally posted by Kiamari
            it seems when i try to fix errors...others occur...*sighs* .....is my code not right or something????
            I don't know about 'or something' but your code is definitely not right; if the compiler
            can't find the Scanner class you either have an old version of Java (older than 1.5)
            of you have an installation problem. The other error is just because you wanted
            to run a class that didn't even properly compile. You should check your Java
            version and if needed upgrade and try again.

            kind regards,

            Jos

            Comment

            • r035198x
              MVP
              • Sep 2006
              • 13225

              #7
              Originally posted by Kiamari
              ok, so i did what you said about removing the two lines and now i get these errors:

              in the build output window it says: class, interface, or enum expected
              import java.util.Scann er;
              ^
              1 error

              in the general output window it says: java.lang.NoCla ssDefFoundError : DvdInventory
              Exception in thread "main"
              Process completed.

              now how do i fix these two errors?

              it seems when i try to fix errors...others occur...*sighs* .....is my code not right or something????
              Out of interest, eh, where had you placed this import statement? What were the first, say, five lines of the code that gave that error?

              Comment

              • Kiamari
                New Member
                • Nov 2007
                • 17

                #8
                Originally posted by JosAH
                I don't know about 'or something' but your code is definitely not right; if the compiler
                can't find the Scanner class you either have an old version of Java (older than 1.5)
                of you have an installation problem. The other error is just because you wanted
                to run a class that didn't even properly compile. You should check your Java
                version and if needed upgrade and try again.

                kind regards,

                Jos
                its definitely not my java version or installation. i have the latest version 6.0...and the other day i had a program to run perfect.... the problem is somewhere in my code and i just cant figure it out...so i came here in hopes that someone could point me in the right direction or tell me what i have to remove for the code to work.....but it seems everything someone says to remove...anothe r error happens......i thought that providing my code someone could see where i have a few things misplaced or tell me if im missing something....si nce my code is "definitely not right"..i thought you knew what i had to do to make it "right"

                Comment

                • Kiamari
                  New Member
                  • Nov 2007
                  • 17

                  #9
                  Originally posted by r035198x
                  Out of interest, eh, where had you placed this import statement? What were the first, say, five lines of the code that gave that error?

                  sorry, i dont know what you are asking. after running my code that's the error i get.....for my full code take a look at the previous posts.

                  Comment

                  • r035198x
                    MVP
                    • Sep 2006
                    • 13225

                    #10
                    Originally posted by Kiamari
                    sorry, i dont know what you are asking. after running my code that's the error i get.....for my full code take a look at the previous posts.
                    There are some characters/words in your .java file that are not part of the code that you want to execute. e.g the line with DVD CLASS.
                    That is not part of the code and must be removed or commented out. The compiler should see only valid Java statements.

                    Comment

                    • JosAH
                      Recognized Expert MVP
                      • Mar 2007
                      • 11453

                      #11
                      Originally posted by Kiamari
                      sorry, i dont know what you are asking. after running my code that's the error i get.....for my full code take a look at the previous posts.
                      Post the first few lines of that second source file. There must be some text before
                      the "import java.util.Scann er;" line. And yes, we know what we're talking about
                      but you're frantically kicking around here and you don't understand our hints and
                      answers; just stay calm.

                      kind regards,

                      Jos

                      Comment

                      • Kiamari
                        New Member
                        • Nov 2007
                        • 17

                        #12
                        Originally posted by JosAH
                        Post the first few lines of that second source file. There must be some text before
                        the "import java.util.Scann er;" line. And yes, we know what we're talking about
                        but you're frantically kicking around here and you don't understand our hints and
                        answers; just stay calm.

                        kind regards,

                        Jos

                        there's no text before import.java.uti l.scanner line....what you saw above was my full code.....until i was told to remove the lines with DVD CLASS and DVD INVENTORY....i reposted the code again with the errors i got after removing those lines.....

                        btw: i am calm...just waiting for the right answer/help...thats all...

                        Comment

                        • r035198x
                          MVP
                          • Sep 2006
                          • 13225

                          #13
                          Originally posted by Kiamari
                          there's no text before import.java.uti l.scanner line....what you saw above was my full code.....until i was told to remove the lines with DVD CLASS and DVD INVENTORY....i reposted the code again with the errors i got after removing those lines.....

                          btw: i am calm...just waiting for the right answer/help...thats all...
                          Are you going to post the first few lines of your current code then?
                          The last code you posted in this thread still has those DVD CLASS things in them.

                          Comment

                          Working...