Results 1 to 18 of 18
Thread: Help in wiritng class.
- 02-14-2011, 05:43 AM #1
Member
- Join Date
- Feb 2011
- Posts
- 9
- Rep Power
- 0
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);
}
}
- 02-14-2011, 05:56 AM #2
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?
GoldestJava Is A Funny Language... Really!.gif)
Click on * and add to member reputation, if you find their advices/solutions effective.
-
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.
- 02-14-2011, 06:27 AM #4
Member
- Join Date
- Feb 2011
- Posts
- 9
- Rep Power
- 0
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.
- 02-14-2011, 06:29 AM #5
- 02-14-2011, 06:38 AM #6
Member
- Join Date
- Feb 2011
- Posts
- 9
- Rep Power
- 0
[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]
- 02-14-2011, 06:43 AM #7
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!.gif)
Click on * and add to member reputation, if you find their advices/solutions effective.
- 02-14-2011, 07:04 AM #8
Member
- Join Date
- Feb 2011
- Posts
- 9
- Rep Power
- 0

I am getting this error.
- 02-14-2011, 07:09 AM #9
Member
- Join Date
- Feb 2011
- Posts
- 9
- Rep Power
- 0
Here is the Project File I am using Netbeans
- 02-14-2011, 07:47 AM #10
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,385
- Blog Entries
- 7
- Rep Power
- 17
- 02-14-2011, 07:50 AM #11
Member
- Join Date
- Feb 2011
- Posts
- 9
- Rep Power
- 0
Could you please tell me how should I fix that?
- 02-14-2011, 08:00 AM #12
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,385
- Blog Entries
- 7
- Rep Power
- 17
They're easy to fix:
Read it carefully and see what changes I made. Don't just copy/paste and compile it and start yelling in delight.Java Code:public boolean equals(BottleClass pBottle) { return theNumber == pBottle.theNumber; } public String toString() { return "This number is: "+theNumber; }
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 02-14-2011, 12:10 PM #13
Member
- Join Date
- Feb 2011
- Posts
- 9
- Rep Power
- 0
Thanks man.
but I am still getting the following error. After analyzing for hours I need help again.

- 02-14-2011, 12:13 PM #14
Member
- Join Date
- Feb 2011
- Posts
- 9
- Rep Power
- 0
I need help urgently today. plz help me in fixing these errors.
- 02-14-2011, 12:26 PM #15
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,385
- Blog Entries
- 7
- Rep Power
- 17
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,
JosLast edited by JosAH; 02-14-2011 at 02:30 PM.
When people rob a bank they get a penalty; when banks rob people they get a bonus.
- 02-14-2011, 12:40 PM #16
Member
- Join Date
- Feb 2011
- Posts
- 9
- Rep Power
- 0
it says the following error in 24, 27, 29 and 30.

but when I click on it. It create the following at the bottom
same thing with in 31 to 36 line but with add method.Java Code:private void read() { throw new UnsupportedOperationException("Not yet implemented"); } }
- 02-14-2011, 12:55 PM #17
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,385
- Blog Entries
- 7
- Rep Power
- 17
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,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 02-14-2011, 01:54 PM #18
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
-
super class reference variable accesses overriding sub class method
By subith86 in forum New To JavaReplies: 5Last Post: 01-26-2011, 06:38 PM -
Dynamic loading of a class (passing class definition over the network)
By eddie-w in forum Advanced JavaReplies: 8Last Post: 04-14-2010, 05:49 AM -
[SOLVED] How to pass information from child class to parent class
By pellebye in forum New To JavaReplies: 7Last Post: 05-06-2009, 12:42 PM -
problem in accessing array values of one class in to jframe class
By cenafu in forum AWT / SwingReplies: 8Last Post: 03-21-2009, 09:34 AM -
Able to find class file in WEB-INF/classes but not after add sub folders in class dir
By vitalstrike82 in forum Web FrameworksReplies: 0Last Post: 05-13-2008, 06:16 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks