Question

In this assessment, you will design and code a Java console application that validates the data...

In this assessment, you will design and code a Java console application that validates the data entry of a course code (like IT4782) and report back if the course code is valid or not valid. The application uses the Java char and String data types to implement the validation. You can use either the Toolwire environment or your local Java development environment to complete this assignment.

The requirements of this application are as follows: The application is to read a course code entered by the user from the keyboard. The course code is made of 5 characters and should follow these rules:

• First character is always an upper case I or a lower case i

• Second character is always an upper case T or a lower case t

• Third, fourth, fifth, and sixth characters are always digits (0-9)

The application then validates the course code against above the rules and prints a message if the course code is valid or not. If the course code is not valid, the application should print a message explaining why the course code is not valid.

Use these course codes to test your application: IT4782 iT4782 OT4782 it&782 .

Also use commenting throughout your code to explain what each statement is doing and why it was needed. Successful completion of this assignment will show a valid message or an invalid message for the entered course code. In addition, if the course code is invalid, the application should identify the reason for the invalidation.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Java Program:

import java.util.Scanner;

public class CourseCodeValidator {

   public static void main(String[] args) {
       // Scanner class to read input from user from the keyboard
       Scanner scan = new Scanner(System.in);
      
       //asking user input/course code
       System.out.println("Enter the course code:");
       String courseCode = scan.next();
      
       //condition course code length must be 6
       if(courseCode.length() == 6) {
           //validating first character of course code
           if(courseCode.charAt(0)=='I' || courseCode.charAt(0)=='i') {
              
               //validating second character of course code
               if(courseCode.charAt(1)=='T' || courseCode.charAt(1)=='t') {
                  
                   //counter to count the number of digits in the course code
                   int counter = 0;
              
                   //loop to traverse on Third, fourth, fifth, and sixth characters of course code
                   for(int i=2;i<courseCode.length();i++) {
                      
                       //getting characters from course code
                       char ch = courseCode.charAt(i);
                      
                       //validating Third, fourth, fifth, and sixth characters of course code
                       if(ch >= '0' && ch <= '9')
                   {
                           //increment the counter
                           counter = counter + 1;
                   continue;
                   }else {
                           System.out.println(courseCode+" course code is invalid.");
                           System.out.println((i+1)+" character should be digit(0-9).");
                   }
                   }
                   //if counter is 4,it means,Third, fourth, fifth, and sixth characters are digits
                   if(counter ==4) {
                       System.out.println(courseCode+" course code is valid.");
                   }
               }else {//invalid condition
                   System.out.println(courseCode+" course code is invalid.");
                   System.out.println("Second character should be either 'T' or 't'.");
               }
              
           }else {//invalid condition
               System.out.println(courseCode+" course code is invalid.");
               System.out.println("First character should be either 'I' or 'i'.");
           }
       }else { //invalid condition
           System.out.println(courseCode+" course code is invalid.");
           System.out.println("Course code is made of 6 characters.");
       }  
   }
}

Output: Case 1

Enter the course code:
IT4782
IT4782 course code is valid.

Output: Case 2

Enter the course code:
iT4782
iT4782 course code is valid

Output: Case 3

Enter the course code:
OT4782
OT4782 course code is invalid.
First character should be either 'I' or 'i'.

Output: Case 4

Enter the course code:
it&782
it&782 course code is invalid.
3 character should be digit(0-9).

Add a comment
Know the answer?
Add Answer to:
In this assessment, you will design and code a Java console application that validates the data...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Debug and fix the Java console application that uses 2 dimensional arrays but the application does...

    Debug and fix the Java console application that uses 2 dimensional arrays but the application does not compile nor execute. Student enters only integers to select courses for registration from a menu. No data type validation of the user menu selection is checked or required. The program terminates only when the student closes it. No registration of other courses not displayed by the program . No registration more than once for the same course. No registration for more than 9...

  • Design and implement a Java program (name it PasswordTest) that accepts a string from the user...

    Design and implement a Java program (name it PasswordTest) that accepts a string from the user and evaluates it as a password, giving it a valid or invalid verdict A good password will be at least 8 characters and includes at least one lower-case letter, at least one upper-case letter, at least one digit, and at least one character that is neither a letter nor a digit. Your program will need to check each character in the string in order...

  • Please write code using Python. Rubric Assignment Solution Total: 100 pts Program successfully retrieves and validates...

    Please write code using Python. Rubric Assignment Solution Total: 100 pts Program successfully retrieves and validates user input 15 pts Morse Code Function Created 10 pts Function Uses Parameters to get input message 15 pts Function successfully converts passed message to Morse Code and returns the Morse Code equivalent of message 45 pts Program calls Morse Code function and outputs the result of the function (i.e. the actual Morse Code) 15 pts Main Function Requirement Part 2 MUST have a...

  • Count Occurrences in Seven Integers Using Java Single Dimension Arrays In this assignment, you will design...

    Count Occurrences in Seven Integers Using Java Single Dimension Arrays In this assignment, you will design and code a Java console application that reads in seven integer values and prints out the number of occurrences of each value. The application uses the Java single dimension array construct to implement its functionality. Your program output should look like the sample output provided in the "Count Occurrences in Seven Integers Using Java Single Dimension Arrays Instructions" course file resource. Full instructions for...

  • Homework 3: Input Validation 1   Objectives control structures console-based user input using Scanner class writing complete...

    Homework 3: Input Validation 1   Objectives control structures console-based user input using Scanner class writing complete programs using two classes: client and supplier 2   User Interface Specification This is a console-based I/O program. Display should go to System.out (print or println) and the program will get user input using the Scanner class. The flow of execution should be as follows: When the program starts, display a one-line introduction to the user Display a menu with 5 options 1. validate zip...

  • JAVA 2. (8 points) Write a code segment which prompts the user to enter the price...

    JAVA 2. (8 points) Write a code segment which prompts the user to enter the price of a tour and receives input from the user. A valid tour price is between $52.95 and $259.95, inclusive. Your program should continue to repeat until a valid tour price has been entered. If the user enters an invalid price, display a message describing why the input is invalid. You may assume that the user only enters a real number. The user will not...

  • Need help with this java assignment please as soon as possible. Also, please make it as...

    Need help with this java assignment please as soon as possible. Also, please make it as simple as possible so I can figure out how you did it if possible. Thanks so much people of chegg. Project 22-2: Validate user entries Validator Test Name: Joel Murach Age: Sales: 10 OK Exit A validation dialog box Invalid Entry XAge is a required field. OK A validation dialog box Validator Test Name: Joel Murach Age: 37 Sales: $100,000.00 OK Operation . This...

  • Create a program via Java that has atleast 8 characters long, one upper case, and one...

    Create a program via Java that has atleast 8 characters long, one upper case, and one lower case, and one digit. here is my code:     public static void main(String[] args)     {         //variables defined         String passwords;         char password =0;                 //settings up password condition to false         boolean passwordcondition= false;         boolean size=false;         boolean digit=false;         boolean upper=false;         boolean lower=false;         //inputting a scanner into the system         Scanner keyboard = new Scanner(System.in);...

  • create java application with the following specifications: -create an employee class with the following attibutes: name...

    create java application with the following specifications: -create an employee class with the following attibutes: name and salary -add constuctor with arguments to initialize the attributes to valid values -write corresponding get and set methods for the attributes -add a method in Employee called verify() that returns true/false and validates that the salary falls in range1,000.00-99,999.99 Add a test application class to allow the user to enter employee information and display output: -using input(either scanner or jOption), allow user to...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT