• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

java 1b hundred ugh

 
Harry Graham
Greenhorn
Posts: 10
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
lol I am banging my head against the wall and stubbing my toes on the coffee table and for the life of me just can't figure out how 1b is just about math. I want to try to use arrays but that is not in the assignment. Someone kick me.

I have figured out how to get the int value of "Gertrude " but now how do I / that into the console length that I declare.

console/"Gertrude "?

BTW I know the answer is staring at me just don't see it.

Hope I am not the only fool
 
Christophe Verré
Sheriff
Pie
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Harry. What are you talking about ? Are you talking about an assignment ? The cattledrive ?
 
Campbell Ritchie
Sheriff
Pie
Posts: 47228
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, it is the cattle drive, so I shall move this thread to that forum. What you are supposed to do is print
Harry Harry Harry Harry Harry Harry Harry Harry Harry Harry Harry Harry Harry
Harry Harry Harry Harry Harry Harry Harry Harry Harry Harry Harry Harry Harry
Harry Harry Harry Harry Harry Harry Harry Harry Harry Harry Harry Harry Harry
Harry Harry Harry Harry Harry Harry Harry Harry Harry Harry Harry Harry Harry
Harry Harry Harry Harry Harry Harry Harry Harry Harry Harry Harry Harry Harry
Harry Harry Harry Harry Harry Harry Harry Harry Harry Harry Harry Harry Harry
Harry Harry Harry Harry Harry Harry Harry Harry Harry Harry Harry Harry Harry
Harry Harry Harry Harry Harry Harry Harry Harry Harry
Now "Harry " contains 6 characters, [H=1 a=2 r=3 r=4 y=5 space =6]. So you have to work out how many "Harry "s you can get into the 80 character width of the command window. That is where the arithmetic comes in.
 
Carol Murphy
village idiot
Bartender
Posts: 1202
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Harry, are you sure that you have to work out how many times the name can be printed completely on each line? Or, rather, just write code that will print to the next line if the complete name doesn't fit?
 
Harry Graham
Greenhorn
Posts: 10
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for moving thread, sorry about having it posted in wrong forum.
Not there yet but still playing. hmm
"IF" or "for" now that is the question

 
Stefan Brandenberger
Greenhorn
Posts: 12
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Carol Murphy wrote:Harry, are you sure that you have to work out how many times the name can be printed completely on each line? Or, rather, just write code that will print to the next line if the complete name doesn't fit?


Well, the latter can be evaluated by computing the former, no?
 
Harry Graham
Greenhorn
Posts: 10
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I can get 1 line to print out correctly or have the print out run forever, kind of funny actually, now to just tweek it a little more. Looking forward to the first nit pick with this.
 
Carol Murphy
village idiot
Bartender
Posts: 1202
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stefan Brandenberger wrote:
Carol Murphy wrote:Harry, are you sure that you have to work out how many times the name can be printed completely on each line? Or, rather, just write code that will print to the next line if the complete name doesn't fit?


Well, the latter can be evaluated by computing the former, no?


Yes, it can. But is that the best and only way to perform this task?
 
Carol Murphy
village idiot
Bartender
Posts: 1202
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually, Harry, I went back to look at my source for this assignment. The solution is very simple, and does not require anything as fancy as an array. It uses simple math. Don't complicate a simple solution.
Cryptic enough for you?
 
Carol Murphy
village idiot
Bartender
Posts: 1202
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Carol Murphy wrote:Harry, are you sure that you have to work out how many times the name can be printed completely on each line? Or, rather, just write code that will print to the next line if the complete name doesn't fit?


I have to correct myself here. I don't want to confuse you further. You do need to figure out how many times the name will fit on each line. I didn't phrase this well. What I should have said was that the solution to this is not complicated. A simple approach is the key.
My bad!
 
Harry Graham
Greenhorn
Posts: 10
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If this needs deleting please delete...
Ok I am still fighting this project, I got it to run correctly now I am being told that I am calling a method 100x and will get same result each time, ok I understand that but how do I make it so that I only grab what I need? I have zero programming exp and my head hurts.
 
Marilyn de Queiroz
Sheriff
Posts: 9059
12
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What if you call the method once and save the result
 
margaret gillon
Ranch Hand
Posts: 335
6
Linux Tomcat Server Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have zero programming exp and my head hurts.


Harry since you have no programming experience you may want to get another book like Java for Dummies 4th edition by Barry Burd that includes more detail on basic programming concepts like loops. I have been programming for 25 years and I use both the course text Just Java2 and the Java for Dummies to help me with the Cattle Drive assignments. Java is very different than the traditional languages I use at work and Burd's detailed explanations help me. There are book reviews of other Java books on this forum Javaranch book review forum


I just checked on amazon.com and Burd has an introduction to programming book that uses Java, too. Beginning Programming with Java For Dummies (For Dummies (Computer/Tech)) (Paperback) . ISBN-10: 0764588745.
 
Harry Graham
Greenhorn
Posts: 10
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why do you change " int j = blahblah //This is what I am doing "
to " int ExplanationOfWhatIsBeingDone = blahblah "
Is it for when longer codes are written and you can not just go int a - z?
I thought the comment would make things simpler.
 
Katrina Owen
Sheriff
Pie
Posts: 1367
18
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are good comments, bad comments, and awful comments.

Good comments explain why you did something the way you did it. It can be a gotcha, or a business rule, or a trade off for performance reasons.

Comments that state the obvious, are cryptic, imprecise, incomplete, outdated, etc are Bad(tm)

Comments that are misleading are awful.

The thing is, if you can make your code speak for yourself, then a lot of the time you won't need comments; less comments -- less to read -- less to bother your brain with.
Also if the code itself tells you what is going on, it is MUCH easier to read and understand, and then it is cheaper to maintain (because generally you read code more than you write it, and often you read it when you've been away from it long enough to have forgotten what it is about... or you never saw it before because someone else wrote it).
 
Carol Murphy
village idiot
Bartender
Posts: 1202
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This very subject is one of the things I found most valuable about doing the drive. The simple act of naming variables in such a way that they describe their purpose makes a huge difference in readability, and thus my ability to comprehend the code I'm trying to decipher.
One example from Java books and also many practice certification exams is the use off foo and bar for variable names. I have a hell of a time with any code fragments that use foo and bar, because of what they stand for. I can't get past it. My mind goes.......foo bar. What can I say. So as petty as it may seem, the discipline of naming variables to help describe their function is a very good practice! And for those of us who hate typing, there's always copy and paste!
 
Katrina Owen
Sheriff
Pie
Posts: 1367
18
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When I was taking exams in programming in college, the programs were in Java, but the variables were in Norwegian. My mind shriveled and died a little trying to figure out what the program was supposed to be doing, and since the program was hard copy (exam was paper based, not on a computer) I couldn't just replace the variables with translations (which were provided on a separate sheet for me).
 
Carol Murphy
village idiot
Bartender
Posts: 1202
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yikes!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic