Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hi, the compiler I am using is JGrasp. Please if anyone can help that would be great. Also please follow the guidelines that are given

Hi, the compiler I am using is JGrasp. Please if anyone can help that would be great. Also please follow the guidelines that are given in these pictures. This is an early CS class so please do not do anything very complex that would be too far in my knowledge of programming. The materials I should know are things of the for, if, while/do loops. along with many methods and parameters. Also switch statements. Things of those nature, but if you do use other useful tools please do not use them a lot. Thank you so much for helping me. I have included a shell at the bottom of this question. Please use that when making the code.

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

---------------------------------------------

SHELL:

 //include commments about your progarm import java.util.Scanner; public class DecryptTelephone { final static String AREA_CODE = "231"; final static String VALID_DIGITS = "0123456789"; final static String CHARS_TO_IGNORE = "- \t"; public static void main( String [] args ) { //declrae variables of type string: encryptNumber, validDigits, decryptedNumber //declare decryiptShift of type integer, which is the number of the shifts to decrypt String validNumberDescription = " A valid number has 10 digits " + "plus any number of spaces and hyphens "; //declare doAgain of type boolean and set it to true //create a scnner object //as lon as doAgain is true { //set the validDigits to null //prompt the user to enter a phone number //get the encrypted phone number and store it in the variable encryptedNumber //call the method extractValidDigits and store the result in the variable validDigits //as long as validDigits is null { //output an error message //prompt the user to get another phone number //store the user's input in the encryptedNumber //call the method extractValidDigits } //call the method getDecryptedShift and store the result in the decryptShift //call the method decryptedPhoneNumber and store the result in the decryptedNumber //if decryptedNumber is not null { //calcaulate (20 - decryptedShift) %10 and storeit in encrptShift //output the decrypted phone number and the encryptShift } //else { //output the phone number and a message that the phone number cannot be decrypted with the given area code } //ask the user if they want to enter another phone number //if the user's says no then change the variable content called doAgain } //output a goodbyr message } /** * Determines if phone number is valid, in which case it Extracts the valid * digits from phoneNumber and returns them in a String. * @param phoneNumber is the encrypted phone number. * @return a String containing only the valid digits from phoneNumber * if phoneNumber is determined to be valid * otherwise null is returned. */ public static String extractValidDigits(String encryptedNumber) { //declare the varaible goodDigits as a String and set it to an empty string, will hold digits with whitespace removed //declare a counter of type int and set it to zero. you can call it i //as long as the goodDigits is not null and the counter is less than the length of the encryptedNumber { //get the character at the index i in the encryptedNumber // if character is a number, increment the goodDigits by 1 { } // else { // if character is not a number, it must be space, tab, or -, if it is not space or - then set goodDigits to null } //increment i by 1 } // 10 digits are required //if gooddigits is not null and the length is not 10 //return null //return goodDigits return "";//this line needs to be removed once you complete this method } // end method extractValidDigits public static int getDecryptShift(String encryptedDigits) { int unshiftedInt = Character.getNumericValue(AREA_CODE.charAt(0)); //get the first character in the String encryptedDigits and store it in the variable charDigit //get the numeric value of charDigit and store it in the variable shiftedInt //declare the variable shift and set it to 10 - (shiftedInt - unshiftedInt) // return the variable shift return 0;//this line must be removed after you are done with this method } public static String decryptPhoneNumber(String encryptedDigits, int shift) { //declare a varaible of type char called charDigit //declare an int variable called digit //declare a variable of type string called decryptedNumber and set it to empty string //for ( i = 0 to 3 { //get the character at the index i of encryptedDigits //get the numeric value of the character and store it in a variable called digit //decryptedNumber += (digit + shift) % 10; } //if the decryptedNumber equals to AREA_CODE, means that we have the correct area code { //for(i = 3 to 9 { //get the charcter at the index i //get its numericValue and store it in the varaible called digit //decryptedNumber += (digit + shift) % 10; } // Reformat the decrypted number as xxx-xxx-xxxx. you need to use the substring method to add dashes in between } // else { //set decryptedNumber to null; } //return decryptedNumber; return null;//this line must be remove after you are done with this method. } // end method decryptPhoneNumber } 

Telephone Number Processing Due: Fridav June 23rd HW #2 CSC 15 Obiectives: To practice all the materials from chapter 1 through 4 Read this document completely before writing your program, it will help you to understand what the problem is and how to approach solving it Often on a web page, the user is asked to supply personal information, such as a telephone number. Your program should take an input from the keyboard representing a telephone number We will consider that the input is a valid telephone number if it contains exactly 10 digits and any number of hyphen (-) and whitespace characters. Keep prompting the user for a telephone number until the user gives you a valid one. Once you have a valid telephone number, you should assume that the digits (only the digits, not the hyphen[s] nor the whitespace) in the telephone number have been encrypted by shifting each number by a constant value. For instance, if the shift is 2, a 0 becomes a 2, a 1 becomes a 3, a 2 becomes a 4, an 8 becomes a 0, a 9 becomes a 1. To decrypt However, we know that the user is from New York where the decrypted area code, represented by the first three digits of the input, is 212 Your program needs to decrypt the telephone number and output the decrypted telephone number with the format 212-xxx-xxxx, as well as the shift value of the encryption. If there was an error in the input and the area code cannot be decrypted to 212, you should output that information. Added Variation: You must put a loop in the main method that will ask if the user wants to decrypt another phone number long as the user replies with a Y'; . The loop mu st continue getting encrypted phone numbers and decrypting them as See Sample output from running the program towards the end of this document. IMPORTANT: Read these requirements ALL the way through before you begin designing your ram! Develop your design BEFORE you start coding! REQUIREMENTS:. You must use good style: meaningful variable names and good, consistent indentation

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

Expert Performance Indexing In SQL Server

Authors: Jason Strate, Grant Fritchey

2nd Edition

1484211189, 9781484211182

More Books

Students also viewed these Databases questions

Question

What is conservative approach ?

Answered: 1 week ago

Question

What are the basic financial decisions ?

Answered: 1 week ago

Question

How many Tables Will Base HCMSs typically have? Why?

Answered: 1 week ago

Question

What is the process of normalization?

Answered: 1 week ago