aspose file tools
The moose likes Java in General and the fly likes JDoe Java Program Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "JDoe Java Program" Watch "JDoe Java Program" New topic
Author

JDoe Java Program

eldon xu
Greenhorn

Joined: Nov 16, 2009
Posts: 4
Recently, I did a java program test, my code is:
>>>>>>>>> JDoe.java

<<<<<<<<<

I got a review as following:

1. It did run however it has warnings and there were many issues.
2. Some of the instructions were not followed properly
3. Not creative about his approach
4. Code is difficult to debug due to so many return statements being used

It is just hard to believe. Can anybody think about any issue based on the review ?
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 3133
eldon xu wrote:
I got a review as following:

1. It did run however it has warnings and there were many issues.
2. Some of the instructions were not followed properly
3. Not creative about his approach
4. Code is difficult to debug due to so many return statements being used

It is just hard to believe. Can anybody think about any issue based on the review ?


What's hard to believe?

1. It did run however it has warnings and there were many issues.


Either it has warnings or it doesn't. There's nothing subjective there. You can see for yourself when you compile.
So I believe this one.

2. Some of the instructions were not followed properly


Nobody here can know whether you followed the instructions. Presumably the individuals grading the test know, however.
So I believe this one.

3. Not creative about his approach


I don't consider a bunch of ifs to be creative, regardless of what the assignment was.
So I believe this one.

4. Code is difficult to debug due to so many return statements being used


I'm not an adherent to the "one return" faith. I think a few is fine. But you do have kind of a lot. Still, the pattern seems pretty simple to derive, so it's not horrible.
So I believe the grader could feel this way, but I agree with him only about 50% on this one.

eldon xu
Greenhorn

Joined: Nov 16, 2009
Posts: 4
The assignemt is here: http://kydevelopment.com/elevator/index.html
You can compile and run the program without any problem.
Jesper de Jong
Java Cowboy
Bartender

Joined: Aug 16, 2005
Posts: 11642

To give you an idea of how this could be done differently, so that you don't have to many if-statements in one big method, is by implementing this with a state machine.

The elevator can be seen as an object which can be in different states: moving, standing still with doors opened, with doors closed, etc. How the elevator behaves depends on what state it is currently in. You could model this explicitly in your program: create a State superclass or interface, and then create subclasses for each possible state. Handle events in the state classes, putting the behaviour for the event for a specific state in the class for that state.

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
eldon xu
Greenhorn

Joined: Nov 16, 2009
Posts: 4
Thank you offering different approaching. That is a very nice thought. But this programming task is to write a class that implements "SingleElevatorController". it only has 1 function, Instruction getNextOperation(SingleElevatorSystemData data). Any other approcah seems making the program lengthy and more complicated, in other words, it will runs slow.
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 3133
eldon xu wrote:Any other approcah seems making the program lengthy and more complicated, in other words, it will runs slow.


No. Proper design will not make it run significantly slower, and in many cases, will make it run significantly faster.
eldon xu
Greenhorn

Joined: Nov 16, 2009
Posts: 4
For this case, would you mind offering some codes that will make it significantly faster, given a specific interface and only one function in it.
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 8428

eldon xu wrote:Any other approcah (sic)...will runs slow.

Do you have any actual empirical evidence supporting such a statement? I mean, that is a pretty bold statement to make without any.

Further, even if it does slow down your code my a nanosecond, will anyone ever really notice? If writing cleaner code saves you hours of debugging but costs a few extra clock cycles, isn't it worth it?


Never ascribe to malice that which can be adequately explained by stupidity.
Randall Twede
Ranch Hand

Joined: Oct 21, 2000
Posts: 3901
it wasn't my assignment, so i sure don't know all that was required, but i sure would think twice about all those if statements. some seem to repeat even. if it even just returned once for each possible instruction, it would be an improvement.


I never took notes in college. That's how I got a 4.0 the first 2 years, and a 3.5 the second two years.
bob mark
Greenhorn

Joined: Feb 03, 2012
Posts: 1
I run the testing program, it is great. It perfectly followed the requirement and got excellent result. No any problem or issue.

1. It did run however it has warnings and there were many issues.
---- I did not see any problem or issues. Did they point out any real stuff?

2. Some of the instructions were not followed properly
---- I saw it completely followed the instructions and got the perfect result. Did they point out anything you missed?

3. Not creative about his approach
---- The program met the requirement, there is no requirement for "creative" here.

4. Code is difficult to debug due to so many return statements being used
---- The program code is perfect. I do not see any difficulty to debug. These return statements are good program pattern. The program is very clean and concisely.

Reviewer gave such valuation is not reasonable. You are very good, do not be discouraged.
 
IntelliJ Java IDE
 
subject: JDoe Java Program
 
Threads others viewed
Java Collection doubt #1
priority queue based on unsorted list(Java's LinkedList Class)
Need definitions of nextInt(), abs() and some other questions
Deleting duplicate integers from a vector!!!
Help with program: Monty Hall Problem
IntelliJ Java IDE