Results 1 to 18 of 18
  1. #1
    vt007 is offline Member
    Join Date
    Feb 2011
    Posts
    9
    Rep Power
    0

    Unhappy Help in wiritng class.

    So i have my 1st project due tommrow and im having some trouble creating a bottle class. here are the instructions

    Write a bottle class. The class has read(), set(int), set(bottle), add(bottle), subtract(bottle), multiply(bottle), divide(bottle), add(int), subtract(int), multiply(int), divide(int), equals(bottles), and toString() methods.

    here is the BotteDemo

    import java.util.Scanner;

    // test driver for the Bottle class

    public class BottleDemo
    {
    public static void main(String[] args)
    {
    Scanner scan = new Scanner(System.in);
    int x;
    Bottle bottle1 = new Bottle();
    Bottle bottle2 = new Bottle();
    Bottle bottle3 = new Bottle();
    Bottle bottle4 = new Bottle();
    Bottle bottleAve = new Bottle();
    System.out.println("please enter a number for bottle1:");
    bottle1.read();
    System.out.println("bottle1 is this value " + bottle1);
    System.out.println("please enter a number for bottle2:");
    bottle2.read();
    System.out.println("please enter a number for bottle3:");
    bottle3.read();
    System.out.println("please enter a number for bottle4:");
    bottle4.read();
    bottleAve = bottleAve.add(bottle1);
    bottleAve = bottleAve.add(bottle2);
    bottleAve = bottleAve.add(bottle3);
    bottleAve = bottleAve.add(bottle4);
    bottleAve = bottleAve.divide(4);
    System.out.println("the average of the 4 bottles is: " +
    bottleAve);
    if (bottle1.equals(bottle3))
    {
    System.out.println("bottle1 and bottle3 are equal");
    }
    else
    {
    System.out.println("bottle1 and bottle3 are not equal");
    }
    System.out.println("Eenter an integer to add to bottle 1");
    x = scan.nextInt();
    bottle1.add(x);
    System.out.println("adding your number " + x +
    " to bottle1 gives " + bottle1);
    bottle2 = bottle1.add(bottle3);
    System.out.println("adding the number + bottle3 + from
    bottle3 to bottle1 gives " + bottle2);
    }
    }

  2. #2
    goldest's Avatar
    goldest is offline Senior Member
    Join Date
    Oct 2009
    Location
    Pune, India
    Posts
    469
    Rep Power
    5

    Wink

    Will you please use Code Tags while posting your code?

    And what is your problem by the way? Have you stuck up somewhere in your code? Does it give you errors? Something else?

    Or you simply want someone here to complete this for you?

    Goldest
    Java Is A Funny Language... Really!
    Click on * and add to member reputation, if you find their advices/solutions effective.

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Agree with goldest that all you've posted was nothing more than a homework dump. Please ask a specific answerable question, not a "here's my code, fix it for me" type question.

  4. #4
    vt007 is offline Member
    Join Date
    Feb 2011
    Posts
    9
    Rep Power
    0

    Default

    I am new to Java. I simply didn't understand what to do with this assignment. The BottleDemo is provided by teacher.

    I need to write a Bottle class using this code.

  5. #5
    goldest's Avatar
    goldest is offline Senior Member
    Join Date
    Oct 2009
    Location
    Pune, India
    Posts
    469
    Rep Power
    5

    Wink

    Quote Originally Posted by vt007 View Post
    I need to write a Bottle class using this code.
    So what have you written so far?
    Java Is A Funny Language... Really!
    Click on * and add to member reputation, if you find their advices/solutions effective.

  6. #6
    vt007 is offline Member
    Join Date
    Feb 2011
    Posts
    9
    Rep Power
    0

    Default

    [code]
    public class BottleClass
    {
    int theNumber;

    BottleClass()
    {
    theNumber = 0;
    }

    void set(int pNumber)
    {
    theNumber = pNumber;
    }

    void set(BottleClass pBottle)
    {
    theNumber = pBottle.theNumber;
    }

    void add(BottleClass pBottle)
    {
    theNumber = theNumber + pBottle. theNumber;
    }

    void add(int pNumber)
    {
    theNumber = theNumber + pNumber;
    }

    void subtract(BottleClass pBottle)
    {
    theNumber = theNumber - pBottle.theNumber;
    }
    void subtract(int pNumber)
    {
    theNumber = theNumber - pNumber;
    }

    void multiply(BottleClass pBottle)
    {
    theNumber= theNumber * pBottle.theNumber;
    }

    void multiply(int pNumber)
    {
    theNumber = theNumber * pNumber;
    }

    void divide(BottleClass pBottle)
    {
    theNumber= theNumber / pBottle.theNumber;
    }

    void divide(int pBottle)
    {
    theNumber = theNumber / pBottle;
    }

    pBottle equals(BottleClass pBottle)
    {
    return theNumber == pBottle.number;
    }


    string toString()
    {
    return "This number is: " + theNumber;
    }

    }
    [code]

  7. #7
    goldest's Avatar
    goldest is offline Senior Member
    Join Date
    Oct 2009
    Location
    Pune, India
    Posts
    469
    Rep Power
    5

    Wink

    And, I am repeating myself... AGAIN. What is the problem you are facing in this code?

    Make sure to add a / in closing bracket of your [code]
    Java Is A Funny Language... Really!
    Click on * and add to member reputation, if you find their advices/solutions effective.

  8. #8
    vt007 is offline Member
    Join Date
    Feb 2011
    Posts
    9
    Rep Power
    0

    Default



    I am getting this error.

  9. #9
    vt007 is offline Member
    Join Date
    Feb 2011
    Posts
    9
    Rep Power
    0

    Default

    Here is the Project File I am using Netbeans

  10. #10
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,524
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by vt007 View Post
    I am getting this error.
    Those are just compilation errors:

    1) pBottle isn't a type;
    2) number isn't a (visible) member in the BottleClass;
    3) string with a lowercase 's' isn't a type.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  11. #11
    vt007 is offline Member
    Join Date
    Feb 2011
    Posts
    9
    Rep Power
    0

    Default

    Could you please tell me how should I fix that?

  12. #12
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,524
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by vt007 View Post
    Could you please tell me how should I fix that?
    They're easy to fix:

    Java Code:
    public boolean equals(BottleClass pBottle) {
       return theNumber == pBottle.theNumber;
    }
    
    public String toString() {
       return "This number is: "+theNumber;
    }
    Read it carefully and see what changes I made. Don't just copy/paste and compile it and start yelling in delight.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  13. #13
    vt007 is offline Member
    Join Date
    Feb 2011
    Posts
    9
    Rep Power
    0

    Default

    Thanks man.

    but I am still getting the following error. After analyzing for hours I need help again.




  14. #14
    vt007 is offline Member
    Join Date
    Feb 2011
    Posts
    9
    Rep Power
    0

    Default

    I need help urgently today. plz help me in fixing these errors.

  15. #15
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,524
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by vt007 View Post
    I need help urgently today. plz help me in fixing these errors.
    Those last two lines (line #76 and line #77) most certainly don't belong there; they are an artefact of a sloppy editing session and you could easily have seen that yourself. I don't know what the other errors are; click on the error indicator icon in the left margin and read for yourself.

    kind regards,

    Jos
    Last edited by JosAH; 02-14-2011 at 02:30 PM.
    cenosillicaphobia: the fear for an empty beer glass

  16. #16
    vt007 is offline Member
    Join Date
    Feb 2011
    Posts
    9
    Rep Power
    0

    Default

    it says the following error in 24, 27, 29 and 30.



    but when I click on it. It create the following at the bottom
    Java Code:
     private void read() {
            throw new UnsupportedOperationException("Not yet implemented");
        }
    }
    same thing with in 31 to 36 line but with add method.


  17. #17
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,524
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by vt007 View Post
    it says the following error in 24, 27, 29 and 30.



    but when I click on it. It create the following at the bottom
    Java Code:
     private void read() {
            throw new UnsupportedOperationException("Not yet implemented");
        }
    }
    That's easy then: your Bottle class doesn't have those methods implemented; NetBeans tries to fix those problems by inserting empty method definitions. You have to fix that yourself; i.e. nobody else knows what you had in mind with those methods. All the compiler can do is indicate that you haven't implemented those methods (with the correct visibility).

    Also, please read the user manual that comes with NetBeans; it explains what those icons and messages mean. Posting pictures of them here again and again slows down your debugging and fixing sessions.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  18. #18
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default

    I understand what its like to be new at programming (been there). With that in mind, might I humbly suggest asking questions and doing research before the day before its due?

    It seems to me from your comments that you have not carefully read the text[book] supplied with your course. I could be wrong, but I don't think your instructor sent you into this assignment blind.

    I strongly suggest that you read your reference material, and take really good notes (also, ask lots of questions in class/after class). If you fall behind here, you will not catch up by the end of the semester. I taught 240 and 241 level courses for a number of semesters, and believe me, if you don't put time into learning the syntax and know what the different parts of a program/language are, you will find yourself running in circles.

    Best of luck, I hope your project is a success!

Similar Threads

  1. Replies: 5
    Last Post: 01-26-2011, 06:38 PM
  2. Replies: 8
    Last Post: 04-14-2010, 05:49 AM
  3. Replies: 7
    Last Post: 05-06-2009, 12:42 PM
  4. Replies: 8
    Last Post: 03-21-2009, 09:34 AM
  5. Replies: 0
    Last Post: 05-13-2008, 06:16 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •