• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Jj Roberts
  • Tim Holloway
  • Piet Souris
Bartenders:
  • Himai Minh
  • Carey Brown
  • salvin francis

Write a public instance method called runExperiments() which takes no argument and returns no value

 
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The method should attempt to decrement powerLevel by a random number between 1 and 3 inclusive for each experiment up to numberOfExperiments. You should make use of the supplied helper method randomInteger() for this.

• If the powerLevel can be reduced, a message indicating the experiment number (starting at 1) should be displayed. If not, a suitable message should be displayed and remaining experiments should not be attempted.

• When all experiments have finished it should display "Experiment run stopped".

Write this method, choosing a suitable kind of loop to control the number of iterations required.

Hints:

1. Don't forget to make use of the return value from decrementPower().

2. Experiments should not yet run as the default value of powerLevel is 0.

Here is the full code:


follows with my attempt to this question: if someone can help me correct it. Much appreciated.


 
 
Marshal
Posts: 71026
291
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The power reduction method looks incorrect to me.
Your runExperiments() method doesn't appear to follow the instructions you were given.
 
lilly Rankine
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
that is why I need help?
 
lowercase baba
Posts: 12933
65
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We don't generally hand out solutions.  Many folk will bend over backwards to guide you, but you must do the heavy lifting.

Start off with telling us where exactly you are stuck.  Does this code compile?  Does it run?  Does it give output, or crash?  If it crashes, what exactly is the error messages?  If it gives output, what exactly does it give, is that different from what you are expecting, and if so, how?
 
lilly Rankine
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So basically I am not sure where I would put the 'each experiment numberOfExperiments' variable part. and the part if powerLevel can be reduced.. not sure how I would do that. I have done what I think is right but clearly it isnt.
 
Campbell Ritchie
Marshal
Posts: 71026
291
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

lilly Rankine wrote:. . . where I would put the 'each experiment numberOfExperiments' variable part. . . .

That is putting the cart before the horse. You need to work out what you are going to do before you try to work out how to do it. The names of variables don't enter the equation until you start implementing something.

Start by working out what you are trying to do.
 
Sheriff
Posts: 7108
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I corrected your code tags in the first post. The code is poorly formatted and doesn't compile (see HowToFormatCode, that's a link).

I believe this is what the code is supposed to look like.  See how much easier it is to read and understand:
 
Campbell Ritchie
Marshal
Posts: 71026
291
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am afraid another error has become legible in Knute's improved code; look at line 38.
 
Sheriff
Posts: 15989
265
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would back up and lay out the "story" of what you think should happen when you run this program.

For example:

1. First I create a SpaceRocket object.

How do I do that? -- I use the SpaceRocket() constructor
What are the parameters needed by this constructor? -- a name and the number of experiments to run
What would that look like as code? -- ... (you answer this)

2. Then we run the experiments.

How do I do that? -- I call the runExperiments() method
What parameters are needed by this method? -- none
What would be the initial value of powerLevel? -- (you figure out what makes sense)
What would that look like as code? -- (you answer this)

3. For each experiment up to the number of experiments (indicated when I created the SpaceRocket),
try to reduce the power.

How do I do that? ...

and so on

If you try to attack the whole problem all at once, you're just going to confuse yourself. When you're confused, then the code you write will be confused, which it is right now.
 
lilly Rankine
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
no I am totally lost. So if anyone can guide me or get me started great
 
Campbell Ritchie
Marshal
Posts: 71026
291
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Go and have a pint. Get some tea. Leave off programming until tomorrow.
 
fred rosenberger
lowercase baba
Posts: 12933
65
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
generally, when you are first starting, the best advice is to turn off your computer.  Get paper, pencil, and erasers.  start writing things out.  

ok..so this is the 21st century, so you can use something like notepad or whatever. The point is to NOT think in "java" but in English, and to literally write out the steps.  The act of putting words on paper forces your brain to think differently.

Once you have the lists and steps, you look at each and say "do I know how to easily convert that to java?"  If no, then go back and refine that step into smaller chunks...and repeat as many times as needed.

 
Campbell Ritchie
Marshal
Posts: 71026
291
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I still think in terms of pencil and paper. Of course a rubber is essential. Get a large one; you will be using it a lot. Just be careful where you fling it in frustration (not at me, please).
As Fred says, you can sue a WP or text editor, but there are much better editors than NotePad. If you are on Windows, my favourite would be NotePad++.
 
