Question: 6.6 LAB: Student Level Student with 0-29 credits is a Freshman, 30-59 credits is aSophomore, 60-89 credits is a Junior, and 90 credits of more

6.6 LAB: Student Level

Student with 0-29 credits is a Freshman, 30-59 credits is aSophomore, 60-89 credits is a Junior, and 90 credits of more are aSenior.

Write a Java enum StudentLevel to represent these levels. Anenum is defined in the same manner as a class, except uses thekeyword enum in place of the keyword class and has a list of Javaidentifiers following the opening brace. Like a class an enum canhave instance variables, a constructor and methods. If aconstructor is specified then each of the identifiers must befollowed by parentheses with an argument list corresponding to theconstructor parameters. For the enum StudentLevel, define:

  • define instance variables label, atLeast, and atMost
  • provide a constructor accepting values for all instancevariables
  • provide get methods for atLeast and atMost
  • define a toString method to return the label
  • use as the enum values the level in all upper case, e.g.,FRESHMAN
  • pass as constructor arguments the appropriate values, e.g.,FRESHMAN("Freshman", 0, 29), for each of the levels.

Write a Student class, define:

  • instance variables name and creditsEarned
  • constructor with name and creditsEarned parameters
  • constructor with just a name parameter and defaultscreditsEarned to be 0
  • get methods for name, creditsEarned
  • getStudentLevel method that returns the StudentLevel based onthe number of creditsEarned, that is returns the level whichcreditsEarned is >= a level's atLeast and <= a level's atMostvalues
  • define an addCredits method which adds a number of credits andreturns an updated StudentLevel.

Complete the supplied Main program by only adding the additionalarguments to the printf statements.

On input of:

John 36 5Bill 53 15

The output will be:

John has 36 credits, John is a SophomoreJohn needs 24 credits to move up a levelOn earning 5 more credits John is a SophomoreBill has 53 credits, Bill is a SophomoreBill needs 7 credits to move up a levelOn earning 15 more credits Bill is a Junior

For this LAB only numeric literal that can be used inthe Student class is 0, to compare creditsEarned with the rangesuse atLeast() and or atMost() methods of the appropriate instanceof StudentLevel

For this LAB if statements are notallowed in the Main class

For this LAB numeric literals other than 1 are notallowed in the Main class

Provided files:

Current File: Main.java

import java.util.Scanner;

public class Main {

public static void main(String[] args){
Scanner scanner = newScanner(System.in);

while (scanner.hasNext()){
Stringname = scanner.next();
intcredits = scanner.nextInt();

Studentstudent = new Student(name, credits);

System.out.printf("%s has %d credits, %s is a %s" /*replace with arguments needed */ )
System.out.printf("%s needs %d credits to move up a level"/* replace with arguments needed */);
credits =scanner.nextInt();
StudentLevel studentLevel =student.addCredits(credits);

System.out.printf("On earning %d more credits %s is a %s",/* replace with arguments needed */);
}
}
}

There is also Student.java and StudentLevel.java but they areempty to start.

Step by Step Solution

3.40 Rating (163 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Heres the solution to the given problem StudentLeveljava java Copy code public enum StudentLevel ... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!