Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

need help with code have alot of errors Task: Create a project called ColorCode_FirstName_LastName or Lab5_FirstName_LastName. Remember to include comments summarizing the program. 1. Declare

need help with code have alot of errors image text in transcribed
image text in transcribed
image text in transcribed
Task: Create a project called ColorCode_FirstName_LastName or Lab5_FirstName_LastName. Remember to include comments summarizing the program. 1. Declare a Scanner that accepts input from the keyboard. 2. Declare the following five variables: - A variable of type int that will hold the user's input - A variable of type int that will hold the result of dividing this input by 16 - A variable of type int that will hold the result of performing mod 16 on this input - A variable of type String that will hold the most significant digit - A variable of type String that will hold the least significant digit 3. Prompt the user to enter the amount of red as an integer from 0 to 255 . Use the appropriate method of the Scanner class to assign the user's input to the appropriate variable. 4. Use a logical operator within an if statement to check that the number is between 0 to 255 , inclusive. - If the number is, proceed with the remaining steps within this if block. - Else, the number is not valid. Print a statement to the console indicating the user provided an invalid input. Refer to the following table for steps 5 and 6. \begin{tabular}{|c|c|} \hline Hexadecimal & Decimal \\ \hline 0 & 0 \\ \hline 1 & 1 \\ \hline 2 & 2 \\ \hline 3 & 3 \\ \hline 4 & 4 \\ \hline 5 & 5 \\ \hline 6 & 6 \\ \hline 7 & 7 \\ \hline 8 & 8 \\ \hline 9 & 9 \\ \hline A & 10 \\ \hline B & 11 \\ \hline C & 12 \\ \hline D & 13 \\ E & 14 \\ \hline F & 15 \\ \hline \end{tabular} 5. The hexadecimal value will consist of two digits. To get the first digit, divide the user's input by 16 using integer division. - If the result is any of the numbers from 10 to 15 , assign the corresponding letter to the String for the most significant digit. - Else, assign the corresponding digit to the String for the most significant digit. 6. To get the second digit, perform a modulo operation with 16 on the user's input. - If the result is any of the numbers from 10 to 15 , assign the corresponding letter to the String for the least significant digit. - Else, assign the corresponding digit to the String for the least significant digit. 7. Print the amount of red as a hexadecimal value to the console. The following is the program flow for this program if the user enters 175 as the decimal value: Please enter the amount of red as a decimal number: 175 Your number in hexadecimal is AF The following is the program flow for this program if the user enters 289 as the decimal value: Please enter the amount of red as a decimal number: 289 Invalid input. Enter a number from 0 to 255

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Pro SQL Server Wait Statistics

Authors: Enrico Van De Laar

1st Edition

1484211391, 9781484211397

More Books

Students also viewed these Databases questions