• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

style or reason

 
Ranch Hand
Posts: 424
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
In the eve or odd assignment I used an if ... else ...,
Marylin had chosen for building a String and therefore only
one println. My solution in my taste is 'clearer' but
see the subject.
 
Sheriff
Posts: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not "building" a string. Assigning a string to a reference and changing that reference to refer to a different string if necessary.
 
Peter Gragert
Ranch Hand
Posts: 424
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Apology, for not expressing myself correct.
Sorry, your answer is (for me) not an answer to the subject.
 
Trailboss
Posts: 23778
IntelliJ IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I must be thick because I don't follow what we are even talking about.
 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I just finished that assignment but haven't sent it in for "nitpicking" yet, as I'm awaiting feedback on the first. But I'm guessing that in the if/else block, you had two println statements (which is precisely what I did). From what I gather, Marilyn's preferred solution would involve creating a String variable that would have a reference to either "odd" or "even". (What I'd really like to say here is it has a value of "odd" or "even", which is clearer to understand, but I know that a String's value is actually a reference).
So I believe the question is whether it's really better to create this extra reference than to have two println statements, and why. Which is exactly what Peter was asking in the first place, and I'd like to know too.
 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Well Peter I think it depends on our familiarity with programming ... I'm still in the learnig stages ... so i will opt for clarity or rather ease of understanding ... I was surprised with the instructors solution too as i never even thought in that direction (i too used two print stmts) ...
The instructors solution to this problem is an optimized version... A second String reference is created only in the event of the number being Even ...
Well now that i'm aware of this, next time i might use the same (if i'm comfortable to the idea ofcourse :->)
 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is my first use of the 'college' so please overlook any inappropriateness --- guess I expanded on the assignment a bit, but the following is how I thought such a task should be handled. Would appreciate any feedback re : is this note appropriate to the forum? also, can following code be further optimized? It works just fine.


(Marilyn added code tags and deleted a little code)

[This message has been edited by Marilyn deQueiroz (edited March 06, 2001).]
 
Don Smathers
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
On reading over my prior reply, I see that leading spaces were dropped. Perhaps because I copied all the stuff from Notepad ??? I'm going to practice with the reply field to see if direct editing will allow leading spaces -- if not, will someone please tell me how to format code in the reply field !! thanks.
{ // start of test
public class Foo
{
// do nothing
}
}
 
Ranch Hand
Posts: 347
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Don,
See here for a good explanation of how to post your code so it looks good and keeps its formatting:
http://www.javaranch.com/ubb/faq.jsp#q4
Stephanie
 
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Don,
You should probably read the "cattle drive" section of this web-site for instructions on how to submit the assignments. This forum should be used to discuss the assignments, but the code should not be posted here.
Pat B.
 
Marilyn de Queiroz
Sheriff
Posts: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Don Smathers:
This is my first use of the 'college' so please overlook any inappropriateness --- guess I expanded on the assignment a bit, but the following is how I thought such a task should be handled. Would appreciate any feedback re : is this note appropriate to the forum? also, can following code be further optimized? It works just fine.


The question is appropriate. However, we prefer that you do not post your solutions here because that may rob later readers of an education. They can simply copy your answer and do absolutely no thinking about the assignment.

Pseudocode is fine. Code snippets are ok (one line or so).

One of the rules of the cattle drive is don't add extra stuff unless specifically mentioned. It just makes more work for the nitpicker. But if you want to discuss ideas for future enhancements here, that's fine.
 
paul wheaton
Trailboss
Posts: 23778
IntelliJ IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't understand how you would use a for loop in this assignment.
I don't see why you would want to use all the jd stuff. Not only does no one do anything like that, you aren't buying uniqueness because you already have uniqueness in Java. Unlike other languages, variables used inside your method are not global.
re "style or reason": Not sure what you are asking for here, but if you want to pass the code review, you need to follow the style guide. If you want to understand the "why" of the style guide, by all means ask here.
 
Don Smathers
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Paul Wheaton:
I don't understand how you would use a for loop in this assignment. ANS: generalize the prgm to handle a longer command line input, such as C:\java Even_Odd 234 11 4 5 789, etc.,
processing each member in turn.
Re: the 'jd stuff' - an invention of my own -- when I first started to study Java, I found the mix of upper/lower case and the use of class, variable, and method names VERY CONFUSING !! So, after consulting my dictionary, I discovered no English words beginning with 'jd' -- many other combos will also work, but I like this one -- sounds Arabic -- anyway, when I review my code six months later, I am NEVER confused that 'jd' words are anything but something I threw in --- never someone elses name for whatever --- maybe hokey, but it works for me.
I don't see why you would want to use all the jd stuff. Not only does no one do anything like that, you aren't buying uniqueness because you already have uniqueness in Java. Unlike other languages, variables used inside your method are not global.
re "style or reason": Not sure what you are asking for here, but if you want to pass the code review, you need to follow the style guide. If you want to understand the "why" of the style guide, by all means ask here. ANS: since posting this, I've learned a lot --- thanks.



[This message has been edited by Don Smathers (edited March 20, 2001).]
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic