Question

In: Computer Science

JAVA PROJECT Step 1: Create an application named YourInitials_Project 3 that uses a class to convert...

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):

Solutions

Expert Solution

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 :


Related Solutions

Create an Java application that uses a class to convert number grades to letter grades and...
Create an Java application that uses a class to convert number grades to letter grades and another class for data validation. Specifications The Grade class should have only one Instance Variable of type int. Use a class named 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 Grade class should have two constructors. The first one should accept no parameters and set the...
1. Create a new Java project called L2 and a class named L2 2. Create a...
1. Create a new Java project called L2 and a class named L2 2. Create a second class called ArrayExaminer. 3. In the ArrayExaminer class declare the following instance variables: a. String named textFileName b. Array of 20 integers named numArray (Only do the 1st half of the declaration here: int [] numArray; ) c. Integer variable named largest d. Integer value named largestIndex 4. Add the following methods to this class: a. A constructor with one String parameter that...
Java Create a Project named Chap4b 1. Create a Student class with instance data as follows:...
Java Create a Project named Chap4b 1. Create a Student class with instance data as follows: student id, test1, test2, and test3. 2. Create one constructor with parameter values for all instance data fields. 3. Create getters and setters for all instance data fields. 4. Provide a method called calcAverage that computes and returns the average test score for an object to the driver program. 5. Create a displayInfo method that receives the average from the driver program and displays...
Step 1: Create a new Java project called Lab5.5. Step 2: Now create a new class...
Step 1: Create a new Java project called Lab5.5. Step 2: Now create a new class called aDLLNode. class aDLLNode { aDLLNode prev;    char data;    aDLLNode next; aDLLNode(char mydata) { // Constructor data = mydata; next = null;    prev = null;    } }; Step 3: In the main() function of the driver class (Lab5.5), instantiate an object of type aDLLNode and print the content of its class public static void main(String[] args) { System.out.println("-----------------------------------------");    System.out.println("--------Create...
Create a Java project called Lab3B and a class named Lab3B. Create a second new class...
Create a Java project called Lab3B and a class named Lab3B. Create a second new class named Book. In the Book class: Add the following private instance variables: title (String) author (String) rating (int) Add a constructor that receives 3 parameters (one for each instance variable) and sets each instance variable equal to the corresponding variable. Add a second constructor that receives only 2 String parameters, inTitle and inAuthor. This constructor should only assign input parameter values to title and...
Create a Java project called Lab3A and a class named Lab3A. Create a second new class...
Create a Java project called Lab3A and a class named Lab3A. Create a second new class named Employee. In the Employee class: Add the following private instance variables: name (String) job (String) salary (double) Add a constructor that receives 3 parameters (one for each instance variable) and sets each instance variable equal to the corresponding variable. (Refer to the Tutorial3 program constructor if needed to remember how to do this.) Add a public String method named getName (no parameter) that...
Create a Java project called 5 and a class named 5 Create a second new class...
Create a Java project called 5 and a class named 5 Create a second new class named CoinFlipper Add 2 int instance variables named headsCount and tailsCount Add a constructor with no parameters that sets both instance variables to 0; Add a public int method named flipCoin (no parameters). It should generate a random number between 0 & 1 and return that number. (Important note: put the Random randomNumbers = new Random(); statement before all the methods, just under the...
Create a new Java project called lab1 and a class named Lab1 Create a second class...
Create a new Java project called lab1 and a class named Lab1 Create a second class called VolumeCalculator. Add a static field named PI which = 1415 Add the following static methods: double static method named sphere that receives 1 double parameter (radius) and returns the volume of a sphere. double static method named cylinder that receives 2 double parameters (radius & height) and returns the volume of a cylinder. double static method named cube that receives 1 double parameter...
In java: -Create a class named Animal
In java: -Create a class named Animal
THIS IS JAVA PROGRAMMING 1. Create a class named Name that contains the following: • A...
THIS IS JAVA PROGRAMMING 1. Create a class named Name that contains the following: • A private String to represent the first name. • A private String to represent the last name. • A public constructor that accepts two values and assigns them to the above properties. • Public methods named getProperty (e.g. getFirstName) to return the value of the property. • Public methods named setProperty ( e.g. setFirstName)to assign values to each property by using a single argument passed...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT