0

Hi, can some one please help me run this code. i have another class named Course, that complied without error. Now in this code i am trying to take user inputs to find resulting gpa in a course. the following code does not compile, please help.

import java.util.*;
import javax.swing.*;

public class Result{

   ArrayList courseResult;

   
   //constructor
 public Result(courseResult cr)
    {
      courseResult= cr;
    }// end of constructor
   
   public void addCourse(){

   String name =JOptionPane.showInputDialog("Enter name of course: ");
          //downcast all strings into int float etc
   String inputMarks =JOptionPane.showInputDialog("Enter course marks: ");
           int marks = Integer.parseInt(inputMarks);
   String inputcHr =JOptionPane.showInputDialog("Enter course credit hours: ");
      int creditHr =Integer.parseInt(inputcHr);
   }


      Course c1 = new Course(name, marks, creditHr);
      courseResult.add(Course c1);
 
} //end of class
2
Contributors
1
Reply
2
Views
10 Years
Discussion Span
Last Post by masijade
0

Here

String name =JOptionPane.showInputDialog("Enter name of course: ");
          //downcast all strings into int float etc
   String inputMarks =JOptionPane.showInputDialog("Enter course marks: ");
           int marks = Integer.parseInt(inputMarks);
   String inputcHr =JOptionPane.showInputDialog("Enter course credit hours: ");
      int creditHr =Integer.parseInt(inputcHr);
   }


      Course c1 = new Course(name, marks, creditHr);
      courseResult.add(Course c1);

I assume you meant

String name =JOptionPane.showInputDialog("Enter name of course: ");
          //downcast all strings into int float etc
   String inputMarks =JOptionPane.showInputDialog("Enter course marks: ");
           int marks = Integer.parseInt(inputMarks);
   String inputcHr =JOptionPane.showInputDialog("Enter course credit hours: ");
      int creditHr =Integer.parseInt(inputcHr);


      Course c1 = new Course(name, marks, creditHr);
      courseResult.add(c1);
   }

not the move of the "}" character, and the change of the add method (which would have produced a different error after you resolved the error with the "}" symbol).

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.