n/a
Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
n/a
Last edited by SaltSlasher; June 24th, 2024 at 03:10 AM.
You're getting an error on this line because you haven't defined a constructor with no arguments. By default and for each class you make, Java makes a constructor that takes no arguments. However, when you define a constructor with arguments in your class, the default constructor is no longer created (such as in your Ship class). In your Ship class, the only valid constructor is one that takes two arguments. So, to fix this, you could either create a second constructor in your Ship class or fix your line of code:it keeps putting an error on my "=" sign, for the line Ship myShip = new Ship();
Ship myShip = new Ship();
so that when you call the Ship() constructor you put in arguments.
Use highlight tags to help others help you!
[highlight=Java]Your prettily formatted code goes here[/highlight]
Using these tags makes your code formatted, and helps everyone answer your questions more easily!
Wanna hear something funny?
Me too.
No, no, no; not on your ShipTest class, in your Ship class. The only constructor that you have in your Ship class is one that takes two arguments, but you want to create a new Ship with no arguments. To do this, you have to create a constructor in your Ship class that has no arguments listed in it.
Use highlight tags to help others help you!
[highlight=Java]Your prettily formatted code goes here[/highlight]
Using these tags makes your code formatted, and helps everyone answer your questions more easily!
Wanna hear something funny?
Me too.
Hahahaha, thank you! I'm gathering that it works? ;D
By the way, sorry for the slow response; Minecraft is rather addicting.
Use highlight tags to help others help you!
[highlight=Java]Your prettily formatted code goes here[/highlight]
Using these tags makes your code formatted, and helps everyone answer your questions more easily!
Wanna hear something funny?
Me too.
Haha! Minecraft is pretty awesome.
So... Your problem is with the timeToCrossEnglishChannel() method. First of all, unless I'm mistaken, the PDF you provided said that this method won't take any arguments (which makes sense, because the Ship object stores the information for speed).
I don't remember the formula, but your PDF provided a conversion from knots to mph. Then, you'll need a little math:
rate = distance / time
If we rearrange that to solve for time (which we don't know; we do know distance -- 21 miles -- and rate -- the speed of the Ship object), we get this:
time = distance / rate
So, you need to convert your speed to mph, then divide the distance through the channel by the speed of the Ship.
As for you set methods, I don't see any issue. The return type you have coded is void, which is correct (set method's don't return anything, just set a value of an object's field). What is the problem?
[EDIT: I'm going to sleep for tonight. I'll check the thread tomorrow and offer more help if you still need it. Good luck!]
Last edited by snowguy13; February 12th, 2012 at 09:33 PM.
Use highlight tags to help others help you!
[highlight=Java]Your prettily formatted code goes here[/highlight]
Using these tags makes your code formatted, and helps everyone answer your questions more easily!
Wanna hear something funny?
Me too.
No, you don't need to do that. Speed is a private variable of Ship, which means only the Ship class can directly access it (that's why we need getters and setters, so other classes can still call the values of a Ship object). This also means that ANY method in your ship class can reference speed simply by you typing "speed," as you did in your getSpeed and setSpeed methods.
For example, look at this quick class
public class Numbers { private int numA; private int numB; //private, only THIS class can directly reference them //constructors, getters, setters; you know what they look like :P //Here's an example of a non-getter-setter method //like your English Channel method public int getSum() { return (numA + numB); //Note, I can still just directly use "numA" and "numB" //without any special set or get calls } }
Hopefully that makes things a little more clear?
Use highlight tags to help others help you!
[highlight=Java]Your prettily formatted code goes here[/highlight]
Using these tags makes your code formatted, and helps everyone answer your questions more easily!
Wanna hear something funny?
Me too.