Tim Hurst
Tim Hurst

Reputation: 1

Java Gradebook Program

I am trying to make a simple gradebook program. My code is not finished yet but I am trying to structure it first. I keep getting an unresolved compilation error that for the life of me I can not figure out. I know it is something simple and stupid but I am about as much of a rookie as you get. Any help trying to overcome this error (Exception in thread "main" java.lang.Error: Unresolved compilation problem: student cannot be resolved to a variable) would be much appreciated!

import java.util.Scanner;
public class Gradebook {

/**
 * @param args
 */
public static void main(String[] args) {
    // TODO Auto-generated method stub

    float discussionweight, hwweight, examweight, discussion, hw, exam, finalaverage;

    // Initializes the input scanner
    Scanner scan = new Scanner(System.in);

System.out.print("Enter the students name: ");
    student = scan.next("");

    // Prompts for the weight of the discussions
    System.out.print ("Enter the weight of the discussions as an integer: ");
    discussionweight = scan.nextFloat();

    // Prompts for the discussions grade
    System.out.print ("Enter the score of the discussions as an integer: ");
    discussion = scan.nextFloat();

    // Prompts for the weight of the homework grade in an integer
    System.out.print ("Enter the weight of the homework as an integer: ");
    hwweight = scan.nextFloat();

    // Prompts for hw grade
    System.out.print ("Enter the hw grade: ");
    hw = scan.nextFloat();

    System.out.print("Enter the weight of the exam as an integer");
    examweight = scan.nextFloat();

    System.out.print("Enter the exam grade");
    exam = scan.nextFloat();



    // Calculate and print the final, weighted average.
    finalaverage = (((discussionweight * discussion) + (hw * hwweight) + (exam * examweight)) / 100);

    System.out.println ("The final average is "+ finalaverage);

    }

    } 
  }

}

Upvotes: 0

Views: 714

Answers (2)

Ryan Hartman
Ryan Hartman

Reputation: 191

It looks like you are never declaring a variable named student.

string student = scan.next("");

Same for the rest of the variables you are using.

Upvotes: 1

Steve
Steve

Reputation: 502

student = scan.next("");

you never tell the compiler what type student is.

something like String student = scan...

Upvotes: 0

Related Questions