Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Overview This is an interactive program that requires you to implement a collect

ID: 659688 • Letter: O

Question

Overview

This is an interactive program that requires you to implement a collection of utility methods.

Specification

doGrades()

Write a static class method named doGrades that uses a repetition control statement to query the user to enter in a letter grade.

The method does not return anything, nor does it receive any parameters.

The method checks if an entered value is a valid grade and prints a status message.

The input loop is terminated when an ampersand (&) is entered (sentinel value). Issue a confirmation prompt when the user enters the sentinel value.

Validity checking of the grade value is defined in the isGrade() method.

isGrade()

Write a static class method named isGrade that receives a char as a parameter. It returns the boolean value true if the received character is a valid grade value; otherwise, it returns false.

Valid grade values can be either upper- or lower-case.

Valid grades values are:

doZipcodes()

Write a static class method named doZipcodes that does not return anything, nor does it take any parameters.

Enter into a loop prompting the user to enter a five digit zipcode.

Validate the zipcode and print a status message.

If the user enters a zipcode value of 0 (zero), then issue a confirmation prompt to make sure they are are really done entering zipcodes. Terminate the loop if they answer yes to the confirmation prompt.

Zipcode validation is performed by the isZipcode() method.

isZipcode()

Write a static class method named isZipcode that receives a the entered zipcode stored in a String object as a parameter. Return the boolean value false if any of the following are true:

the String length is not equal to five (5),

the String contains a non-digit character,

the String when converted to an int is less than 1 or greater than 99999;

otherwise, return the boolean value true.

doRanges()

Write a static class method named doRanges() that takes no parameters and returns nothing (i.e. it has a void return type).

Use a repetition control statement to get the following integer inputs:

minimum value

maximum value

value

Test to see if the value falls between the minimum and maximum values, and print a status message.

The loop is terminated if the minimum and maximum values are equal. Issue a confirmation prompt to make sure the user is done comparing numbers.

The range check is implemented in the inRange() method.

inRange

Write a static class method named inRange that takes three int values as parameters. The following is the method header.

Return -1 if the value is less than the minimum value. Return 0 if the value is greater than or equal to the minimum value and is less than or equal to the maximum value. Return 1 if the value is greater than the maximum value.

main

Write a static class method named main() that calls methods that validate letter grades, validate zipcodes, and test if a number fall in a range of values.

The following methods are called:

Hints

Converting a String object into an int can be accomplished using the int Integer.parseInt(String) static class method defined in the Integer class that comes with the JSDK.

A specific String character can be accessed using the char stringObject.charAt(int) instance method defined in the String class.

This program requires you to write the following methods having the names listed.

Be sure your prompts are short, yet descriptive. In some cases a two line prompt may be necessary.

Example Output

Note: For documentation purposes user inputs are inside angle-brackets.

Explanation / Answer

please find the required solution:

import java.util.Scanner;


public class UtilityClss
{
   public static void doGrades()
   {
       Scanner scanner=new Scanner(System.in);
       String grade;
       do
       {
           System.out.println("Enter a grade (A, B, C, D, F, W, Y, I, P, Z, or & to exit):");
           grade=scanner.next();
           if(isGrade(grade))
           {
               if(!grade.equals("&"))
                   System.out.println("Grade '"+grade+"' is valid.");
           }
           else
               System.out.println("Grade '"+grade+"' is invalid.");
       }
       while(!grade.equals("&"));
       scanner.close();
   }
   public static boolean isGrade(String grade)
   {
       String temp="ABCDFWYIPZabcdfwyipz&";
       return grade.length()==1 && temp.contains(grade);
   }
   public static void doZipcodes()
   {
       Scanner scanner=new Scanner(System.in);
       String zipcode;
       do
       {
           System.out.println("Enter a five digit zipcode (0 to exit):");
           zipcode=scanner.next();
           if (isZipcode(zipcode))
           {
               System.out.println("zipcode " + zipcode + " is valid");
           }  
       }
       while(!zipcode.equals("0"));
       scanner.close();
   }
   public static boolean isZipcode(String zipcode)
   {
       try
       {
           Integer.parseInt(zipcode);
           if(zipcode.length()>5)
           {
               System.out.println("*** error:zipcode '"+zipcode+"' too long");
               return false;
           }
           else if(zipcode.length()<5)
           {
               System.out.println("*** error:zipcode '"+zipcode+"' too short");
               return false;
           }
           return true;
       }
       catch(NumberFormatException e)
       {
           System.out.println("*** error:zipcode '"+zipcode+"' is not a number");
           return false;
       }
   }
   public static void main(String[] args)
   {

doGrades();
       doZipcodes();
   }
}

Sample output:

Enter a grade (A, B, C, D, F, W, Y, I, P, Z, or & to exit):
a
Grade 'a' is valid.
Enter a grade (A, B, C, D, F, W, Y, I, P, Z, or & to exit):
e
Grade 'e' is invalid.
Enter a grade (A, B, C, D, F, W, Y, I, P, Z, or & to exit):
&
Enter a five digit zipcode (0 to exit):
51
*** error:zipcode '51' too short
Enter a five digit zipcode (0 to exit):
123
*** error:zipcode '123' too short
Enter a five digit zipcode (0 to exit):
yyyyy
*** error:zipcode 'yyyyy' is not a number
Enter a five digit zipcode (0 to exit):
12345
zipcode 12345 is valid
Enter a five digit zipcode (0 to exit):
0