aspose file tools*
The moose likes Beginning Java and the fly likes am i right? java programing Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "am i right? java programing" Watch "am i right? java programing" New topic
Author

am i right? java programing

Josh Leo
Greenhorn

Joined: Mar 27, 2011
Posts: 7
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

Joined: Aug 16, 2005
Posts: 14338
    
  22

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?

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Josh Leo
Greenhorn

Joined: Mar 27, 2011
Posts: 7
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

Joined: Aug 16, 2005
Posts: 14338
    
  22

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

Joined: Mar 30, 2011
Posts: 10
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

Joined: Mar 27, 2011
Posts: 7
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

Joined: Aug 16, 2005
Posts: 14338
    
  22

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

Joined: Oct 13, 2005
Posts: 39791
    
  28
Why are you using Integers and not ints?
Josh Leo
Greenhorn

Joined: Mar 27, 2011
Posts: 7
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
Sheriff

Joined: Sep 28, 2004
Posts: 18978
    
  40

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


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: am i right? java programing