10/27/22, 4:30 PM Assignment 5: Stacks
https:
webcourses.ucf.edu/courses/1413634/assignments/ XXXXXXXXXX/2
Assignment 5: Stacks
Due Friday by 11:59pm Points 100 Submitting a file upload File Types java
Available until Nov 11 at 11:59pm
Start Assignment
One of the things my wife likes to do is speak pig latin. I can never understand it and it never works fo
me. I just end up adding ay to the end of each word. I think you have to move letters to the end, but
eally unsure about it.
In that spirit I am going to ask you to using Java's Stack class to take a message and encode it. Let me
explain how this will work.
1. Messages will be between 5 and 1,000,000 units long.
2. Messages will have groups to show which parts need to be encoded first.
3. The character '1' will show a start of a group, and the character '2' will the end
4. Each grouping will 3 characters. Take the middle value will always be a vowel and the two end
values will be consonants.
5. Instead of consonants, another grouping can replace one or both of them. A grouping cannot
eplace a vowel.
6. You must evaluate the nested
eplaced groupings. Since 1 and 2 give you the end you can read it
left to right.
7. The output should only have the letters inside.
Examples:
Input Output
1cat2 cta
11top2e1cat22 tpoctae
111tom2op2it2 tmopoti
11top2i1tom22 tpotmoi
Limitations
Class Name: WordScramble
Public Static Methods:
String encode(String)
Must use the Stack Class
Strings will be no less than 5
10/27/22, 4:30 PM Assignment 5: Stacks
https:
webcourses.ucf.edu/courses/1413634/assignments/ XXXXXXXXXX/2
Strings will have the same amount of 1s and 2s.
A 1 must come before a matching 2.
Main Method
To help you run the sample cases, I attached my main method from when I wrote the solution. Please
include this in your program. The graders will add to this.
public static void main(String[] args) {
System.out.println(encode("1top2"));
System.out.println(encode("11top2e1cat22"));
System.out.println(encode("111tom2op2it2"));
System.out.println(encode("11top2i1tom22"));
}
10/31/22, 10:14 AM Assignment 6: Inheritance
https:
webcourses.ucf.edu/courses/1413634/assignments/ XXXXXXXXXX/3
Assignment 6: Inheritance
Due Friday by 11:59pm Points 100 Submitting a file upload File Types java
Available until Nov 11 at 11:59pm
Start Assignment
You will be making a chess valid move checker for two pieces. In this assignment, you will be creating
two classes to turn in, and another class to run the program. (You do not need to turn in the runne
class.). To help you make sure you can run our code, I have provided you with a few tests that will help
you get majority of the points.
Step 1: Download the ChessPiece.java
(https:
webcourses.ucf.edu/courses/1413634/files/ XXXXXXXXXX/download?download_frd=1) file. This
contains the abstract class, and data structures you will need.
Step 2: Complete the method, isOccupied(int, int). This is the only method you need to complete. It
will loop through masterList and determine if any pieces are in the row and column given from the
parameters. If it finds a ChessPiece at that location, it will return that piece. If not, it returns null.
Step 3: Create two classes called Knight and Rook. If you are not familiar on how these two chess
pieces move, look at these two examples. Knight
(http:
www.chesscorner.com/tutorial
asic/knight/knight.htm) and Rook
(http:
www.chesscorner.com/tutorial
asic
ook
ook.htm) . To make this easier, you can assume that we
are on an 8 by 8 board, with index starting at 0. In addition, all checks are within the 8x8 board.
Both classes will extend ChessPiece and will store the position they are cu
ently in as two integers.
Their constructors will take in the color of the piece, the row followed by the column of where the piece is
cu
ently at. As a reminder, you must include the abstract methods in ChessPiece once you extend it.
Step 4: Write the isValid method. I would suggest working on Knight first. I would also encourage you
to use the test below, but if you don't have Rook working (or created) change the Rooks to Knights to
test out the samples. It should have no effect on your program.
Knight has 8 valid moves, it can move 2 positions in one direction and 1 positions in another. It doesn't
have to wo
y about if it is blocked. It just has to check if those positions are free. If an enemy is in the
square, it can go to it. If the same color is there, it cannot.
Rook is a bit harder. You will need to check if all spaces between the cu
ent space and target space a
free. If the target space has something in it, it is only valid if it is a different color.
https:
webcourses.ucf.edu/courses/1413634/files/ XXXXXXXXXX?wrap=1
https:
webcourses.ucf.edu/courses/1413634/files/ XXXXXXXXXX/download?download_frd=1
http:
www.chesscorner.com/tutorial
asic/knight/knight.htm
http:
www.chesscorner.com/tutorial
asic
ook
ook.htm
10/31/22, 10:14 AM Assignment 6: Inheritance
https:
webcourses.ucf.edu/courses/1413634/assignments/ XXXXXXXXXX/3
DO NOT add additional methods other than the ones defined in ChessPiece. It will most likely create
e
ors. Do not create other chess pieces to turn in. If you would like to expand on this, and make a
chess program fully, please do so. Due to limited grading resources, please only submit these three
files.
Files to submit:
ChessPiece.java
Knight.java
Rook.java
Black Rook Test
XXXXXXXXXXnew Rook("Black", 6, 4);
new Knight("White", 4, 2);
new Knight("Black", 6, 2);
new Rook("Black", 2, 4);
System.out.println(ChessPiece.masterList.size());
System.out.println(ChessPiece.masterList.get(0).isValidMove(6, 6));
System.out.println(ChessPiece.masterList.get(0).isValidMove(6, 5));
System.out.println(ChessPiece.masterList.get(0).isValidMove(6, 3));
System.out.println(ChessPiece.masterList.get(0).isValidMove(6, 2));
System.out.println(ChessPiece.masterList.get(0).isValidMove(6, 1));
System.out.println(ChessPiece.masterList.get(0).isValidMove(7, 1));
System.out.println(ChessPiece.masterList.get(0).isValidMove(1, 4));
System.out.println(ChessPiece.masterList.get(0).isValidMove(2, 4));
System.out.println(ChessPiece.masterList.get(0).isValidMove(3, 4));
System.out.println(ChessPiece.masterList.get(0).isValidMove(4, 4));
System.out.println(ChessPiece.masterList.get(0).isValidMove(8, 4));
System.out.println(ChessPiece.masterList.get(0).isValidMove(7, 4));
Solution:
true
true
true
false
false
false
false
false
true
true
true
true
Knight Test
XXXXXXXXXXnew Rook("Black", 6, 4);
new Knight("White", 4, 2);
new Knight("Black", 6, 3);
new Rook("White", 2, 3);
System.out.println(ChessPiece.masterList.size());
System.out.println(ChessPiece.masterList.get(1).isValidMove(6, 3));
10/31/22, 10:14 AM Assignment 6: Inheritance
https:
webcourses.ucf.edu/courses/1413634/assignments/ XXXXXXXXXX/3
System.out.println(ChessPiece.masterList.get(1).isValidMove(6, 1));
System.out.println(ChessPiece.masterList.get(1).isValidMove(2, 3));
System.out.println(ChessPiece.masterList.get(1).isValidMove(2, 1));
System.out.println(ChessPiece.masterList.get(1).isValidMove(5, 4));
System.out.println(ChessPiece.masterList.get(1).isValidMove(3, 4));
System.out.println(ChessPiece.masterList.get(1).isValidMove(5, 0));
System.out.println(ChessPiece.masterList.get(1).isValidMove(3, 0));
System.out.println(ChessPiece.masterList.get(1).isValidMove(3, 3));
System.out.println(ChessPiece.masterList.get(1).isValidMove(6, 4));
Solution
true
true
false
true
true
true
true
true
false
false