LAB EXERCISE 7:  Course Grade

Goal: In this exercise, you will learn how to:
1. Insert the Main Method (Main Entry Point to the Java Program)
2   Import a Java Class Library
3.  Declare Variables
4.  Create a Return Methods
5.  Create a Void Method
6.  Use a Nested If-Then Statement
7.  Create an Object
8.  Call an Object’s Method.

Program Specifications:
Create an application that will calculate the student’s total points achieved in COMSC-51 and then compute the course grade based on the following criteria:

The work for the course consists of the following:

a.     25 Lab Assignments @ 30 points ea.                                         750

b.    Project-  Create a Java program that connects to a database                   75

c.     Project-  Create a Java graphical user interface application                       75

d.    Final Exam                                                                                            100

Total:                                                                                                        1000 points

 

Class grade will be computed as follows:

900 - 1000 points = A

800 -  899  points = B

700 -  799  points = C

600 -  699  points = D

less than 600       =  F

 

 

User will enter the student’s ID, first and last name, total points for lab assignments (maximum 750), total points for the 2 projects (maximum 150) and final exam points.

A.  Pre-requisites:
1. Create a folder on your desktop Exercise-7

2. Launch Eclipse

3. Setup your Eclipse Workspace to point to the Exercise-6 folder
a. Select File-> Switch Workspace
b. Browse and select your Exercie-7 folder as your Workspace.



B. Requirements:

1.  Create a Java Project and name it as CourseGrade

2.  Create the first Class that will have the Main Method

a.       Name the Class as MainApp

b.       Choose the main method to insert into the class

        

3.  Create the second Class that will have the Constructor and Methods

a.      Name the Class as StudentGrade

b.      Do not select the main method stub

   

C. Requirements for the StudentGrade Class:

1.  Insert the import java.util.Scanner class which will allow data to be inputted from the console.

 

2.  Declare the String variables- id, lastName, firstName and letterGrade

 

3.  Declare the Integer variables- labPoints, projectPoints, finaExamPoints, and totalPoints

 

4.  Declare the constant variables and initialize
static String course = "COMSC-051 Java Programming Part 1"

final static String COLLEGE= "Los Medanos College"

5.  Create a void Method called getData()

a.  Declare the scanner input class objects

b.  Prompt the user to input the data.  

c.   Assign the inputted data to the variable

d.  Close the scanner input class object
Below is the code you can copy and paste

// declare the scanner object used to input the student's ID from the console
Scanner inputID= new Scanner(System.in);
System.out.println("Enter the Student ID: ");
id = inputID.nextLine();                    

// declare the scanner object used to input the student's last name from the console
Scanner inputLastName= new Scanner(System.in);
System.out.println("Enter the Last Name: ");
lastName = inputLastName.nextLine();

// declare the scanner object used to input the student's first name from the console
Scanner inputFirstName= new Scanner(System.in);
System.out.println("Enter the First Name: ");
firstName = inputFirstName.nextLine();

// declare the scanner object used to input the lab exercises points earned from the console
Scanner  inputLabPoints= new Scanner(System.in);
System.out.println("Enter the Total Points for Lab Exerices (Max Points: 750): ");
labPoints = inputLabPoints.nextInt();

// declare the scanner object  used to input the project points earned from the console
Scanner inputProjectPoints= new Scanner(System.in);
System.out.println("Enter the Points for Projects: (Max Points: 150):");
projectPoints = inputProjectPoints.nextInt();

// declare the scanner object used to input the final exam points earned from the console
Scanner inputFinalExam= new Scanner(System.in);
System.out.println("Enter the Points for Final Exam: (Max Points: 100): ");
finaExamPoints = inputFinalExam.nextInt();             

// close scanner input objects
inputID.close();
inputLastName.close(); 
inputFirstName.close(); 
inputLabPoints.close();
inputProjectPoints.close();
inputFinalExam.close();

 

6.  Create the Method called calcTotalPoints ()

a.  This method should not accept any argument

b.  This method will return an integer

c.   Insert the formula   totalPoints = labPoints + projectPoints + finaExamPoints

d.  Return totalPoints

 

7.  Create a Method called calcGrade()

a.  This method should not accept any argument

b.  This method will return a String

c.   Enter the Nested If-Then Statement to return the course grade

Below is the code you can copy and paste

// method to calculate the student's letter grade from the total points earned
String calcGrade(){
           if (totalPoints>=900) {
                     return letterGrade="A";
            } else if(totalPoints >=800 && totalPoints <900) {
                      return letterGrade="B";
            } else if (totalPoints >=700 && totalPoints <800) {
                      return letterGrade="C";
            } else if (totalPoints >=600  && totalPoints<700){
                      return letterGrade="D";
            } else {
                       return letterGrade="F";
             }   
}

 

       

 

Below is the code for the StudentGrade Class:

       

 

       

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 


D. Requirements for the MainApp Class:

1.  Add comments (documentation)– Program Description, Author and Date

2.  Create the instance of object called student from the StudentGrade class

3.  Call the object’s void method student.getData() to have user input the data 

4.  Declare the totalPoints variable as integer and assign the results from object’s method-  student.calcTotalPoints()

5.  Declare the letterGrade variable as a string and assign the results from object’s method  student.calcGrade()

6.  Display the output on the console.  Below is the code you and copy and paste.

// display the inputed data on the console
System.out.println("Student ID: " + student.id);
System.out.println("Student Name: " + student.firstName + " " + student.lastName);
System.out.println("College: " + StduentGrade.COLLEGE);
System.out.println("Course: "  + StduentGrade.course);

// display the returned results on the console
System.out.println("Total Points: " + totalPoints);
System.out.println("Course Grade: " + letterGrade);

 

Below is the code for the MainApp Class:

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 


E. Test:  

1.   Save your Java code

2.   Compile and run your Java program.

3.   Verify there is no syntax, logical or run-time errors.

4.   Use the following set of test data to determine if the application is calculating properly:

               

 

 

 

 

 

 

 

 

 

 

 

 

 

 


       

F. Submit your exercise in the Canvas Lab Exercise #7 Drop Box.

1. Submit the screen shot of the Eclipse Workbench window showing the Console output screen.
You can use Paint (save as JPG) or Word to paste the screenshot.

2. Zip up and submit the compressed CourseGrade subfolder that is in the Exercise-07 folder.
NOTE: Right click on the
subfolder and select Send to “Compress Folder”.  The file will have a file extension of .zip.