Log in

View Full Version : help on grade calculator tool(GPA)



amyshetty
04-13-2017, 03:52 PM
Hey! Help me
I'm totally stuck on this project, in which a user is supposed to enter number of students in a class, and number of exams taken. Then they enter each student's name, and then the exam scores for that student on a single line separated by blank spaces.
Here website I want clone tool: https://gpahub.net/
Any advice would be really appreciated, thanks a lot.


public class proj2 {

public static void main(String[] args) {
Scanner s = new Scanner(System.in);

System.out.println("Welcome to Gradecalculator!");

System.out.println("Please enter the number of students:");
int students = s.nextInt();

System.out.println("Please enter the number of exams:");
int exams = s.nextInt();

int i = 0;
int studentnumber = 1;

int sum = 0;
while (i < students) {

double average = sum/exams;

System.out.println("Enter student " + studentnumber++ + "'s name :");
String studentname = s.next();

System.out.println("Enter exam scores :");

for (; i < exams; i++) {
int n = s.nextInt();
sum+=n;

if (n < 0) {
System.out.println("Invalid exam scores, reenter: ");
}
}
if (average <= 100 && average >= 90) {
System.out.println("Letter grade: A");
System.out.println(studentname + " gets 4 stars! ****");
} if (average <= 89 && average >= 80) {
System.out.println("Letter grade: B");
System.out.println(studentname + " gets 3 stars! ***");
} if (average <= 79 && average >= 70) {
System.out.println("Letter grade: C");
System.out.println(studentname + " gets 2 stars! **");
} if (average <= 69 && average >= 60) {
System.out.println("Letter grade: D");
System.out.println(studentname + " gets 1 star! *");
} if (average <= 59) {
System.out.println("Letter grade: F");
System.out.println(studentname + " gets 0 stars!");
}
}
}
}

Deadweight
04-14-2017, 03:04 AM
A few things I noticed, sleep so I can be wrong, and I haven't played with java in awhile
Also, not sure if we are suppose to help with homework... but still

Your if statements are weird (unless they are just copied wrong).
Shouldn't student number start at 0 and not 1. Shouldn't you be comparing student number to students. studentnumber < student.
Variable i should just be located inside the for loop.
The n < 0 needs to before you add it to the sum (you dont want to add a negative number to the sum) and you will need to do i--;

That is a quick glance. (Ignore spelling and grammar mistakes on my part)

styxlawyer
04-14-2017, 05:00 PM
Java, JavaScript, PHP or C++, the language is irrelevant as the methods are all the same. You need to think seriously about the implications of using the same variable in these two lines in your code:




while (i < students) {
.
.
for (; i < exams; i++) {