Junilu Lacar
Sheriff
Posts: 15989
265
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

lilly Rankine wrote:no I am totally lost. So if anyone can guide me or get me started great



Ok, here's how I would start it. Since a Java program runs from a main() method, what would the main() method look like? Probably something like this:

This would be its simplest form. This code suggests that there's a constructor for SpaceRocket that takes two parameters, a String and a number. You already have that, right? The string is the name and the number is the number of experiments to run. The next line calls the runExperiments() method to, well, start running the experiments.

Now here's where you have to put your brain to work. What should happen in the constructor? What should happen in the runExperiments() method? Try to tell the story at a very high level first. A lot of the story is already given to you in the requirements. You just need to lay things out in the proper logical sequence. Once you have a clear idea of the sequence of actions your program needs to take, then it's much easier to translate those ideas into code.

Here's a more complete skeleton of the program. Try running it to see what it does. Then start replacing the placeholder code with bits and pieces of the story you want to tell.
 
Junilu Lacar
Sheriff
Posts: 15989
265
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The trick to solving a programming problem quickly is, ironically, to go slowly. That is, don't try to write 50 lines of code at one go to solve a huge problem. Rather, break the huge problem down into lots of smaller problems and solve each of those one at a time. Each small problem should only take a few lines of code to solve.

For example, if you're trying to fill in the SpaceRocket() constructor, what small problem should you solve here? One small problem might be "How do I 'remember' the name of this new SpaceRocket object so that it can be displayed later from other methods?" The answer there is to save the parameter value in an instance field. How do you do that? I see you probably already know how to do that. It takes only two lines of additional code to do it.

Next, how do you "remember" the number of experiments to run? The solution is the same as the previous problem. Another two lines of code.

Every time you add a few lines of code to solve a small problem, you run the program to make sure you didn't mess anything up. Ideally, you'd run tests, but you probably haven't been taught how to do that. So for now, you just keep running the program every time you add a few lines of code to solve another small problem.

Then you just keep going that way, incrementally building up the program. The advantage of doing it this way is that if during one of these frequent runs, you find out that the program won't compile any more or it doesn't do what you expected it to do, you kind of know what lines of code you messed up because you've only been adding or changing one or two or three lines of code at a time.

This takes a lot of discipline but with practice, it soon becomes easier and with even more practice, it becomes a habit.
 
lilly Rankine
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Junilu Lacar

But it needs to start like this:

public void runExperiments()
since the question says to write and instance method as above with no arguments or return value. Now from there how would I continue? Many thanks
 
