Question
here are some UML diagrams and classes for help import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; /** If you register an object of this class as a listener
here are some UML diagrams and classes for help
import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent;
/** If you register an object of this class as a listener to any object of the class JFrame, the object will end the program and close the JFrame, if the user clicks the JFrame's close-window button. */ public class WindowDestroyer extends WindowAdapter { public void windowClosing(WindowEvent e) { System.exit(0); } }
HashMapStudentIDs |
none |
+ main(): static void |
This is all that should be required for this one.
Scramble extends JFrame |
+ WIDTH: static final int = 400 + HEIGHT: static final int = 100 - scrambleLabel: JLabel - statusLabel: JLabel - entryTextField: JTextField - checkButton: JButton - giveupButton: JButton - words[]: String = {one, two, three, four, five} - onWord: int - guessIs: int |
+ Scramble()- build your app here + actionPerformed(ActionEvent e): void + setupNewWord(): void + scrambleWord(String word): String + getFirst(String word, int split): String + getLast(String word, int split): String + main(): static void |
scrambleWord(String word):
Create a String variable result and initialize it as empty.
Get the length of word and store it in an integer variable
Create a random generator: Random generator = new Random()
Create a for loop that loops through based on the length of the word, using the variable created in step 2
Int split = generator.nextInt(word.length());
Find the index of the split in word and store it in a char variable
Call getFirst() and send it word, split
Call getLast() and send it word, split
Add the char variable value to result.
Add the result from getFirst() and getLast() to variable word
Outside the loop, return result
Output for scramble:
When the check is selected and the response is incorrect.
When the check is selected and the response is correct.
When Give up is selected
Part 1:
You have a list of student IDs followed by the course number (separated by a space) that the student is enrolled in. The listing is in no particular order. For example, if student 1 is in CS100 and CS200 while student 2 is in CS105 and MATH210 then the list might look like this:
1 CS100
2 MATH210
2 CS105
1 CS200
Write a program that reads data in this format from the console. If the ID is 1 then stop inputting data. Use the HashMap class to map from an Integer (the student ID) to an ArrayList of type String that holds each class that the student is enrolled in. The declaration should look like this:
HashMap
After all data is input, iterate through the map and output the student ID and all classes stored in the vector for that student. The result should be a list of classes organized by student ID.
Part 2:
Write an application called Scramble that has a GUI to play a game of word anagrams. Create two arrays of strings. The first array will hold words, and the second will hold scrambled versions of those words. Your Java code can
initialize these arrays directly with the
words. Display the scrambled version of the word in a label. The user will enter a guess for the word in a text field and press a Check button. You should see whether the guess is correct. If it is not correct, change the guess in the text field to
Sorry, that is incorrect. Please try again.
If the guess is correct, change it to
That is correct.
Here is a new word to try.
and display a new scramble. Also provide a Give Up button. If it is pressed, display the unscrambled word and provide a new scrambled word.
Here are some extensions that can be made to improve this application:
Read the words from a file
Do not use a second array of scrambled words, but instead use Javas random number generator to swap letters in the word just before you display the scrambled word.
Randomly decide which word to display.
Keep a score. Award 5 points if the user gets the word on the first guess, 3 points for getting it on the second guess, or 1 point for getting it on the third guess.
Divide the total points scored by the number of words presented.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started