• Post Reply Bookmark Topic Watch Topic
  • New Topic

Java Calculator error  RSS feed

 
jason dick
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to work out the average of a students mark they have an exam worth 60% and 4 courseworks work 40% how would I work out their marks for example a student scores: 68 in the exam and a total of (8+9+10+10)=37 in the courseworks the mark should be 77% the exam is out of 100 and the coursework is out of 40 but it gives me something else here is the code:

 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 37507
552
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jason,
The problem is that everything is an integer. In Java's mind, 68/100 is 0. I'm not clear on why you take the square root afterwards, but everything is 0 on that line anyway.

Also, I think you formula is wrong. You want 60% of the exam grade, not to multiply it by 60. Take a look at using the double type so you can have fractions.
 
Knute Snortum
Sheriff
Posts: 4287
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


What is the square root doing here?
 
jason dick
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Knute Snortum wrote:

What is the square root doing here?


You guys are useless I sorted it out myself
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 37507
552
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
jason dick wrote:You guys are useless I sorted it out myself

I'm sorry the replies didn't help you. Can you share what the actual problem so future readers are this thread are helped? (and so we know why the advice provided wasn't useful)
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!