Solved-Lab 8- Solution

$30.00 $19.00

This lab will help you to practice using Strings. Write a method that takes a string argument and returns a new string that is the reverse of that argument. For instance, when called like this from main: String s = “Hello”; String t = reverse(s); System.out.println(t); the method should display: olleH Write a method that…

You’ll get a: . zip file solution

 

 
Categorys:
Tags:

Description

5/5 – (2 votes)

This lab will help you to practice using Strings.

  1. Write a method that takes a string argument and returns a new string that is the reverse of that argument. For instance, when called like this from main:

String s = “Hello”;

String t = reverse(s);

System.out.println(t);

the method should display:

olleH

  1. Write a method that finds the character in a string that comes last alphabetically. For instance, when the method is called like this from main:

String s = “bizarre”;

char last = lastCharAlphabetically(s);

System.out.println(“last = “ + last);

the method should display:

last = z

  1. Write a method to prompt the user to choose a password. The password must contain at least one uppercase letter, one lowercase letter, one digit, and one special character (defined as a character that is neither a letter nor a digit). If the string the user enters does not meet these requirements, display an error message indicating the unmet requirement(s) and re-prompt the user. Below is a sample execution.

Please choose a password: mypassword

Your password must contain a uppercase letter

Your password must contain a digit

Your password must contain a special character

Please choose a password: myPassword

Your password must contain a digit

Your password must contain a special character

Please choose a password: my_Password

Your password must contain a digit

Please choose a password: my_Password1234

Password = my_Password1234

  1. Write a method that takes an array of strings and orders the strings in the array by the number of vowels (a, e, i, o, or u) in each string (from fewest to most vowels).

If two strings have the same number of vowels, order them by which one comes first alphabetically, ignoring case. For instance, when called like this from main:

String[] strings = {“hello”, “apple”, “hat”, “cat”, “Banana”, “AAA”};

System.out.println(Arrays.toString(strings));

orderByVowels(strings);

System.out.println(Arrays.toString(strings));

The output should be:

[hello, Apple, hat, cat, Banana, AAA]

[cat, hat, Apple, hello, AAA, Banana]

  1. Write a method that takes a string of the form LastName, FirstName and return FirstInitial. LastName. For instance, when called from main like this:

String s = “Doe, John”;

String t = formatName(s);

System.out.println(t);

the output should be:

J. Doe

Rubric

For each question (20 points total):

  • Computes the correct answer: 2 point

  • Complies with all directions: 1 point

  • Follows style guidelines and commented as appropriate: 1 point