Jump to content

Need some help with a Java assignment

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
5 replies to this topic

#1
Bloodpanda

Bloodpanda

    Newbie

  • Members
  • Pip
  • 3 posts
Hi i need some help on how to do this java programing assignment. It was due like 3 weeks ago and i have been unable to do it so far because i missed days when we were going over this material.

The assignment is:

1. Write a class named Grades that inputs and calculates grades for a number of students. Each student has five grades. The output of the method main() must consist of (a) the average score of the student with the highest average, (b) the average score of the student with the lowest average, © the overall average for all students. You must have a public method named studentAve() that does the following:

· Reads the five grades for a single student

· returns the average of this student’s grades.

The studentAve() takes no parameters and returns a double, so its method signature must be:

public static double studentAve()



main() must read a double from the user that indicates whether or not there is another student. If this number is negative, main() should output the required averages.

Here is the input for a sample run (the ‘|’ represents typing the ‘Enter’ key – like in the autograder):
0| // this number is read by main() to indicate that there is information for another student
1|2|3|4|5|
0| // indicates there is another set of student grades to read
2|4|6|8|10|
-1| // indicates there are no more students to process

Here is the output for this input (again, the ‘|’ represents println() printing an end-of-line character – like in the autograder):
Low Average: 3.0; High Average: 6.0; Overall Average: 4.5|

You may print anything you like using System.err.println(), but, in order to pass the autograder, you must print exactly the required output and nothing else using System.out.println().

Hints:
a) If the first number main() reads is negative, print 0.0 for low, high, and overall averages.
b) in studentAve() use a loop and a counter, and loop until you have read 5 grades then return. The loop in studentAve() does NOT keep reading until it sees a negative input.



Thank you!!!

PS:Im not necessarily asking for you to write the code, more like give me a walk through so to speak of how to do this. Thank you.

#2
Orjan

Orjan

    Writes binary right handed and hex left handed

  • Moderators
  • 3,299 posts
I recognize this assignment. look back in a few threads here in java and see what it can give.
__________________________________________
I study Information Systems at Karlstad University when I'm not on CodeCall

#3
Bloodpanda

Bloodpanda

    Newbie

  • Members
  • Pip
  • 3 posts

Orjan said:

I recognize this assignment. look back in a few threads here in java and see what it can give.

EDIT:Was the the one you were talking about?

Quote

import java.util.Scanner;
public class Uppgift15 {
public static void main(String[] args) {
int number=0, lowest=Integer.MAX_VALUE, slowest=Integer.MAX_VALUE, shighest=Integer.MIN_VALUE, highest=Integer.MIN_VALUE, med=0;
Scanner tgb = new Scanner(System.in);
System.out.print("Write X couple of numbers and finish with 0: ");
System.out.println(" ");

number=tgb.nextInt();
while (number !=0)
{
if (number>highest)
{
shighest=highest;
highest=number;
}
if (number<lowest)
{
slowest=lowest;
lowest=number;
}
number=tgb.nextInt();
}
System.out.println("The lowest number is: " +lowest);
System.out.println("The 2nd lowest number is: " +slowest);
System.out.println("The highest number is: " +highest);
System.out.println("The 2nd highest number is: " +shighest);

}}


#4
Bloodpanda

Bloodpanda

    Newbie

  • Members
  • Pip
  • 3 posts
Orjan, if that was the java assignment you thought of it sadly does not help me with what i am doing. Thank you though.

Any one else have advice/imput on this? It is crucial that i get this done tonight!

Thank you!!!

#5
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
What do you have currently? Without knowing what part you're stuck on, it's hard to offer meaningful assistance.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#6
sanfor

sanfor

    Newbie

  • Members
  • PipPip
  • 11 posts
me too