Knute Snortum
Sheriff
Posts: 7108
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to ShowSomeEffort (that's a link).  In this post, Junilu Lacar has shown you how to get started.  What problems are you running into?  
 
Junilu Lacar
Sheriff
Posts: 15989
265
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

lilly Rankine wrote:But it needs to start like this:

public void runExperiments()


No, it doesn't. You are misunderstanding the instructions and you are misunderstanding the structure of a Java class as well as how a Java program runs. It doesn't matter where that runExperiments() method is within the source. When you run a Java program, it always starts from the public static void main(String[] args) method of some class, that class being the argument of the java command given on the command line.
 
Junilu Lacar
Sheriff
Posts: 15989
265
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe there's more to this that you're not telling us.

How are you running the programs you're writing? With the code example I gave, you'd run it from the command line like this:

$ java SpaceRocket

If this isn't how you run your programs, then you need to tell us exactly how you do it so we have a better idea of the environment that you're using. Otherwise, we're going to assume that you're running the program the way I just showed above.
 
Junilu Lacar
Sheriff
Posts: 15989
265
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In your original post, you wrote "Here is the full code" followed by code for the SpaceRocket class. Did you write that code or was it given as part of the initial problem? I'm beginning to think it was part of the initial problem you were given. Is that correct? Meaning your task was simply to extend that code by adding a runExperiments method. This would mean that you'll need to answer my previous question of how you're running the program so we have a better idea of what's really going on here.
 
lilly Rankine
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wrote that code. ahh ok so I am not supposed to start with 'public void runExperiments()'. I thought because the question required that. What do I write in place of the placholder code?
 
Marshal
Posts: 7851
538
Mac OS X VI Editor BSD Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@OP

Why SpaceRocket constructor does not accept as the parameters powerLevel (this one maybe could be avoided) and maxPowerLevel? And the opposite question, why numberOfExperiments is part of constructor parameters list? numberOfExperiments I'd more expect to be part of runExperiments() method.

So the use of it could look similar to:

I'd find it more intuitive to use it that way as opposed to building-in the number of experiments to run during the rocket creation.
 
Campbell Ritchie
Marshal
Posts: 71026
291
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe that is a requirement for the exercise.
 
Junilu Lacar
Sheriff
Posts: 15989
265
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

lilly Rankine wrote:What do I write in place of the placholder code?


You would write code that would perform actions your program is required to take. What those are, you're going to have to figure out. Again, try to take this one bit at a time. Don't try to solve everything all at once.
 
Junilu Lacar
Sheriff
Posts: 15989
265
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Liutauras Vilda wrote:Why SpaceRocket constructor does not accept as the parameters powerLevel (this one maybe could be avoided) and maxPowerLevel? And the opposite question, why numberOfExperiments is part of constructor parameters list? numberOfExperiments I'd more expect to be part of runExperiments() method.


Reasonable questions, if you're thinking about good design. I don't think that's the point of this exercise though; the OP is still a beginner so I think the point is to learn about problem solving and organizing the solution.
 
Junilu Lacar
Sheriff
Posts: 15989
265
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm going to try to illustrate to OP using a slightly different problem.

Let's say that we want to simulate RaceCar instead. A RaceCar has a gas tank that can hold up to maxFuel units of gas. The car races on a closed track. Each time around the track is called a lap. When the car is racing, it will consume anywhere from 3 to 5 units of gas for every lap around the track that it completes. Completely at random, the car can make a pitstop to add more gas, except it can only add up to 2 units of gas during a stop, up to its maximum capacity. That is, if the car stops after having only used up 1 unit of gas, it will only be topped off with 1 unit instead of 2 units. If it has used 3 units of gas, the full 2 units allowed per stop will be used but it won't be able to add more until the next time it stops. Eventually, it's possible that the car will run out of gas in the middle of running a lap around the track.

The task is to simulate this race car running a race of N laps and see whether or not it completes the race or runs out of gas. Your program should display either "The race car runs out of gas on lap N and does not finish" where N is the lap number in which the car runs out of gas or "The race car finishes with N units of gas remaining" where N is the number of units of gas left in the tank.

I'll give you a chance to digest this before I show you how I would start solving this. See what kind of similarities this problem has with your SpaceRocket problem.
 
Junilu Lacar
Sheriff
Posts: 15989
265
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's how I'd start. It's not very different from what I showed you earlier with the SpaceRocket.

Smaller problems:
1. I need to create a RaceCar object. Let's say I tell the RaceCar what its name is and how much fuel capacity it has.
2. I need to tell the RaceCar to start running a race.
3. While running the race, the car needs to consume gas (3 to 5 units).
4. The car might stop for fuel after running a lap (or it might not).

I start with the first problem: creating a RaceCar with a name and maximum fuel capacity:


The first small problem has now been solved with just a few lines of code.

But I need to run the program so I can see that it works. So I add a main() method, like so:

I save this code in a file named RaceCar.java. Since Java 11, we can run a .java file directly instead of having to compile it first with the javac command and then running the program with the java command. Here what that would look like on the terminal:

$ java RaceCar.java
Created RaceCar Rankine with maximum fuel capacity of 25


The first line is the command I type in at the terminal. The second line is the output of the program.
 
Junilu Lacar
Sheriff
Posts: 15989
265
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Now the second problem: tell the car to start running the race. This is easy. I just add a method with some placeholder code and then call it from the main() method.

I save those changes and run the program again:

$ java RaceCar.java
Created RaceCar Rankine with maximum fuel capacity of 25
Running race...

Now I see the output from the runRace() method. I want to make sure the program completes properly, so I add another message in the main() method:

I save these changes and run the program again:

$ java RaceCar.java
Created RaceCar Rankine with maximum fuel capacity of 25
Running race...
Done.

Now I see the output from all the methods that are being executed: from invoking the constructor, the runRace() method, then the main() method's last line indicating the program run has completed.
 
Junilu Lacar
Sheriff
Posts: 15989
265
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Now we get to the question that's similar to the one Liutauras asked earlier: Should we pass a value to the runRace() method to tell it how many laps to run? Or should that be passed to the constructor? I'm going to opt for the former since it makes more sense to me. So I make some changes to the program:

Say I want to run 10 laps. So I change the call in the main() method:

I save these changes and run the program again:

$ java RaceCar.java
Created RaceCar Rankine with maximum fuel capacity of 25
Running race of 10 laps...
lap #0
lap #1
lap #2
lap #3
lap #4
lap #5
lap #6
lap #7
lap #8
lap #9
Done.

Now we're getting closer to the actual solution. By using placeholder code to display messages that hint at what the program is doing, I can begin to understand the flow of the program logic. This helps me figure out where I need to make changes to solve the next small problem I want to solve.
 
Junilu Lacar
Sheriff
Posts: 15989
265
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here I'm going to pause a minute to refactor. Refactoring is something I do to make sure the program expresses its intent as clearly as possible. That means I want to write the program in a way that the code makes a lot of sense to anyone reading it for the first time (or second or third). The easier it is to understand what the code is doing, the easier it will be to add more functionality to it and avoid making mistakes while doing so. Bugs in code are really a manifestation of a lack of understanding of what you're trying to make the program do.

One of the things that makes our code more difficult for other people (and even ourselves) to read and understand are poorly chosen names. In the last change I made, I chose the name raceLaps to indicate how many laps were supposed to be run in the race. I think we can do better.

So I try to tell the "story" of the runRace() in plain language: "I want to run a race for a total of N laps." Ok, so if that's the "story" I want the code to tell, maybe I should use the name totalLaps instead of raceLaps. Let's see what that looks like:

I think that's actually better and clearer. It may seem trivial but even a small, even trivial, clarification like this can help ease the cognitive load (the effort it takes to understand what you're looking at).

