• Post Reply Bookmark Topic Watch Topic
  • New Topic

Read and print overall grades program  RSS feed

 
Joey Williams
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So essentially I'm in a java class, the teacher doesn't explain anything or really teach he just types and expects people to understand. I had a homework assignment to do the follow;

Write a Java program that reads grades on midterm1(0-80),  midterm2(0-100), final(0-200), quizzes(0-150), homework assignments(0-240), and lab projects(0-300) and then prints the overall grade(0-100). The scores are weighted as follows:
midterm1: 10%
midterm2: 15%
final: 20%
quizzes: 15%
homework: 25%
lab projects: 15%

can someone review what i've written and tell me if it's correct or if i'm going about this the wrong way? any guidance would be appreciated, thanks!

 
Liutauras Vilda
Sheriff
Posts: 4928
334
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch.

Have you tried to calculate on a paper first and see if your calculated result matches to what your written program gives as an output?
 
Carey Brown
Saloon Keeper
Posts: 3329
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Seem correct though I have two suggestions. Don't use abbreviations, e.g. should be "midterm1". And there's nothing in your spec that says a grade can have decimal places in it, so you should probably use int's.

Note that '/' and '*' have the same precedence and are operated on left to right.
 
Liutauras Vilda
Sheriff
Posts: 4928
334
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Carey Brown wrote:Note that '/' and '*' have the same precedence and are operated on left to right.

@OP what Carey was saying, that you don't need use parentheses, unless it is way clearer to you.
 
Joey Williams
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Liutauras Vilda wrote:Welcome to the Ranch.

Have you tried to calculate on a paper first and see if your calculated result matches to what your written program gives as an output?


Yes, and I have verified it by creating a println that I deleted after it was verified. My concern wasn't towards the math just that the way I did it was correct.


Carey Brown wrote:Seem correct though I have two suggestions. Don't use abbreviations, e.g. should be "midterm1". And there's nothing in your spec that says a grade can have decimal places in it, so you should probably use int's.



Note that '/' and '*' have the same precedence and are operated on left to right.


I probably should have clarified that the only portion we had to write was the steps for calculation of the average and the "system.out.println("course average = " + avg);

I understand that I could've just arranged it in the order of operations, for the time being using () just helps me see exactly whats going on. Thank you for your suggestions
 
Campbell Ritchie
Marshal
Posts: 56599
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Carey Brown wrote:. . . Note that '/' and '*' have the same precedence and are operated on left to right.
The bit about left to right can be taken two ways:
  • 1: Java® expressions are evalauted by going left to right.
  • 2: Those operators (like most operators) associate left to right (=associate to the left).
  • I would suggest you change the order of the arithmetic operations. Try omitting the casts and change the order so the multiplication is always done before the division. See whether you get the same results.
     
    Campbell Ritchie
    Marshal
    Posts: 56599
    172
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    . . . and welcome to the Ranch
     
    Joey Williams
    Greenhorn
    Posts: 3
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Campbell Ritchie wrote:
    Carey Brown wrote:. . . Note that '/' and '*' have the same precedence and are operated on left to right.
    The bit about left to right can be taken two ways:
  • 1: Java® expressions are evalauted by going left to right.
  • 2: Those operators (like most operators) associate left to right (=associate to the left).
  • I would suggest you change the order of the arithmetic operations. Try omitting the casts and change the order so the multiplication is always done before the division. See whether you get the same results.



    I really got to looking at what you were saying and saw that I could do it like this,



    cleaning up the code quite a bit, for my turn in I left it as.



    just to show the steps of how I was adding in the weighted value.

    thank you for your input on this.
     
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!