Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

am i right? java programing

 
Josh Leo
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
void addEntry(Integer newEntry)
throws SimulationException

Adds a new entry to the log. Existing entries are shifted along one place in the window accordingly.
Parameters:
newEntry - the new value to be added to the log
Throws:
SimulationException - if the given value is not in the range 0 to maxEntry, inclusive

how does the code look like ? does it look like this ?
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15482
43
Android IntelliJ IDE Java Scala Spring
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, the description says that addEntry is a method that returns nothing (it's void) and that takes an Integer as an argument, and it can throw a SimulationException. So, most likely the implementation of the method indeed looks something like:

The first lines of the description already say that literally.

What exactly are you confused about?
 
Josh Leo
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
newEntry - the new value to be added to the log
Throws:
SimulationException - if the given value is not in the range 0 to maxEntry, inclusive

i am confused about these 2 parameter. how can i create it?
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15482
43
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is this a method that you have to implement yourself (and someone else's code is going to call it), or are you just going to call the method yourself?

I can't tell you how to implement it, because I don't know anything about the context in which you're going to write or use this method.

newEntry is an argument that gets passed to the method. The method has to do something with it (add it to the log - whatever the log is in this case). Apparently, the method also has to check if newEntry is in the range 0 to maxEntry, and if it isn't, it should throw a SimulationException.
 
Sze Kong Chan
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Josh,

See if this help.. :0)

Implementation goes something like that


To invoke the method


Not sure if I get what you want. otherwise, please elaborate.. BTW don't forget to define a class for your SimulationException
 
Josh Leo
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this is my code




Constructor:
To connect to the provided GUI, your WaterLog class must provide a constructor with the following signature, as well as all the methods below. (Observation: We've expressed this requirement as a comment because it isn't possible to define a constructor in an interface.)
Parameters:
Integer windowSize - the (minimum) number of entries that the log must retain
Integer maxEntry - the largest value that will ever be entered in the log
Throws:
SimulationException - if windowSize is not strictly positive (i.e., greater than zero)
SimulationException - if maxEntry is negative (i.e., less than zero)
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15482
43
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are some errors in your code.

Note that you have a ; after your if-statement. That makes the if-statement do nothing, and the method will always throw a SimulationException, no matter if newEntry is > maxEntry or not. Remove the semi-colon.

I think that you also have to add some more code to the method. You're not yet adding the value to the log; you're only checking the value.

Josh Leo wrote:Constructor:
To connect to the provided GUI, your WaterLog class must provide a constructor with the following signature, as well as all the methods below. (Observation: We've expressed this requirement as a comment because it isn't possible to define a constructor in an interface.)

You haven't defined an interface. WaterLog is a class, and there's already a constructor there (lines 10-12).
 
Campbell Ritchie
Sheriff
Pie
Posts: 50196
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why are you using Integers and not ints?
 
Josh Leo
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think that you also have to add some more code to the method. You're not yet adding the value to the log; you're only checking the value.


allow me to ask a stupid question. how can i add value to the log ?

I used Integer because my teacher told me to do so.
 
Henry Wong
author
Marshal
Pie
Posts: 21498
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Josh Leo wrote:
allow me to ask a stupid question. how can i add value to the log ?


That's an implementation detail -- you have to tell us. It's your log class.

If you decide to persist to file, then you'll have to append to the file. If you decide to use a List, then you have to append to the list. If you decide to use a buffer, then you have to append to the buffer.

Henry
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic