• Post Reply Bookmark Topic Watch Topic
  • New Topic

Please check my program (Marks Calculation)  RSS feed

 
Bobby Sharma
Ranch Hand
Posts: 598
3
Google App Engine jQuery Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Do I need to optimize the above code or this is right ? Do I need to remove something ?
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're checking for equality with 60 twice (and also for equality with 50) - that should certainly be corrected. Even better, the "<=" check for the value of "marks" in lines 3 and 5 can be removed - and you should be able to tell us why that is not necessary.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12565
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bobby Sharma wrote:Do I need to optimize the above code or this is right ? Do I need to remove something ?

You should be able to tell us. What do your specs say you need to do?
 
Bobby Sharma
Ranch Hand
Posts: 598
3
Google App Engine jQuery Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Ulf and Fred ,

Owing to unforeseen circumstances , I had to leave programming and Java. I had developed a mind-set of a programmer before I switched to running my own business(not software related). Now , I am back to programming and Java itself. I should remove my programming certification details from the signature.
The reason I code my program with two extra "<=" is the question asked me to do "if marks is less than 60 and greater than 50, then..." so I just converted the english into Java without thinking too much. Maybe I don't know anymore how does if-else exactly works. thank you very much.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12565
49
Chrome Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bobby Sharma wrote: I just converted the english into Java without thinking too much.

and that is the hardest thing to learn about being a programmer. Programming is probably 70-80% thinking, and only 20-30% coding.

having the extra <= isn't really wrong as far as the language goes...it is legal to do it. However, it can be confusing to the next person who come along (or even yourself when you come back days/weeks/months later). The question is...what should be the result when someone has a mark of exactly 60? The way your code is written, it will print "First Class". That may be right, that may be wrong, but WE can't know that. Same with a mark of exactly 50 - what SHOULD it do?
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bobby Sharma wrote:
Owing to unforeseen circumstances , I had to leave programming and Java. I had developed a mind-set of a programmer before I switched to running my own business(not software related). Now , I am back to programming and Java itself. I should remove my programming certification details from the signature.
The reason I code my program with two extra "<=" is the question asked me to do "if marks is less than 60 and greater than 50, then..." so I just converted the english into Java without thinking too much. Maybe I don't know anymore how does if-else exactly works. thank you very much.


Doesn't "less than 60 and greater than 50" become "marks<60 && marks>50" when converted to Java? What you have is "less than or equal to 60, and greater than or equal to 50", when converted back to English.

Henry
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!