I save these changes and run the program again. Since I only changed the name of the parameter, the program should output the same thing it did before I changed raceLaps to totalLaps. I see that nothing has changed as far as the program output is concerned so I can proceed knowing that while I didn't add or change any functionality, I made the program make a little bit more sense to someone reading it.

Refactoring is something you should do every time you get a program to run correctly. Always make sure the code is well-organized and that it makes sense when you read it.
 
Junilu Lacar
Sheriff
Posts: 15989
265
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Next, I'll focus on the part of the story that says "A race car will consume anywhere from 3 to 5 units of fuel for every lap it runs."

I'm going to need a random number generator for this so I'll import the java.util.Random class:

The Random class has a nextInt(int bound) method that returns a random integer from 0 (inclusive) up to but excluding the specified bound that's passed as a parameter.

If I pass in 5 as the bound then nextInt(5) will return a random number from 0 to 5 (exclusive) or 0 to 4 (inclusive). This is not what we need though. We need a random number from 3 to 5 (inclusive). Not a problem. We can do this:

This works because if nextInt(3) returns 0 (the minimum value it can return), then 3 + 0 == 3, which is the lower bound we need. If nextInt(3) returns 2 (the maximum value it can return), then 3 + 2 makes 5, the upper bound we need.

So I insert this logic in the runRace() method. This is just our initial attempt to get it working. Once we get it working, we'll refactor the code so that it is better organized and more understandable. This is what we might attempt to do:

I save these changes and run the program again. I run the program several times and observe the output. If you've been following along, try it yourself.

What I see is that the program appears to run somewhat correctly. Every time I run it, it usually displays a value for the the number of units of fuel used that's different from the value in previous runs. However, the number doesn't change for every lap: it's the same value for every lap when I run the program. I want the value to be different for each lap. This tells me that the program probably has a bug. See if you can figure out what change needs to be made in the program to fix this bug.

That is, instead of this output:

$ java RaceCar.java
Created RaceCar Rankine with maximum fuel capacity of 25
Running race of 10 laps...
lap #0, used up 3 units of fuel
lap #1, used up 3 units of fuel
lap #2, used up 3 units of fuel
lap #3, used up 3 units of fuel
lap #4, used up 3 units of fuel
lap #5, used up 3 units of fuel
lap #6, used up 3 units of fuel
lap #7, used up 3 units of fuel
lap #8, used up 3 units of fuel
lap #9, used up 3 units of fuel
Done.

The output should look more like this:

$ java RaceCar.java
Created RaceCar Rankine with maximum fuel capacity of 25
Running race of 10 laps...
lap #0, used up 3 units of fuel
lap #1, used up 5 units of fuel
lap #2, used up 3 units of fuel
lap #3, used up 5 units of fuel
lap #4, used up 4 units of fuel
lap #5, used up 5 units of fuel
lap #6, used up 3 units of fuel
lap #7, used up 5 units of fuel
lap #8, used up 4 units of fuel
lap #9, used up 3 units of fuel
Done.

 
Junilu Lacar
Sheriff
Posts: 15989
265
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I wrote:That is, if the car stops after having only used up 1 unit of gas, it will only be topped off with 1 unit instead of 2 units. If it has used 3 units of gas, the full 2 units allowed per stop will be used but it won't be able to add more until the next time it stops.


I think I need to make a little bit of a clarification on this. A RaceCar will start a race with a full tank of gas. It can only add gas after completing at least one full lap. So, if it stops to top up after one lap and having used up 3 units of fuel, then since it can only refuel with 2 units at a time, it will run the next lap with 1 unit of fuel less than its maximum capacity.

Let's do this with a concrete example so it's clearer. Say the car has a maximum tank capacity of 25. It starts the race with a full tank, i.e., 25 units of fuel. It runs one lap, consuming 3 units. It stops to refuel, adding 2 units of fuel. That means it only has 24 units of gas in its tank now (25 - 3 + 2). It runs another lap, this time consuming 4 units of fuel. It stops and refuels another 2 units. So that makes 25 - 3 + 2 - 4 + 2 = 22 units of fuel. It keeps doing this until it either completes the race (in our case, 10 laps) or runs out of fuel which happens when fuelUsed in running the lap is greater than what it has in the tank at the start of the lap.

This means that you can safely ignore the part about "it will only be topped off with 1 unit instead of 2 units" for now because you'll never run into this scenario given the other rules I stated of using up between 3 to 5 units of fuel and being able to refuel only 2 units at a time.
 
Liutauras Vilda
Marshal
Posts: 7851
538
Mac OS X VI Editor BSD Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Junilu Lacar wrote:Should we pass a value to the runRace() method to tell it how many laps to run? Or should that be passed to the constructor? I'm going to opt for the former since it makes more sense to me.


Liutauras Vilda wrote:...why numberOfExperiments is part of constructor parameters list? numberOfExperiments I'd more expect to be part of runExperiments() method.


@OP
In case you are trying to make a sense out of it, why it is like so.

If you think about it carefuly, numberOfExperiments isn't really a property of Space Rocket, same as in Junilu's given example raceLaps isn't a property of a Race Car (or any other). Space rockets don't have number of experiments built-in, nor race cars have race laps - both can participate in... experiments or ride laps respectively.

Does it make sense to you?

I see Campbell pointed out about the prescribed requirements you were given, so it seems you have been told to design mentioned method that way, let it be, but be aware, that normally need to put more thought what kind of knowledge you build into objects and what kind of responsibilities you assign to them, makind so without a thought one ends up with a messy classes/objects which are hard to understand what they are meant for as they have no clear purpose - but that's for future, actually near one.
 
Junilu Lacar
Sheriff
Posts: 15989
265
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@OP: I'm going to pause at this point to let you ask questions or get clarification. My suggestion would be for you to not just read through my example but to also do it just as I described.

I'll continue with the rest of the solution once you show that you understand the bug in the last part (where the amount of fuel used is the same for every lap instead of randomly changing from one lap to the next) and show that you can come up with the correct way to fix the bug.
 
lilly Rankine
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok so I think I understand that but as the question says, the method should not have an argument and a return value, whereas the examples do
 
lilly Rankine
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
also that is the requirement of the question. The whole code I have wirtten so far is basically answers to questions. And one I have mentioned above is the one I am stuck on and have to do that wothout having to change eveything else
 
Junilu Lacar
Sheriff
Posts: 15989
265
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know what else to say, lilly, it's not our job to solve the problem you were given, it's yours. The best we can do here is give you examples and guidance on how to solve the problem but we are not in the habit of giving out solutions. That defeats the whole point of learning.

I showed you an approach to solving a problem. You have to look past the specifics of what I did and try to understand the thinking process behind it. It's the thinking part that's important in programming. Without it, there can be no solution. Sorry.
 
lilly Rankine
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are required to run experiments up to a number that is expressed by the relevant instance variable. Each experiment shall be run if the power level is higher than zero, each experiment will decrement power of a random value between 1 and 3 and if the power goes to zero shall stop and print the run has finished. You should not run experiments if the current power level is already zero.

This is how I read it.
 
Mo-om! You're embarassing me! Can you just read a tiny ad like a normal person?
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic