1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Dafna1 [17]
3 years ago
11

In this assessment, you will design and code a Java console application that validates the data entry of a course code (like IT4

782) 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 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. Your program output should look like this sample output:
Computers and Technology
1 answer:
ivolga24 [154]3 years ago
4 0

Answer:

The program is written using jCreator IDE

Comments are used for explanatory purpose

Program starts here

import java.util.*;

public class courecode

{

public static void main(String [] args)

{

 String ccode; // Declare course code as string

 Scanner input = new Scanner(System.in);

 System.out.print("Course code: "); // Prompt user for input

 ccode = input.nextLine();

 boolean flag = true; // Initialize a boolean variable to true

 if(ccode.length() != 6) // Check if length of course code is 6

 {

  System.out.print("Input length must be 6"); //Display message if length of input string is not 6

 }

 else // If length is 6

 {

  for(int i = 0; i<6;i++) //check validity if input string using for loop

  {

   if(i == 0) //Test for first character

   {

    //The following if statement will be executed if the first character is not i or I

    if(ccode.charAt(i) != 'i' && ccode.charAt(i) != 'I')

    {

     System.out.println("Invalid Course Code");

     System.out.println("The course code must start with an i or I");

     flag = false; //Set boolean variable to false

     break;

    }

   }

   else if(i == 1)

   {

    //The following if statement will be executed if the second character is not t or T

    if(ccode.charAt(i) != 't' && ccode.charAt(i) != 'T')

    {

     System.out.println("Invalid Course Code");

     System.out.print("The second letter of the course code must be t or T");

     flag = false; //Set boolean variable to false

     break;

    }

   }

   else

   {

    //The following if statement will be executed if any of the last 4 characters is not an integer

    if(!Character.isDigit(ccode.charAt(i)))

    {

     System.out.println("Invalid Course Code");

     System.out.print("The last 4 characters of the course code must be an integer");

     flag = false; //Set boolean variable to false

     break;

    }

   }

  }  

 }

 //The following statment checks if boolean variable flag is still true

 // If true, then the input course code is valid and the accompanying print statement will be executed

 if(flag)

 {

  System.out.print("The input course code is valid");

 }  

}  

}

Explanation:

Lines marked with // are comments

Check comments (//) for explanation

You might be interested in
Which of the following processes demonstrates that matter is made up of minute particles? (A) Difussion (B) Capillarity (C) Dist
Orlov [11]

Answer:

Evaporation

Explanation:

Evaporation is when water gets transferred from an object to the sun by thermal energy which is produced by the Sun. Evaporation can also be caused when heat causes water vapour to come, and it gets evapprated by the Sun and thermal energy. Each particle moves at once, so when this technology gets incurred on the Sun, it becomes an example.

8 0
3 years ago
What will be the output of following python code? a,b=3,4 a,b,c=b,a+3,b-1 print(a,b,c)​
Novosadov [1.4K]

Answer:

6 3 4

Explanation:

A=3+3

b=4-1

c=b=4

6 0
3 years ago
Answer all of the questions correctly and you will be amazing. Fill in Blanks
Naya [18.7K]
A.Chicken Street
B.You just got Vectored
5 0
4 years ago
if anyone is on a Chromebook, do you ever mean to press backspace, then you accidentally press the power button and think "OH CR
Pie

Answer:

every single day of my life

7 0
3 years ago
Read 2 more answers
Can someone help me with the 2.4 code practice question 2 on Edhesive???
Law Incorporation [45]

Answer:

sure, just show me the problem

5 0
4 years ago
Other questions:
  • you are configuring a wireless connection on your home router. Because you live in an apartment complex, the level of security i
    5·1 answer
  • Which of the following grinding methods is best suited to a shorter cylindrical workpiece?
    8·1 answer
  • What is the decimal equivalent of the largest binary integer that can be obtained with
    9·1 answer
  • Which of the following is not a component of Google Display ads' value proposition?
    9·1 answer
  • What does CRM stand for?
    10·1 answer
  • Pressing the Backspace key deletes the text to the of the insertion point. The left or the right?
    8·2 answers
  • You are tasked with leading a project to build a custom software testing tool for client. You have been provided with a set of p
    7·1 answer
  • A pangram is a sentence that contains all the letters of the English alphabet at least once. For example, the quick brown fox ju
    6·1 answer
  • You wrote a program to allow the user to guess a number. Complete the code to generate a random integer from one to 10.
    8·2 answers
  • WHAT DO YOU KNOW?<br> Why would you want to change your Table<br> Properties?
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!