Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please help me understand my errors. Exception in thread main java.lang.Error: Unresolved compilation problems: Syntax error on token else, delete this token Syntax error, insert

Please help me understand my errors.

Exception in thread "main" java.lang.Error: Unresolved compilation problems: Syntax error on token "else", delete this token Syntax error, insert "}" to complete Block Syntax error on token "}", delete this token Syntax error, insert "}" to complete ClassBody

at TestGrade.main(TestGrade.java:39)

GradeException

public class GradeException extends Exception { static final String[] StuGrade = new String[]{"A", "B", "C", "D", "F"}; //Constructor without args public GradeException() { super("GradeException"); } //Constructor new expectations public GradeException(String message) { super(message); } }

TestGrade

import java.util.Scanner; import java.util.*; import java.io.*;

public class TestGrade extends GradeException { public static void main(String args[]) throws Exception { //Declare variables int i = 0; int a = 0; int ID[] = new int[10]; int j = 0; String Grade1[] = new String[10]; String Grade = "0"; int StudentID = 0; try { for (i = 0; i < ID.length; i++) { //Student id input System.out.println("Enter sudent ID: "); Scanner id = new Scanner(System.in); String sl = id.nextLine(); StudentID = Integer.parseInt(sl); //Grade input System.out.println("Enter the grade: "); Scanner g = new Scanner(System.in); Grade = g.nextLine(); GradeException GE = new GradeException(); boolean con = Arrays.asList(StuGrade).contains(Grade); if (con == true); System.out.println("Valid Grade"); else { // Throw GradeException System.out.println("Invalid Grade"); throw new GradeException(); } //Reassign values to grade ID[i] = StudentID; Grade1[i] = Grade; } //Display results System.out.println(" "); System.out.println("Consolidate Grade"); System.out.println("==================="); System.out.println("ID Grade"); //Display result up to end of ID length for (i = 0; i < ID.length; i++) { System.out.println(" " + ID[i] + " " + Grade1[i]); } } //Catch block catch (GradeException ex) { System.out.println(ex.getMessage()); ID[i] = StudentID; Grade1[i] = "I"; for (i = 0; i < ID.length; i++) { System.out.println(" " + ID[i] + " " + Grade1[i]); } catch (Exception ex) { System.out.println(ex.getMessage()); } } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

DB2 11 The Ultimate Database For Cloud Analytics And Mobile

Authors: John Campbell, Chris Crone, Gareth Jones, Surekha Parekh, Jay Yothers

1st Edition

1583474013, 978-1583474013

More Books

Students also viewed these Databases questions

Question

How to safely discipline or terminate an employee?

Answered: 1 week ago

Question

=+What sanctions are available to employers

Answered: 1 week ago

Question

=+ If strikes occur, are they legally regulated?

Answered: 1 week ago

Question

=+industrial action Under what circumstances can unions strike?

Answered: 1 week ago