ASSIGNMENT NO. 1

A. Write code to generate a random character between 48 and 122 (inclusive). You can do this by first generating an integer value between 48 and 122 and then cast it as a char. Do this in a loop 100 times, concatenating each character to a String as each character is generated. When the loop completes, the string will contain 100 characters. Print the string of 100 characters.

Remember that to generate a random number between a start and end value, the formula is:

(int)(start + Math.random()*(end-start+1))

Loop through the string you just created, character by character using charAt(i), to count and print the following:

  • The total number of characters in the string (better be 100)
  • The total number of digits
  • The total number of letters
  • The total number of upper-case letters
  • The total number of lower-case letters
  • The total number of characters not a letter or digit

B. Write a program that prompts the user to enter an enhanced Social Security number as a string in the format DDD-DD-DDDX where D is a digit from 0 to 9. The rightmost character, X, is legal if it’s between 0 and 9 or between A to Z.

The program should check whether the input is valid and in the correct format. There’s a dash after the first 3 digits and after the second group of 2 digits.

If an input is invalid, print the input and the position in the string (starting from position 0) where the error occurred.

If the input is valid, print a message that the Social Security number is valid.

Continue to ask for the next Social Security number but stop when a string of length 1 is entered.

Test cases

ABC

123-A8-1234

12-345-6789

12345-6789

123-45-678A

123-45-678AB

A

ASSIGNMENT NO. 2

Homework 5 CISC 1115 TR11

Your Java program will be reading input from a file name strInput.txt. Each record contains

String firstname

String lastName

String strSalary (which will be converted to a double if it’s valid – see below)

char status

String cityState (city and state and combine together but separated by a comma)

Sample input:

Ira Rudowsky 87654.32 F Brooklyn,NY

Jane Doe 987609.87 F NY,NY

Mickey Mantle 345678.30 D Orlando,FL

Fran Young 10456.82 G Boston,MA

Richard Clark 67890.32 D Washington,DC

Jack Smith 23489A.82 D Houston,TX

Serena Williams 1295609.87 D Denver,CO

Read from the file one record at a time and process as follows:

  • Any record whose status code is neither D or F should be written to the screen indicating the error. The next record should be read in.
  • If the status code is D or F, validate the salary that it contains only digits and one decimal point 3 positions from the right (indicating cents).
    • If the salary is invalid, print the entire record to the screen, indicating the error (char at position x is not a digit or period is missing or period is in the wrong position).
    • If the salary is valid, convert it to a double.
    • If the status code is D, compute the bonus (double) as 12.5% of salary and 18% if the status code is F.
  • Separate the cityState into two individual Strings named city and state. Use the position of the comma to help extract the city portion before the comma and the state after the comma (use indexOf to find the comma and substring to extract the two parts)
  • Each record that has a status of D should be written to a file named strOutputD and those record with status of F should be written to a file named strOutputF.
    • For both files, each record printed should include firstName, lastName, status, salary, bonus, city and state (without the comma)
  • When all records have been read in, print to the screen the number of D, F and incorrect records processed.
  • Submit your code, the output on the screen and the output in the two files.

    Make your order right away

    Confidentiality and privacy guaranteed

    satisfaction guaranteed