CSC1110 Exercise Week 3
In this exercise, you complete prompts that give your practice with conditional statements and loops.
Setup
For this assignment you must use IntelliJ and follow the instructions in the Lab 3 Pre-Lab regarding installing Java and IntelliJ. You must also create a new project for this assignment and package with your MSOE username. Create a new Java program called Exercise3.java. Delete the contents of the file and copy the starter code below into the file. Edit the contents of the file to match your package name and information.
Instructions
The program consists of four stubbed out methods. You must implement all the methods based on the provided JavaDoc. Your output should resemble the sample output shown. You are only allowed to use the String methods charAt(), equals(), length(), and substring().
Starter Code
/*
* Course:
* Term
* Assignment Name
* Name:
* Created: 9/5/2025
*/
package username;
import java.util.Scanner;
/**
* Starter code for Exercise3. Fill in the stub out methods
* based on the provided javadoc for each.
*/
public class Exercise3 {
/**
* Asks the user for two words that are identical.
* Compare the words and print out whether they are the same
* or not.
* @param scan Scanner object to get user input
*/
public static void sameWord(Scanner scan){
//TODO
}
/**
* Asks the user for a word and then a letter. Prints
* whether the word contains the letter.
* @param scan Scanner object to get user input
*/
public static void containsLetter(Scanner scan){
//TODO
}
/**
* Asks the user for two words that are identical. If the
* user doesn't enter two identical words, ask again.
* @param scan Scanner object to get user input
*/
public static void sameWord2(Scanner scan){
//TODO
}
/**
* Asks the user for a word and a letter. Replace
* all occurrences of that letter with "*"
* @param scan Scanner object to get user input
*/
public static void makeStar(Scanner scan){
//TODO
}
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println("\nTesting: Same Word 1");
sameWord(scan);
System.out.println("\nTesting: Contains Letter");
containsLetter(scan);
System.out.println("\nTesting: Same Word 2");
sameWord2(scan);
System.out.println("\nTesting: Make Star");
makeStar(scan);
}
}
Sample Output
Example 1
Testing: Same Word 1
Enter a word
foo
Enter the same word again
bar
The words are not identical.
Testing: Contains Letter
Enter a word
foobar
Enter a letter
o
o was in foobar
Testing: Same Word 2
Enter a word
foo
Enter the same word again
bar
The words are not identical.
Try again.
Enter a word
foo
Enter the same word again
foo
The words are identical.
Testing: Make Star
Enter a word.
foobar
Enter a letter.
o
New word: f**bar
Example 2
Testing: Same Word 1
Enter a word
foo
Enter the same word again
foo
The words are identical.
Testing: Contains Letter
Enter a word
foobar
Enter a letter
c
c was not in foobar
Testing: Same Word 2
Enter a word
foo
Enter the same word again
foo
The words are identical.
Testing: Make Star
Enter a word.
foobar
Enter a letter.
c
New word: foobar
Submission
See your professor's instructions for details on submission guidelines and due dates.