alfnks alfnks - 1 year ago 119
Java Question

I keep getting the java:122 error: '.class' expected. How do I resolve it?

import java.util.*;

public class Averages{ //name class as public

public static void main(String[] args){

Scanner sc = new Scanner(; //initialized string using 'new'

String Course;
int knowledgemark;
int communicationmark;
int thinkingmark;
int applicationmark;
int average;
int finalexam;
int average2;
String answer;
int maxK;
int maxC;
int maxA;
int maxT;
int knowledgeweight;
int communicationweight;
int thinkingweight;
int applicationweight;
String Assignment;
String Test;
int average3;
int weight;
int weightaverage;
int average4= 0;

System.out.println("What class are you calculating for?");
Course = Scan.nextLine();

System.out.println("What's your knowledge mark for this course?");
knowledgemark = Scan.nextLine();

System.out.println("What's your application mark for this course?");
applicationmark = Scan.nextLine();

System.out.println("What's your thinking mark for this course?");
thinkingmark = Scan.nextLine();

System.out.println("What's your communication mark for this course?");
communicationmark = Scan.nextLine();

average = ((knowledgemark + communicationmark + applicationmark + thinkingmark)/4);
average = Scan.nextInt();

System.out.println("Your average for" + Course + "is" + average);

System.out.println("Do you want to calculate your exam with your final exam mark? (yes or no)");
answer =;

if(answer.equals ("yes")){
System.out.println("What is your final exam mark?");
finalexam = scan.nextInt();
average2 = (((average * 70) + finalexam * 30) /100);
System.out.println("Your final average in this course is" + average2);

System.out.println("You average for" + Course + "is" + average);

System.out.println("You can also calculate your marks with tests/assignments");
Test = Scan.nextLine();

System.out.println("What test/assignment are you calculating for?");
Test = Scan.nextLine();

System.out.println("What is the weighting for knowledge?");
knowledgeweight = Scan.nextLine();

System.out.println("What is your knowledge mark for the test/assignment?");
maxK = Scan.nextLine();

System.out.println("What is the weighting for communication?");
communicationweight = Scan.nextLine();

System.out.println("What is your communication mark for the test/assignment?");
maxC = Scan.nextLine();

System.out.println("What is the weighting for application?");
applicationweight = Scan.nextLine();

System.out.println("What is your application mark for the test/assignment?");
maxA = Scan.nextLine();

System.out.println("What is the weighting for knowledge?");
thinkingweight = Scan.nextLine();

System.out.println("What is your thinking mark for the test/assignment?");
maxT = Scan.nextLine();

average3 = (maxK * knowledgeweight + maxC * communicationweight + maxT * thinkingweight + maxA * applicationweight);

System.out.println("Your final average for this test/assignment is" + average3);

System.out.println("What is the weight of the test/assignment (10, 30, 50)?");
weightaverage = Scan.nextInt;

weightaverage = (average3 * weightaverage);

System.out.println("Your assignment/test weighted is" + weightaverage);

int length;

Scanner scan = new Scanner(;

System.out.println("How many classes do you have?");

length = scan.nextInt();

int[] firstArray = new int[length];

for(int i=0; i<length; i++){

System.out.println("What is your course mark for each class in order" + (1 + i) + "?");

firstArray[i] = scan.nextInt[];


Here is my code. The error is near the bottom of the page. Thanks ahead of time!

Please hep me fix this as I do not know what to do

It is my only error left to compile.

Thanks and greatly appreciated!

Edit: Formatted to show code in one snippet.

Answer Source

You are missing () in your call to nextInt() at

weightaverage = Scan.nextInt;

change it to something like

weightaverage = Scan.nextInt();


firstArray[i] = scan.nextInt[];

should be

firstArray[i] = scan.nextInt();

And, you aren't consistent with your Scanner name.

Scanner sc = new Scanner(;

needs to be

Scanner Scan = new Scanner(;

if you're going to call Scan.nextInt(). Also, you are calling nextLine() (which returns a String) and assigning the result to int variables.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download