• Post Reply Bookmark Topic Watch Topic
  • New Topic

Java Calculator  RSS feed

 
jason dick
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have coded a calculator that calculates percentages. Ok the problem is how would I accurately calculate a grade mark that is split up for example an exam that is 100 marks that counts 60% and 4 courseworks out of 10 marks each total counts 40% then compute the total marks. This is the code:

 
Raymond Tong
Ranch Hand
Posts: 255
2
IntelliJ IDE Java Spring
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Grand total should be 100 for full marks.
According to your code

The formula itself is not complex, get pencil and paper and write that formula before start coding.
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
jason dick wrote:This is the code:...

Also:
  (exam2/10 + exam3/10 + exam4/10 + exam5/10)
only works because '/' has a higher precedence than '+'.

For clarity, you're usually better off putting ALL "ambiguous" stuff in brackets, even if they're not strictly necessary - viz:
  (exam2/10) + (exam3/10) + (exam4/10) + (exam5/10)

Futhermore, the above sum equals:
  (exam2 + exam3 + exam4 + exam5) / 10

and since you then multiply by 40, the entire expression is equal to:
  (exam2 + exam3 + exam4 + exam5) * 4

HIH

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