desperate need of help fixing code?!?!

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

    desperate need of help fixing code?!?!

    i have tried everything but i keep getting these errors: illegal start of expression public Dvd()...and there's an arrow pointing under the p. the other error is: javalang.nosuch methoderror.mai n exception in main thread.

    i am providing my code so its not like im asking anyone to do it all for me...only to correct my mistakes cuz apparently i dont know what im doing or im not doing something right.

    by the way im using jcreator for this program.

    package dvdinventory;

    public class Dvd {

    public static void main(String[] args) {

    String productNumber;
    String itemName;
    int numberofUnits;
    double priceperUnit;

    public Dvd()
    {
    productNumber = "0";
    itemName = "";
    numberofUnits = 0;
    priceperUnit = 0.0;
    }

    public Dvd(String productNum, String productName, int quantity, double unitPrice)
    {
    productNumber = productNum;
    itemName = productName;
    numberofUnits = quantity;
    priceperUnit = unitPrice;
    }

    public String getProductNumbe r()
    {
    return productNumber;
    }

    public String getProductName( )
    {
    return itemName;
    }

    public int getNumberofUnit s()
    {
    return numberofUnits;
    }

    public double getPricePerUnit ()
    {
    return priceperUnit;
    }
    }
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    You can't define a method within another method; first close your main() { ... }
    method and only then define another one.

    kind regards,

    Jos

    Comment

    • Kiamari
      New Member
      • Nov 2007
      • 17

      #3
      Originally posted by JosAH
      You can't define a method within another method; first close your main() { ... }
      method and only then define another one.

      kind regards,

      Jos
      i think it is closed....if not, where do i close it?

      Comment

      • Laharl
        Recognized Expert Contributor
        • Sep 2007
        • 849

        #4
        Remove main() and its associated curly braces (one right after, one at the end) and make those Strings/doubles private. They are the instance variables (aka private data) for your class, the information that all DVDs have.

        Comment

        • Kiamari
          New Member
          • Nov 2007
          • 17

          #5
          Originally posted by Laharl
          Remove main() and its associated curly braces (one right after, one at the end) and make those Strings/doubles private. They are the instance variables (aka private data) for your class, the information that all DVDs have.
          i did some editing...so here is what i have so far:

          package dvdinventory;

          public class Dvd {

          private String productNumber;
          private String itemName;
          private int numberofUnits;
          private double priceperUnit;

          public Dvd(String "0", String "", int 0, double 0.0)
          {
          productNumber = "0";
          itemName = "";
          numberofUnits = 0;
          priceperUnit = 0.0;
          }

          public Dvd(String productNum, String productName, int quantity, double unitPrice)
          {
          productNumber = productNum;
          itemName = productName;
          numberofUnits = quantity;
          priceperUnit = unitPrice;
          }

          public String getProductNumbe r()
          {
          return productNumber;
          }

          public String getProductName( )
          {
          return itemName;
          }

          public int getNumberofUnit s()
          {
          return numberofUnits;
          }

          public double getPricePerUnit ()
          {
          return priceperUnit;
          }
          }


          NOW there are 3 errors:
          <identifier> expected
          public Dvd(String "0", String "", int 0, double 0.0)
          <identifier> expected
          public Dvd(String "0", String "", int 0, double 0.0)
          <identifier> expected
          public Dvd(String "0", String "", int 0, double 0.0

          arrow pointing after String before 0 in the first error, arrow pointing after String before "" in second error, and an arrow pointing after double before 0.0 in last error ?????

          help?!?!

          Comment

          • r035198x
            MVP
            • Sep 2006
            • 13225

            #6
            Originally posted by Kiamari
            sorry, havent a clue what youre talking about either??
            For starters every opening brace must have a corresponding closing brace. Your opening brace for your main method does not have a corresponding closing brace.
            Or maybe, do you know what the main method is?

            Comment

            • JosAH
              Recognized Expert MVP
              • Mar 2007
              • 11453

              #7
              @OP: (Kiamari): how come you've got your parentheses right in this thread but you're
              complaining about this matter overhere? Don't double post; it confuses your readers
              here and they will less likely respond to your chaotic questions.

              kind regards,

              Jos

              Comment

              • Kiamari
                New Member
                • Nov 2007
                • 17

                #8
                Originally posted by JosAH
                @OP: (Kiamari): how come you've got your parentheses right in this thread but you're
                complaining about this matter overhere? Don't double post; it confuses your readers
                here and they will less likely respond to your chaotic questions.

                kind regards,

                Jos
                it's not a double post...that's a seperate file i was having trouble with also

                Comment

                • JosAH
                  Recognized Expert MVP
                  • Mar 2007
                  • 11453

                  #9
                  Originally posted by Kiamari
                  it's not a double post...that's a seperate file i was having trouble with also
                  No, you just are having compilation problems; please stick to one thread.

                  kind regards,

                  Jos

                  Comment

                  Working...