Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

class Main { public static void main(String[] args) { // TODO: First coding sess

ID: 3742736 • Letter: C

Question

class Main {
public static void main(String[] args) {
    // TODO: First coding session
    // Create a short program that prompts the user for their name,
    // reads the name, and replies with a greeting by name, starting
    // with "Hello, "
    // Use java.util.Scanner to read from System.in.
    // Use System.out.println() to reply.
  
    // TODO: Second coding session
    // Use the Scanner's type-specific methods to read user input
    // as int, double, boolean and String, in that order.
    // Output them all on one line separated by spaces, in the same order.
  
    // In the questions below use length(), toLowerCase(), toUpperCase(),
    // trim(), charAt(int), indexOf(int ch), indexOf(String),
    // replace(char from, char to), substring(int from), and/or
    // substring(int from, int to)
  
    // TODO: Third coding session.
    // Modify "The quick brown fox jumps over the lazy dog." to make
    // 1. all consonants be lower case
    // 2. all vowels to be upper case
    // 3. output the resulting string
    // Consider using String.toLowerCase() and String.replace().
  
    // TODO:
    // Extract and print the word "fox" using indexOf() and substring() methods.


    // TODO: Fourth coding session.
    // Print field of asterisks (*) per the instructions.

    // TODO:
    // Print field of double quotes (") per the instructions.

}

}

Instructions from your teacher:

Warm up

Use Scanner and System.in to read data from the user, then System.out to print it back out.

Use Scanner.nextLine() and related .next*() methods.

Use String methods.

Field of stars

After doing the first N exercises, use the special characters and to output this flag-like set of stars. Don't use spaces or tabs in your println() calls, use " " instead.

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

After getting the stars to print, add another set of code to print with double quotes (") instead of asterisks (*).

" " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " "

Explanation / Answer

import java.util.Scanner;

public class Main {

public static void main(String[] args) {

Scanner scanner = new Scanner(System.in);

//TODO:First coding session

System.out.println(" * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *");

System.out.println(" " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " "");

System.out.print("Please Enter your name: ");

String name = scanner.nextLine();

System.out.println("Hello " + name);

//TODO:Second coding session

System.out.println(" * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *");

System.out.println(" " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " "");

int i = scanner.nextInt();

double d = scanner.nextDouble();

boolean b = scanner.nextBoolean();

String str = scanner.nextLine();

System.out.println(i + " " + d + " " + b + " " + str);

//TODO:Third coding session

String text = "The quick brown fox jumps over the lazy dog.";

String s = text.toLowerCase();

s = s.replace('a', 'A');

s = s.replace('e', 'E');

s = s.replace('i', 'I');

s = s.replace('o', 'O');

s = s.replace('u', 'U');

System.out.println(s);

String word = s.substring(s.indexOf('f'), s.indexOf('f') + "fox".length());

System.out.println(word);

//TODO:Fourth coding session

System.out.println(" * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *");

System.out.println(" " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " "");

}

}