In: Computer Science
JAVA PROJECT
Step 1: Create an application named YourInitials_Project 3 that uses a class to convert number grades to letter grades and another class for data validation. Make comments including your name, date, and project name as well as appropriate comments throughout your application that include the step number.
Step 2: Create code to print Titles
Step 3: Create a variable to hold user’s choice. Remember that all variables must begin with your initials and should be descriptive.
Step 4: Create code to continue while choice is equal to “y” or “Y”.
Step 5: Create a New Class named YourInitials_Console. The console class should contain two methods: getString getInt .
Step 6: In main(), declare a integer variable that will call the Console.getInt method to get the user input (“Enter numerical grade:”)
Step 7: Create a New Class named YourInitials_Grade to store the data for each grade. This class should include these three methods: public void setNumber(int number) public int getNumber() public String getLetter()
The grading criteria are as follows:
A 88-100
B 80-87
C 67-79
D 60-67
F <60
• The Grade class should have two constructors. The first one should accept no parameters and set the initial value of the number instance variable to zero. The second should accept an integer value and use it to set the initial value of the number instance variable.
Step 8: Create a New Object in the main class that will get the grade number from the Grade Class
Step 9: Create code to get and display the Letter Grade.
Step 10: Create code to ask the user to continue using the getString method from the Console.
Console
Welcome to the Letter Grade Converter
Enter numerical grade: 90
Letter grade: A
Continue? (y/n): y
Enter numerical grade: A
Error! Invalid integer. Try again.
Enter numerical grade: 87.9
Error! Invalid integer. Try again.
Enter numerical grade: 87
Letter grade: B Continue? (y/n):
YourInitials_Console.java :
//import package
import java.util.*;
//Java class
public class YourInitials_Console {
//object of Scanner class
static Scanner userInput=new Scanner(System.in);
//method to getInt() from user
public static int getInt()
{
//asking user numeric grade
System.out.print("Enter numerical
grade:");
//reading input
while(!userInput.hasNextInt())
{
//when numeric
grade is not entered then
System.out.println("Error! Invalid integer. Try again.");
//asking user
numeric grade
System.out.print("Enter numerical grade:");
userInput.next();
}
//read and return integer
return userInput.nextInt();
}
//getString() method
public static String getString()
{
return "Continue? (y/n):";
}
}
***********************************************************
YourInitials_Grade.java :
//Java class
public class YourInitials_Grade {
//instance variable
private int number;
//default constructor
public YourInitials_Grade()
{
this.number=0;//set number to
0
}
//constructor with parameters
public YourInitials_Grade(int number)
{
this.number=number;//set number to
number
}
//setter method
public void setNumber(int number)
{
this.number=number;//set number to
number
}
//getter method
public int getNumber()
{
return this.number;
}
public String getLetter()
{
//declaring variable to store
letter grade
String grade="";
//checking value of number
if(number>=88 &&
number<=100)
{
//when number is
between 88 to 100 then
grade="A";//set
grade
}
else if(number>=80 &&
number<=87)
{
//when number is
between 80 to 87 then
grade="B";//set
grade
}
else if(number>67 &&
number<=79)
{
//when number is
between 67 to 79 then
grade="C";//set
grade
}
else if(number>=60 &&
number<=67)
{
//when number is
between 60 to 67 then
grade="D";//set
grade
}
else if(number<60)
{
//when number is
less than 60 then
grade="F";//set
grade
}
//return letter grade
return grade;
}
}
*****************************************************
YourInitials_Project3.java :
//import package
import java.util.*;
//Java class
public class YourInitials_Project3 {
//main() method
public static void main(String[] args) {
//object of Scanner class
Scanner userInput=new
Scanner(System.in);
//print Titles
System.out.println("Welcome to the
Letter Grade Converter");
//declaring variable to store user
choice
String usersChoice="Y";
//using while loop
while(usersChoice.toUpperCase().contentEquals("Y"))
{
//continue while
loop till user enter Y
//declaring
integer variable
int
number=YourInitials_Console.getInt();
//object of
YourInitials_Grade class
YourInitials_Grade yourGrade=new YourInitials_Grade();
//call method
and set the grade number
yourGrade.setNumber(number);
//call method to
get and display letter grade
System.out.println("Letter grade: "+yourGrade.getLetter());
//call method to
continue while loop
System.out.print(YourInitials_Console.getString());
//reading
input
usersChoice=userInput.nextLine();
}
}
}
===============================================
Output :