Home‎ > ‎CIS36B‎ > ‎cis-36b-schedule‎ > ‎

AllLab

Lab 5: 2D Arrays and Images


due Thursday, October 10 at 11:59pm on Canvas


Pair Programming Extra Credit (+5pts E.C.)
  • Both partners fill in, sign, date, and submit the pair programming contract
  • Upload the document(s) along with your Lab code to Canvas.
  • Only ONE partner submits the Lab code on Canvas.
  • BOTH partners submit the contract.
  • Please make sure both your names are on all the files.
  • If you need help finding a partner, please contact me as soon as possible.



Image Processing
  • Image files can be stored as 2D arrays, where each row and column of the array stores the ARGB (alpha-red-green-blue) value of a single pixel in the image.
  • Recall that pixels are dots of color that have an alpha (transparency) represented using one byte, as well as a combination of red, green and blue (represented using one byte each). Therefore, you can store the value of one pixel as an int (4 bytes long), where:
    • the first byte is the alpha value: 0000 0000 is totally transparent and 1111 1111 is totally opaque
    • the second byte is the red value: 0000 0000 no red in the color of the pixel and 1111 1111 maximal red in the pixel
    • the third byte is the green value: 0000 0000 no green in the color of the pixel and 1111 1111 maximal green in the pixel
    • the fourth byte is the blue value: 0000 0000 no blue in the color of the pixel and 1111 1111 maximal blue in the pixel
  • The combination of those 4 bytes makes one pixel - a single dot of color with a transparency inside an image
4 bytes to make one pixel
  • If you consider an image like a table of pixels, where each pixel has a row and column position within the image, then you can store the image in a 2D array.
  • Once you have the image stored, you can make updates to each pixel to convert the image into a black-and-white or sepia-toned picture.
  • In this program, you will work with two new APIs (libraries of code) to read in an image file and access data about that image: java.awt.Image.BufferedImage to access and manipulate the image and javax.imageio.ImageIO to read in the image and write it out to another file.
  • Note that you can read about these two libraries by clicking on the above links and familiarize yourself with their methods.

Starter Code:
  • Make a new project for Lab 5 and add a class named ImageManip to this project.
  • Additionally, you will need to drag and drop an image file of your choice into the main project folder for Lab 5.
    • You will work with this image file of your choice for the lab.

import java.io.*;
import java.util.Scanner;
import java.awt.image.BufferedImage;
import javax.imageio.ImageIO;

public class ImageManip {
    public static void main(String[] args) throws IOException {
        int[][] img_array;
        File file;
        BufferedImage img;
        String fileName;

        Scanner input = new Scanner(System.in);
        System.out.println("Welcome!\n");
        System.out.print("Enter the name of an image file (jpg extension): ");
    }
}

How to Read in an Image File and Extract Its Values:
  • We will need to use the ImageIO API to read from the file.
  • All you need to do is to call ImageIO.read(file variable name goes here);
  • This method returns a BufferedImage variable
  • Note that we have not worked with buffered I/O before, as it was not necessary for our I/O using text files.
    • To read about the difference between buffered and unbuffered I/O, see the article here.
  • Next, you will use some methods from the BufferedImage API, specifically:
    • getHeight() - returns the height of the image in pixels
    • getWidth() - returns the width of the image in pixels
    • getRGB(col, row) - returns the int ARGB of the pixel at position col, row or think of it as x, y
    • setRGB(col, row, pixel) - updates the ARGB of a pixel at position col, row - or think of it as x, y - to be a new integer value 
  • Hint: Use a nested for loop to read all ARGB pixel values into your 2D array


Converting to Grayscale (Black-and-White):
  • To convert to grayscale, you will need to average the RGB value of each pixel, using this formula:
int average = (R + B + G) / 3
  • But first, you need to extract the RGP value from the pixel itself
  • If you have a an integer pixel variable containing the ARGB of one pixel, then you will need to extract each individual byte and save it as an integer - one integer for the alpha value, one for the red, one for the green, and one for the blue - so that you can compute their averages.
  • Use the following formula:
    int a = (pixel >> 24) & 255;
  int r = (pixel >> 16) &
255;
  int g = (pixel >> 8) &
255;
  int b = pixel &
255;
  • The >> above performs what is called a bit-wise shift to the right, where all bits are shifted a specified number of bits to the right, and their original positions are replaced with 0s. For example:
1111 1101 0001 1001 >> 4

yields 0000 1111 1101 0001
  • Above, the bits were all shifted 4 bits to the right. Notice that 1001 was shifted off the end (and thus discarded).
    • All other bits were shifted over by 4. The original locations of 1111 was replaced with all 0s.
  • Therefore, in our integer pixel, if we shift the bits over by 24, we will get the alpha value to be stored in the first byte of the integer (located in last byte of the integer)
  • If we shift the bits by 16, we will get the red value in the first byte.
  • If we shift the bits by 8, we will get the green value in the first byte.
  • The blue value is already stored in the first byte of the integer.
  • See more about bitwise shifts here.
  • Lastly, we will apply what is called "bitwise AND" (%), where we AND all bits by 255.
    • This has the effect or replacing all bits with 0s, except in the first byte of the integer where we have the alpha, red, green, or blue value is stored.
  • Once we have extracted the alpha, red, green, and blue values into their own unique integer variables (with 0s for the remaining bits), we can then average them to calculate the grayscale value of that pixel.
  • Finally, we will create a new pixel using a left shift << to replace the RGB with the average we computed, and then do a bitwise OR (|) to recombine the new ARGB back into one single integer representing that updated pixel:
pixel = (a << 24) | (avg << 16) | (avg << 8) | avg;
  • Learn more about bitwise & and | here
  • Finally, we update the pixel to contain the grayscale value of the pixel by calling img.setRGB(x, y, pixel)
  • You will need to carry out this process for each pixel in the image. Thus, a nested for loop will be required.
  • Note that you can see a complete tutorial here
    • How would you update this tutorial to store the image in a 2D array?


Converting to Sepia:
  • Use the below algorithm to convert each pixel in the image to sepia values:
newRed = 0.393*R + 0.769*G + 0.189*B
newGreen = 0.349*R + 0.686*G + 0.168*B
newBlue = 0.272*R + 0.534*G + 0.131*B

If any of these output values is greater than 255, 
simply set it to 255.

Update the RGB to contain the newRed, newGreen, and newBlue values (use bitwise shifts and & and | as above)

Output Files:
  • Note that the program should prompt the user to enter the name of any file of their choice as an input file.
    • Drag and drop this file into your Eclipse project
  • However the output files should be named bw.jpg (grayscale) and sepia.jpg (sepia)
  • Note that you should right-click on the name of the project and select "refresh" from the drop down menu if your file names are not visible after adding the input file to your project folder, or after running the program and generating the output files.

Sample Output:
  • Your program should work identically to the output below (note that the user can enter any input file of their choice here - no error detection needed)

Welcome!

Enter the name of an image file (jpg extension): helicopter2.jpg

Thank you!
Check bw.jpg for a black and white image of helicopter2.jpg,
and sepia.jpg for a sepia image of helicopter2.jpg



What to Submit:

When you are satisfied your program is working properly, submit the following to Canvas:
  • ImageManip.java
  • If working with a partner, Pair Programming Contract (both partners)
  • Note that you must store the image file as a 2D array in your program in order to receive credit for this assignment.

How You Will Be Graded:

  • 100 points: The assignment works as shown in the sample output. All required features are implemented and implemented correctly. The program produces sepia and grayscale images of the original image file. A 2D array is used to store the image file.
  • 80-100 points: The assignment works mostly as shown in the sample output. Most required features are implemented and implemented correctly. Wording or spacing choices may differ from those shown. Images may not be fully in grayscale or sepia.
  • 40-80 points: Some of the assignment works as shown in the sample output. Some required features are implemented and implemented correctly.
  • 10-40 points: Serious problems in implementation and little correspondence between sample output and what is shown. Few of the features implemented or implemented correctly.
  • 0 points: Code does not compile or outputs an error at runtime.


Lab 12: Abstract Classes and Polymorphism

due Monday, February 24 at 9:20am on Canvas

Tic-Tac-Toe
  • For this Lab you are going to get a lot of practice working with arrays and methods!
  • You will write a tic-tac-toe game which stores the game board as an array of length 9.
  • The game will alternate between a human player at the keyboard and a computer A.I., who take turns placing on the board.
  • The human user should be prompted for a choice of letter (X or O), and the A.I. will take the letter that was not selected.
  • To select a placement, the human user will type the input as a single number representing the row and column values of the desired placement.
    • For example, the input 21 represents a desired placement of row 2 and column 1
  • The human player should place first.
    • Display the updated game board with the new placement after the user has entered input.
  • Subsequently, the computer A.I. will make a placement.
    • Again, display the updated game board with the new placement after the A.I. has selected a position on the board.
  • The game should continue until one of the players has won, or there is a tie (game board filled, but no 3-in-a-row placements)
  • Note that the A.I. should follow this algorithm when deciding where to make a placement:
    • If the center position (row 2, column 2) is empty, it should place in the center
    • Otherwise, it should determine whether the human user currently has two-in-a-row and is about to win the game - but only checking possible two-in-a-row placements that include the center position (in other words, it will not check all possible two-in-a-row on the game board). If the user is about to win in this way, the A.I. should make a placement to block the user.
    • Otherwise, the A.I. will place in a random, unoccupied position on the board.
  • In the below started code, I have provided you with the signatures for all the methods that you are required to write for this assignment.
    • Optionally, as long as you write the below methods, you are welcome to write any additional methods that you find useful.
  • The Javadoc comments for each method specify the purpose of the method and may give hints about how to write it.
  • I have already written the randomPosition method for you, so that method should remain unchanged.
  • To get started, copy and paste the starter code into a file called TicTacToe.java.
    • Notice the capitalization
    • By convention, class names are always capitalized in Java
  • Each time you write a method, try calling the method in main to make sure it is working
  • Don't write all your code at once before compiling!
    • Greater chance of getting errors and bugs in your code
    • Errors and bugs are harder to track down, the longer and more complex your program becomes
  • In fact, try to break this assignment into as small of pieces as possible, and test each small to piece to make sure it is working as you go along.
    • In other words, compile and run your code at frequent intervals

Starter Code:


/**
 * Tic-Tac-Toe Game
 * @author
 * @author
 * CIS 36B
 */

import java.util.Random;
import java.util.Scanner;

public class TicTacToe {

    /**
     * Initializes the board by assigning all array elements
     * the value of '_' (underscore)
     * @param board the array representing the tic-tac-toe board
     */
    public static void setUpBoard(char board[]) {
       
    }
   
    /**
     * Capitalizes the x or o entered by a player
     * Ignores already capitalized X and O
     * @param character the x or o
     * @return the capitalized X or O
     */
    public static char capitalizeXO(String character) {
        return '\0';
    }
   
    /**
     * Prints the board to the console in the form of a grid,
     * including column and row numbers and the message Tic-Tac-Toe:
     * @param board the array representing the tic-tac-toe board
     */
    public static void displayBoard(char board[]) {
        System.out.print("\nTic-Tac-Toe:\n ");
    }
   
    /**
     * Converts the player choice of row and column
     * in the form of RC into the correct index of
     * the board array.
     * Hint: Use integer division by 10 to extract the row
     * Hint: Use modulus by 10 to extract the column
     * @param rowCol the row and column, e.g. 12 or 33
     * @return the correct index of the array that
     * corresponds to the row and column
     */
    public static int convertToIndex(int rowCol) {
        return -1;
    }
   
    /**
     * Determines whether a particular position
     * on the board has already been taken.
     * @param board the array representing the game board
     * @param position the position to check
     * @return whether that position has already been taken
     */
    public static boolean spotTaken(char board[], int position) {
        return false;
    }
   
    /**
     * Selects a location for the computer AI's next
     * move, using the following algorithm:
     * 1. Selects the center position (4) if it is open
     * 2. Otherwise, blocks the player provided the player played
     * in the center position and now has two in a row
     * including the center
     * 3. Otherwise, generates a random position from
     * which to play
     * @param board the game board
     * @param player the character (X or O) of the player
     * @return the position (0-8) on the board
     * at which the computer should play next
     */
    public static int findAIPlacement(char board[], char player) {
        return -1;
       
    }
   
   
    /**
     * A helper method to findAIPlacement
     * Gives a random position on the board
     * Used for generating moves for the computer
     * @param size the length of the board array
     * @return a random index in the board array
     */
    public static int randomPosition(int size) {
        Random r = new Random(System.currentTimeMillis());
        return r.nextInt(size);
       
    }
   
    /**
     * Determines whether three characters are all Xs or all Os
     * Used as a helper method to the gameOver method
     * @param a the first character to compare, either X, O, or -
     * @param b the second character to compare, either X, O, or -
     * @param c the third character to compare, either X, O or -
     * @return whether the characters are all Xs or all Os
     */
    public static boolean threeInRow(char a, char b, char c) {
        return false;
    }
   
    /**
     * Determines whether the game is over
     * due to one player winning, using
     * a series of if statements.
     * Calls the threeInRow method for each
     * possible row on the board.
     * @param board the tic-tac-toe game board
     * @return whether the game is over
     */
    public static boolean gameOverWinner(char board[]) {
        return false;
    }
   
    /**
     * Determines whether the game is over
     * due to a tie.
     * Compares numMoves to the length.
     * @param board the tic-tac-toe game board
     * @param numMoves the number of moves that have been made so far
     * @return whether the game is over
     */
    public static boolean gameOverTie(char board[], int numMoves) {
        return false;
    }
   

    public static void main(String[] args) {
        System.out.println("Welcome to Tic-Tac-Toe!");
        char board[] = new char[9];
        int numMoves = 0; //increments when player or game A.I. makes a move
       
    }
      
}


Sample Output (A.I. blocks 2-in-a-row from center):

Welcome to Tic-Tac-Toe!

Would you like to play as X or O: X

Tic-Tac-Toe:
  1 2 3
1 _ _ _
2 _ _ _
3 _ _ _

Please enter your move: 22

Tic-Tac-Toe:
  1 2 3
1 _ _ _
2 _ X _
3 _ _ _

Counter move!

Tic-Tac-Toe:
  1 2 3
1 O _ _
2 _ X _
3 _ _ _

Please enter your move: 21

Tic-Tac-Toe:
  1 2 3
1 O _ _
2 X X _
3 _ _ _

Counter move!

Tic-Tac-Toe:
  1 2 3
1 O _ _
2 X X O
3 _ _ _

Please enter your move: 12

Tic-Tac-Toe:
  1 2 3
1 O X _
2 X X O
3 _ _ _

Counter move!

Tic-Tac-Toe:
  1 2 3
1 O X _
2 X X O
3 _ O _

Please enter your move: 13

Tic-Tac-Toe:
  1 2 3
1 O X X
2 X X O
3 _ O _

Counter move!

Tic-Tac-Toe:
  1 2 3
1 O X X
2 X X O
3 O O _

Please enter your move: 33

Tic-Tac-Toe:
  1 2 3
1 O X X
2 X X O
3 O O X

It's a tie!

***Game Over***


Alternately (A.I. take the center):

Welcome to Tic-Tac-Toe!

Would you like to play as X or O: o

Tic-Tac-Toe:
  1 2 3
1 _ _ _
2 _ _ _
3 _ _ _

Please enter your move: 11

Tic-Tac-Toe:
  1 2 3
1 O _ _
2 _ _ _
3 _ _ _

Counter move!

Tic-Tac-Toe:
  1 2 3
1 O _ _
2 _ X _
3 _ _ _

Please enter your move: 12

Tic-Tac-Toe:
  1 2 3
1 O O _
2 _ X _
3 _ _ _

Counter move!

Tic-Tac-Toe:
  1 2 3
1 O O _
2 X X _
3 _ _ _

Please enter your move: 13

Tic-Tac-Toe:
  1 2 3
1 O O O
2 X X _
3 _ _ _

O wins!

***Game Over***


Alternately (spot already taken):


Welcome to Tic-Tac-Toe!

Would you like to play as X or O: x

Tic-Tac-Toe:
  1 2 3
1 _ _ _
2 _ _ _
3 _ _ _

Please enter your move: 22

Tic-Tac-Toe:
  1 2 3
1 _ _ _
2 _ X _
3 _ _ _

Counter move!

Tic-Tac-Toe:
  1 2 3
1 _ O _
2 _ X _
3 _ _ _

Please enter your move: 22

That spot is already taken!

Please enter your move: 12

That spot is already taken!

Please enter your move: 33

Tic-Tac-Toe:
  1 2 3
1 _ O _
2 _ X _
3 _ _ X

Counter move!

Tic-Tac-Toe:
  1 2 3
1 O O _
2 _ X _
3 _ _ X

Please enter your move: 31

Tic-Tac-Toe:
  1 2 3
1 O O _
2 _ X _
3 X _ X

Counter move!

Tic-Tac-Toe:
  1 2 3
1 O O O
2 _ X _
3 X _ X

O wins!

***Game Over***


What to Submit:

When you are satisfied your program is working properly, submit the following to Canvas:
  • TicTacToe.java
  • If working with a partner, Pair Programming Contract (both partners)

Lab 1.2: Halley's Comet (80 pts)

  • According to Dictionary.com a comet is "a celestial body moving about the sun, usually in a highly eccentric orbit, consisting of a central mass surrounded by an envelope of dust and gas that may form a tail that streams away from the sun."
  • Perhaps the most famous comet is Halley's Comet, which is bright enough to be visible to the human eye when it comes close enough to earth, and has the habit of appearing in the sky at meaningful moments throughout history.
  • Interestingly, its orbit is what is known as "retrograde", meaning that it travels around the sun in the opposite direction of the planets.
  • Halley's is considered a short-period comet because its orbit is under 200 years, as opposed to some comets with orbits more than thousands of years long.
  • In fact, it appears in the sky every 74-79 years. Did/will Halley's appear during your lifetime?
  • Assume that you are given a text file named years.txt containing the years in which Halley's comet has been visible from earth, starting in 240BC, or will be visible in the "near" future. This file has the following contents:
240BC, 164BC, 87BC, 12BC, 66, 141, 218, 295, 374, 451, 530, 607, 684, 760, 837, 912, 989, 1066, 1145, 1222, 1301, 1378, 1456, 1531, 1607, 1682, 1758, 1835, 1910, 1986, 2061, 2134,

  • Without altering the file from the above format (i.e. you are not allowed to erase the commas or alter the spacing or order), write a program that will prompt a user to enter a year between 240BC and 2200, and then report whether Halley's comet was visible during that year.
  • The user should be able to continue entering years, until pressing 'x' to end the program.
  • To receive credit, your program must:
  • Read the numbers from the file
  • Store them in an array of ints
  • Implement a binary search method to search for the year entered by the user, by writing a binary search method with the following signature:
public static int binarySearch(int[] dates, int year) {
  • Additional restrictions to provide challenge... the only String methods allowed on this assignment are:
    • substring
    • length
    • charAt
    • toUpperCase
    • toLowerCase
    • equals
    • equalsIgnoreCase
    • compareTo
    • compareToIgnoreCase
  • Your program should be named Halleys.java and must work identically to the sample output shown below:
Welcome!

Enter a year between 240BC and 2200 or 'x' to exit: 67
Halley's Comet did not appear in the year 67.

Enter a year between 240BC and 2200 or 'x' to exit: 66
Halley's Comet did appear in the year 66.

Enter a year between 240BC and 2200 or 'x' to exit: 2020
Halley's Comet will not appear in the year 2020.

Enter a year between 240BC and 2200 or 'x' to exit: 2061
Halley's Comet will appear in the year 2061.

Enter a year between 240BC and 2200 or 'x' to exit: 87BC
Halley's Comet did appear in the year 87BC.

Enter a year between 240BC and 2200 or 'x' to exit: 88BC
Halley's Comet did not appear in the year 88BC.

Enter a year between 240BC and 2200 or 'x' to exit: 300BC
Invalid date!

Enter a year between 240BC and 2200 or 'x' to exit: 2300
Invalid date!

Enter a year between 240BC and 2200 or 'x' to exit: x

Goodbye!

  • Additionally, your program should meet the below requirements:
    • Your program should adjust for future dates starting in 2020 to state "will appear" or "will not appear." See above examples.
    • Also, your program must be able to handle dates that contain BC. Hint: Check whether a date has an ending of "BC", and then handle this case differently from AD numbers.
    • Additionally, you should assume that you do not know the number of dates in the input file, and write your program accordingly.
    • Finally, your program should do error checking for cases in which the user types a date that falls outside the range of 240BC to 2200. No other error checking is required.
  • Style requirements:
    • You should use proper indentation. If uncertain, remember to go to Source->Format on Eclipse to autoformat your code
    • Your method(s) should each have a full Javadoc comment placed above the method. See lesson 1 notes on Javadocs, if uncertain.
  • Hint: Research the parseInt() method of the Integer class and make use of it to convert your Strings to ints.

What to Submit:

  • When you are satisfied your program is working properly, submit the following to Canvas:
    • Halleys.java (only one partner)
    • Pair Programming Contract (both partners)
  • Please submit these files separately - no zip or compressed files (5 point deduction)
  • Please use the default package or remove your package statement before submitting (5 point deduction)
  • Please make sure both names are on your assignment (5 point deduction for missing name(s))
  • Please make sure your code is properly indented (5 point deduction for improperly indented code)
    • Hint: Go to source->format on Eclipse to auto-format your code

How You Will Be Graded:

  • 80 points: The assignment works as shown in the sample output. All required features are implemented and implemented correctly.
  • 60-80 points: The assignment works mostly as shown in the sample output. Most required features are implemented and implemented correctly. Wording or spacing choices may differ from those shown.
  • 40-60 points: Some of the assignment works as shown in the sample output. Some required features are implemented and implemented correctly.
  • 10-40 points: Serious problems in implementation and little correspondence between sample output and what is shown. Few of the features implemented or implemented correctly. Or, student did not pair program.
  • 0 points: Code does not compile or outputs an error at runtime.
  • Incorrect formatting (indentation) and incorrect or missing Javadoc comments will each lead to a 5 point deduction.
  •  


Pair Programming Required (or No Credit)
  • Both partners fill in, sign, date, and submit the pair programming contract
  • Upload the document along with your Lab code to Canvas.
  • Only ONE partner submits the Lab code on Canvas.
  • BOTH partners submit the contract.
  • Please make sure both your names are on all the files.
  • If you need help finding a partner, please contact me as soon as possible.


Pac-Cookie!

  • For this lab, you will write a simplified version of Pac-man called Pac-Cookie. 
  • During this assignment, you will:
    1. Write an abstract class to hold the data for a game character
    2. Write a subclass to store information about the player character
    3. Write a subclass to store information about a ghost character
    4. Extend the ghost class to create an additional sub-class for another Ghost character
    5. Write a game class
    6. Optionally, construct a class that uses static methods to test a class

Game Specifications:

  • Pac-Cookie is a simplified, turn-based version of the arcade game Pac-man.
  • In this game, the user plays as Pac-Cookie (represented with a P on the game board)
  • Pac-Cookie's goal is to consume 20 cookies (represented with *) without running into a Ghost (represented with a G on the game board).
  • Note that Ghosts should also consume cookies as they advance through the board
  • The board is represented as a 10X10 2D array initially filled with * (cookies) and H walls
  • After the initial introduction to the game, the player should be asked to enter one of four possible options to move the character along the game board:
      • u (up)
      • d (down)
      • l (left)
      • r (right)
  • After the player has entered a selection, the Ghosts should move and then the updated game board should be displayed.
    • Do not display the game board before the Ghosts have moved.
  • If the Player lands on a row and column in the board that contains a *, the Player should be given one point and the * should be replaced with a blank space for the remainder of the game.
    • Also, any cookies eaten by the Ghost (G) or Spooky (S) should replace *s with blank spaces on the board.
  • You must perform some error checking:
  • First, the Player character cannot go out of bounds of the 2D array.
    • Otherwise, the game prints a message "Ouch!" For example:
Welcome to Pac-Cookie!

Your goal is to eat all remaining cookies (at least 20) - before you escape!
But, beware the not-so-friendly ghosts...
They will eat the cookies... and YOU!

Ready to play? Let's go!

Score: 0
Remaining Cookies: 53

H H H H H H H H H H

H P * * * * * * * H

H * * * * * * * * H

H * * H * * H * * H

H * * H * * H * * H

H * * H * * H * * H

H * * H * * H * * H

H * * H * * H * * H

H * * * * * * * G *

H H H H H H H H H H

How do you want to move? (u/d/l/r): u
Ouch!
Score: 0
Remaining Cookies: 53

H H H H H H H H H H

H P * * * * * * * H

H * * * * * * * * H

H * * H * * H * * H

H * * H * * H * * H

H * * H * * H * * H

H * * H * * H * * H

H * * H * * H * * H

H * * * * * * * G *

H H H H H H H H H H

How do you want to move? (u/d/l/r):
  • Similarly, the player cannot move through inner walls. For example:
How do you want to move? (u/d/l/r): r
Score: 3
Remaining Cookies: 47

H H H H H H H H H H

H   * * * * * * * H

H   * * * * * * * H

H   P H * * H * * H

H * * H * * H * * H

H * * H * * H * G H

H * * H * * H *   H

H * * H * * H *   H

H * * * * * * *   *

H H H H H H H H H H

How do you want to move? (u/d/l/r): r
Ouch!
Score: 3
Remaining Cookies: 47

H H H H H H H H H H

H   * * * * * * * H

H   * * * * * * * H

H   P H * * H * * H

H * * H * * H * * H

H * * H * * H * G H

H * * H * * H *   H

H * * H * * H *   H

H * * * * * * *   *

H H H H H H H H H H

How do you want to move? (u/d/l/r): r
Ouch!
Score: 3
Remaining Cookies: 47

H H H H H H H H H H

H   * * * * * * * H

H   * * * * * * * H

H   P H * * H * * H

H * * H * * H * * H

H * * H * * H * G H

H * * H * * H *   H

H * * H * * H *   H

H * * * * * * *   *

H H H H H H H H H H

How do you want to move? (u/d/l/r):

  • However, the Ghosts can move through inner (but not outer) walls. For example:
Score: 31
Remaining Cookies: 9

H H H H H H H H H H

H                 H

H                 H

H     H * * H     H

H     H * P H     H

H     H *   H     H

H     G *   H     H

H     H *   H     H

H     * *         *

H H H H H H H H H H

How do you want to move? (u/d/l/r): u
  • Second, if the user enters incorrect input, the program must print "Invalid move!" and the game should not advance until the user types in correct input:
How do you want to move? (u/d/l/r): dd
Invalid move!
Score: 3
Remaining Cookies: 47

H H H H H H H H H H

H   * * * * * * * H

H   * * * * * * * H

H   P H * * H * * H

H * * H * * H * * H

H * * H * * H * G H

H * * H * * H *   H

H * * H * * H *   H

H * * * * * * *   *

H H H H H H H H H H

How do you want to move? (u/d/l/r):

  • The game should continue until one of the following events occurs:
    • The Player loses by getting eaten by one of the Ghosts (both Player and Ghost end up at the same row and col within the 2D array)
    • The Player loses because there are not enough cookies left on the game board for the Player to achieve 20 points.
    • The Player wins by scoring more than 20 points AND escaping out the lower right-side exit WITH no more cookies remaining on the board.
  • Required: You must implement the classes whose starter code is provided below.
    • In your implementation, you will be expected to read the comments for each method and implement the method based on the given description.
  • Pay particular attention to the algorithm followed by the Ghost:
    • The Ghost will start the game in the lower right corner.
    • It should follow a pattern of moving only in the upwards position until it reaches the top row of the maze.
    • From the top row, it should proceed moving only left until it reaches the upper left corner,
    • Once it arrives in the upper left corner, it should jump to the bottom right corner again
    • Its movements are complicated by the fact that every 10 turns, it should spawn to random position on the board.
    • From this random position, it should proceed to move all the way to the top, followed by all the way to the left.
    • This Ghost should eat cookies, as shown
    • For more information, please see the sample output located at the end of the lab directions.
  • Additionally, you must extend the Ghost class to write a Ghost sub-class (Spooky.java), representing a different Ghost character
    • Both Ghost characters should behave differently in the game.
    • Please use an S to represent Spooky on the board.
    • Both Ghost characters must be displayed on the game board at all times
    • You must implement the Ghost.java class provided, and then it is up to your own powers of invention to create the Spooky subclass and determine how the Ghosts behave in the game.
    • The name of the Ghost subclass must be Spooky.java and must extend Ghost.java
  • Below is the starter code for the required classes (except for Spooky.java).

Character.java Code:

  • The below abstract class must remain unchanged from what is provided, or you will receive no credit for this lab.
  • Note that you will not submit this file to Canvas
  • You will inherit from this class when you write Player.java and Ghost.java

/**
 * Character.java
 * @author
 * @author
 * CIS 36B, Lab 12
 */
public abstract class Character {
    private int xPos;
    private int yPos;
   
    /**
     * Sets the x (column) location of the character
     * @param x the x position of the character in the x-y plane
     */
    public void setXPos(int x) {
        xPos = x;
    }
   
    /**
     * Sets the y (row) location of the character
     * @param y the y position of the character in the x-y plane
     */
    public void setYPos(int y) {
        yPos = y;
    }
   
   
    /**
     * Returns the x position of the character
     * @return the x position of the character in the x-y plane
     */
    public int getXPos() {
        return xPos;
    }
   
    /**
     * Returns the y position of the character
     * @return the y position of the character in the x-y plane
     */
    public int getYPos() {
        return yPos;
    }
   
   
    /**
     * Moves the character one space to the left
     * by subtracting one from its x position
     * Or, prevents the player from going outside
     * the bounds of the board by leaving the
     * character in the same position.
     */
    public void moveLeft() {
        xPos-=1;
    }
   
    /**
     * Moves the character one space to the right
     * by adding one to its x position
     * Or, prevents the player from going outside
     * the bounds of the board by leaving the
     * character in the same position.
     */
    public void moveRight() {
        xPos+=1;
    }
   
    /**
     * Moves the character one space down
     * by adding one to its y position
     * Or, prevents the player from going outside
     * the bounds of the board by leaving the
     * character in the same position.
     */
    public void moveDown() {
        yPos+=1;
    }
   
    /**
     * Moves the character one space up
     * by subtracting one from its y position
     * Or, prevents the player from going outside
     * the bounds of the board by leaving the
     * character in the same position.
     */
    public void moveUp() {
        yPos-=1;
    }
}

Player.java
  • At a minimum, you must implement the below methods, but may also add any additional methods you would like.
  • Note that you are only allowed to add methods to this class, but no variables.
/**
 * Player.java
 * @author FILL IN HERE
 * @author
FILL IN HERE
 * CIS 36B, Lab 12
 */

public final class Player extends Character{
    private int score;
   
    /**
     * Player default constructor
     * Gives the player a starting
     * position of [1,1] on the board
     * and sets score to 0
     */
    public Player() {
    }
   
    /**
     * Returns the player's current score
     * @return the score
     */
    public int getScore() {
        return -1;
    }
   
    /**
     * Updates the player's score by 1
     */
    public void updateScore() {
        return;
    }
}


Ghost.java:
  • At a minimum, you must implement the below methods, but may also add any additional methods you would like.
  • Note that you can only add methods to this class, not variables.
  • You must then extend this class to create Spectre.java and Apparition.java classes.
/**
 * Ghost.java
 * @author FILL IN HERE
 * @author FILL IN HERE
 * CIS 36B, Lab 12
 */

import java.util.Random;

public class Ghost extends Character{
    private int numMoves;
    int max;
   
    /**
     * One argument constructor
     * Calls setXPos() and setYPos()
     * to give the ghost its initial
     * placement at the bottom right
     * corner of the board [max-2, max-2]
     * Also initializes max (the max
     * x and y dimension on the board)
     * and numMove to 0
     * @param max the
     */
    public Ghost(int max) {
    }
   
    /**
     * Moves the Ghost according to an
     * algorithim:
     * If the number of moves it has made
     * is divisible by 10, it generates a
     * random move. Otherwise, it moves up
     * until it cannot go farther. Then,
     * it moves left until it can go no
     * farther.
     * Once it reaches the [1,1]
     * corner it jumps back to its starting
     * position. Updates numMoves.
     */
    public void move() {
       
    }
   
    /**
     * Places the ghost at a random
     * board position
     */
    public void generateRandomMove() {
    }
}



Game.java:
  • At a minimum, you must implement the below methods, but may also add any additional methods you would like to represent the game play as shown in the sample output below.
  • Also you should declare two new private variables of type Spectre (represented as an S on the board) and Apparition (represented as an A on the board)
/**
 * Game.java
 * @author FILL IN HERE
 * @author FILL IN HERE
 * CIS 36B, Lab 12
 */

import java.util.Scanner;

public class Game {
    private int upperX;
    private int upperY;
    private int totalCookies;
   
    private Ghost g;
    private Player p;
    private String board[][];
   
    /**
    * Constructor for the Game class
    * Initializes private variables
    * Calls initialize board to intialize
    * the board. Places characters at their
    * starting positions.
    * Note that there are 53 cookies on
    * the board at the start of the game
    */
    public Game() {
       
    }
   
   /**
     * Initializes the board to *s for cookies
     * and Hs for walls
     * Called by the constructor
     */
    private void initializeBoard() {
        for (int i = 0; i < board.length; i++) {
            for (int j = 0; j < board[i].length; j++) {
                if( i == 0 || j == 0) {
                    board[i][j] = "H";
                } else if (j == board.length - 1 || i == board.length - 1) {
                    board[i][j] = "H";
                } else if (j == board.length / 3 && i > 2 && i < 8 ) {
                    board[i][j] = "H";
                } else if (j == (2 * board.length) / 3 && i > 2 && i < 8 ) {
                    board[i][j] = "H";
                } else {
                    board[i][j] = "*";
                }
            }
        }
    }
   
    /**
     * Places the player and ghost at a
     * new spot on the board
     */
    public void updateBoard() {
        return;
    }
   
    /**
     * Replaces the current location of the
     * player and ghost with two blank spaces
     * unless the ghost is walking through a wall
     * in which case, only the player's space
     * is cleared
     * Hint: See initializeBoard method for
     * placement of interior walls
     */
    public void clearSpace() {
        return;
    }
   
    /**
     * Prints out board as shown in sample output
     * including displaying the current score and
     * the number of remaining cookies
     */
    public void printBoard() {
        return;
    }
   
    /**
     * Determines whether the player has lost by either
     * being eaten by the ghost or because there
     * are not enough cookies left on the board to win
     * @return whether the player has lost
     */
    public boolean gameOverLose() {
        return false;
    }
   
    /**
     * Determines whether the player has won
     * the game by scoring at least 20 points,
     * eating all possible cookies, and
     * escaping from the hole in the leftside
     * wall
     * @return whether the player has won
     */
    public boolean gameOverWin() {
        return false;
    }
   
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        String choice = "";
       
        System.out.println("Welcome to Pac-Cookie!\n");
        System.out.println("Your goal is to eat all remaining cookies (at least 20) - before you escape!");
        System.out.println("But, beware the not-so-friendly ghosts..."
                + "\nThey will eat the cookies... and YOU!");
        System.out.println("\nReady to play? Let's go!\n");
       
        Game game = new Game();
       
        //Add your code here!
      
        input.close();
       
    }
}



Base Game (Before Spooky Added) Sample Output:


Example 1: Winning the Game:

Welcome to Pac-Cookie!

Your goal is to eat all remaining cookies (at least 20) - before you escape!
But, beware the not-so-friendly ghosts...
They will eat the cookies... and YOU!

Ready to play? Let's go!

Score: 0
Remaining Cookies: 53

H H H H H H H H H H

H P * * * * * * * H

H * * * * * * * * H

H * * H * * H * * H

H * * H * * H * * H

H * * H * * H * * H

H * * H * * H * * H

H * * H * * H * * H

H * * * * * * * G *

H H H H H H H H H H

How do you want to move? (u/d/l/r): u
Ouch!
Score: 0
Remaining Cookies: 53

H H H H H H H H H H

H P * * * * * * * H

H * * * * * * * * H

H * * H * * H * * H

H * * H * * H * * H

H * * H * * H * * H

H * * H * * H * * H

H * * H * * H * * H

H * * * * * * * G *

H H H H H H H H H H

How do you want to move? (u/d/l/r): d
Score: 1
Remaining Cookies: 51

H H H H H H H H H H

H   * * * * * * * H

H P * * * * * * * H

H * * H * * H * * H

H * * H * * H * * H

H * * H * * H * * H

H * * H * * H * * H

H * * H * * H * G H

H * * * * * * *   *

H H H H H H H H H H

How do you want to move? (u/d/l/r): d
Score: 2
Remaining Cookies: 49

H H H H H H H H H H

H   * * * * * * * H

H   * * * * * * * H

H P * H * * H * * H

H * * H * * H * * H

H * * H * * H * * H

H * * H * * H * G H

H * * H * * H *   H

H * * * * * * *   *

H H H H H H H H H H

How do you want to move? (u/d/l/r): d
Score: 3
Remaining Cookies: 47

H H H H H H H H H H

H   * * * * * * * H

H   * * * * * * * H

H   * H * * H * * H

H P * H * * H * * H

H * * H * * H * G H

H * * H * * H *   H

H * * H * * H *   H

H * * * * * * *   *

H H H H H H H H H H

How do you want to move? (u/d/l/r): d
Score: 4
Remaining Cookies: 45

H H H H H H H H H H

H   * * * * * * * H

H   * * * * * * * H

H   * H * * H * * H

H   * H * * H * G H

H P * H * * H *   H

H * * H * * H *   H

H * * H * * H *   H

H * * * * * * *   *

H H H H H H H H H H

How do you want to move? (u/d/l/r): d
Score: 5
Remaining Cookies: 43

H H H H H H H H H H

H   * * * * * * * H

H   * * * * * * * H

H   * H * * H * G H

H   * H * * H *   H

H   * H * * H *   H

H P * H * * H *   H

H * * H * * H *   H

H * * * * * * *   *

H H H H H H H H H H

How do you want to move? (u/d/l/r): d
Score: 6
Remaining Cookies: 41

H H H H H H H H H H

H   * * * * * * * H

H   * * * * * * G H

H   * H * * H *   H

H   * H * * H *   H

H   * H * * H *   H

H   * H * * H *   H

H P * H * * H *   H

H * * * * * * *   *

H H H H H H H H H H

How do you want to move? (u/d/l/r): d
Score: 7
Remaining Cookies: 39

H H H H H H H H H H

H   * * * * * * G H

H   * * * * * *   H

H   * H * * H *   H

H   * H * * H *   H

H   * H * * H *   H

H   * H * * H *   H

H   * H * * H *   H

H P * * * * * *   *

H H H H H H H H H H

How do you want to move? (u/d/l/r): r
Score: 8
Remaining Cookies: 37

H H H H H H H H H H

H   * * * * * G   H

H   * * * * * *   H

H   * H * * H *   H

H   * H * * H *   H

H   * H * * H *   H

H   * H * * H *   H

H   * H * * H *   H

H   P * * * * *   *

H H H H H H H H H H

How do you want to move? (u/d/l/r): u
Score: 9
Remaining Cookies: 35

H H H H H H H H H H

H   * * * * G     H

H   * * * * * *   H

H   * H * * H *   H

H   * H * * H *   H

H   * H * * H *   H

H   * H * * H *   H

H   P H * * H *   H

H     * * * * *   *

H H H H H H H H H H

How do you want to move? (u/d/l/r): u
Score: 10
Remaining Cookies: 34

H H H H H H H H H H

H   * * * *     G H

H   * * * * * *   H

H   * H * * H *   H

H   * H * * H *   H

H   * H * * H *   H

H   P H * * H *   H

H     H * * H *   H

H     * * * * *   *

H H H H H H H H H H

How do you want to move? (u/d/l/r): u
Score: 11
Remaining Cookies: 33

H H H H H H H H H H

H   * * * *   G   H

H   * * * * * *   H

H   * H * * H *   H

H   * H * * H *   H

H   P H * * H *   H

H     H * * H *   H

H     H * * H *   H

H     * * * * *   *

H H H H H H H H H H

How do you want to move? (u/d/l/r): u
Score: 12
Remaining Cookies: 32

H H H H H H H H H H

H   * * * * G     H

H   * * * * * *   H

H   * H * * H *   H

H   P H * * H *   H

H     H * * H *   H

H     H * * H *   H

H     H * * H *   H

H     * * * * *   *

H H H H H H H H H H

How do you want to move? (u/d/l/r): u
Score: 13
Remaining Cookies: 30

H H H H H H H H H H

H   * * * G       H

H   * * * * * *   H

H   P H * * H *   H

H     H * * H *   H

H     H * * H *   H

H     H * * H *   H

H     H * * H *   H

H     * * * * *   *

H H H H H H H H H H

How do you want to move? (u/d/l/r): u
Score: 14
Remaining Cookies: 28

H H H H H H H H H H

H   * * G         H

H   P * * * * *   H

H     H * * H *   H

H     H * * H *   H

H     H * * H *   H

H     H * * H *   H

H     H * * H *   H

H     * * * * *   *

H H H H H H H H H H

How do you want to move? (u/d/l/r): r
Score: 15
Remaining Cookies: 26

H H H H H H H H H H

H   * G           H

H     P * * * *   H

H     H * * H *   H

H     H * * H *   H

H     H * * H *   H

H     H * * H *   H

H     H * * H *   H

H     * * * * *   *

H H H H H H H H H H

How do you want to move? (u/d/l/r): r
Score: 16
Remaining Cookies: 24

H H H H H H H H H H

H   G             H

H       P * * *   H

H     H * * H *   H

H     H * * H *   H

H     H * * H *   H

H     H * * H *   H

H     H * * H *   H

H     * * * * *   *

H H H H H H H H H H

How do you want to move? (u/d/l/r): r
Score: 17
Remaining Cookies: 23

H H H H H H H H H H

H G               H

H         P * *   H

H     H * * H *   H

H     H * * H *   H

H     H * * H *   H

H     H * * H *   H

H     H * * H *   H

H     * * * * *   *

H H H H H H H H H H

How do you want to move? (u/d/l/r): r
Score: 18
Remaining Cookies: 22

H H H H H H H H H H

H                 H

H           P *   H

H     H * * H *   H

H     H * * H *   H

H     H * * H *   H

H     H * * H *   H

H     H * * H *   H

H     * * * * * G *

H H H H H H H H H H

How do you want to move? (u/d/l/r): r
Score: 19
Remaining Cookies: 21

H H H H H H H H H H

H                 H

H             P   H

H     H * * H *   H

H     H * * H *   H

H     H * * H *   H

H     H * * H *   H

H     H * * H * G H

H     * * * * *   *

H H H H H H H H H H

How do you want to move? (u/d/l/r): d
Score: 20
Remaining Cookies: 20

H H H H H H H H H H

H                 H

H                 H

H     H * * H P   H

H     H * * H *   H

H     H * * H *   H

H     H * * H *   H

H     H * * H *   H

H     * * * * * G *

H H H H H H H H H H

How do you want to move? (u/d/l/r): d
Score: 21
Remaining Cookies: 19

H H H H H H H H H H

H                 H

H                 H

H     H * * H     H

H     H * * H P   H

H     H * * H *   H

H     H * * H *   H

H     H * * H * G H

H     * * * * *   *

H H H H H H H H H H

How do you want to move? (u/d/l/r): d
Score: 22
Remaining Cookies: 18

H H H H H H H H H H

H                 H

H                 H

H     H * * H     H

H     H * * H     H

H     H * * H P   H

H     H * * H * G H

H     H * * H *   H

H     * * * * *   *

H H H H H H H H H H

How do you want to move? (u/d/l/r): d
Score: 23
Remaining Cookies: 17

H H H H H H H H H H

H                 H

H                 H

H     H * * H     H

H     H * * H     H

H     H * * H   G H

H     H * * H P   H

H     H * * H *   H

H     * * * * *   *

H H H H H H H H H H

How do you want to move? (u/d/l/r): d
Score: 24
Remaining Cookies: 16

H H H H H H H H H H

H                 H

H                 H

H     H * * H     H

H     H * * H   G H

H     H * * H     H

H     H * * H     H

H     H * * H P   H

H     * * * * *   *

H H H H H H H H H H

How do you want to move? (u/d/l/r): d
Score: 25
Remaining Cookies: 15

H H H H H H H H H H

H                 H

H                 H

H     H * * H   G H

H     H * * H     H

H     H * * H     H

H     H * * H     H

H     H * * H     H

H     * * * * P   *

H H H H H H H H H H

How do you want to move? (u/d/l/r): l
Score: 26
Remaining Cookies: 14

H H H H H H H H H H

H                 H

H               G H

H     H * * H     H

H     H * * H     H

H     H * * H     H

H     H * * H     H

H     H * * H     H

H     * * * P     *

H H H H H H H H H H

How do you want to move? (u/d/l/r): l
Score: 27
Remaining Cookies: 13

H H H H H H H H H H

H               G H

H                 H

H     H * * H     H

H     H * * H     H

H     H * * H     H

H     H * * H     H

H     H * * H     H

H     * * P       *

H H H H H H H H H H

How do you want to move? (u/d/l/r): u
Score: 28
Remaining Cookies: 12

H H H H H H H H H H

H             G   H

H                 H

H     H * * H     H

H     H * * H     H

H     H * * H     H

H     H * * H     H

H     H * P H     H

H     * *         *

H H H H H H H H H H

How do you want to move? (u/d/l/r): u
Score: 29
Remaining Cookies: 11

H H H H H H H H H H

H           G     H

H                 H

H     H * * H     H

H     H * * H     H

H     H * * H     H

H     H * P H     H

H     H *   H     H

H     * *         *

H H H H H H H H H H

How do you want to move? (u/d/l/r): u
Score: 30
Remaining Cookies: 10

H H H H H H H H H H

H                 H

H                 H

H     H * * H     H

H     H * * H     H

H     H * P H     H

H     H *   H     H

H     G *   H     H

H     * *         *

H H H H H H H H H H

How do you want to move? (u/d/l/r): u
Score: 31
Remaining Cookies: 9

H H H H H H H H H H

H                 H

H                 H

H     H * * H     H

H     H * P H     H

H     H *   H     H

H     G *   H     H

H     H *   H     H

H     * *         *

H H H H H H H H H H

How do you want to move? (u/d/l/r): u
Score: 32
Remaining Cookies: 8

H H H H H H H H H H

H                 H

H                 H

H     H * P H     H

H     H *   H     H

H     G *   H     H

H     H *   H     H

H     H *   H     H

H     * *         *

H H H H H H H H H H

How do you want to move? (u/d/l/r): r
Ouch!
Score: 32
Remaining Cookies: 8

H H H H H H H H H H

H                 H

H                 H

H     H * P H     H

H     H *   H     H

H     G *   H     H

H     H *   H     H

H     H *   H     H

H     * *         *

H H H H H H H H H H

How do you want to move? (u/d/l/r): l
Score: 33
Remaining Cookies: 7

H H H H H H H H H H

H                 H

H                 H

H     H P   H     H

H     G *   H     H

H     H *   H     H

H     H *   H     H

H     H *   H     H

H     * *         *

H H H H H H H H H H

How do you want to move? (u/d/l/r): d
Score: 34
Remaining Cookies: 6

H H H H H H H H H H

H                 H

H                 H

H     G     H     H

H     H P   H     H

H     H *   H     H

H     H *   H     H

H     H *   H     H

H     * *         *

H H H H H H H H H H

How do you want to move? (u/d/l/r): d
Score: 35
Remaining Cookies: 5

H H H H H H H H H H

H                 H

H     G           H

H     H     H     H

H     H     H     H

H     H P   H     H

H     H *   H     H

H     H *   H     H

H     * *         *

H H H H H H H H H H

How do you want to move? (u/d/l/r): d
Score: 36
Remaining Cookies: 4

H H H H H H H H H H

H     G           H

H                 H

H     H     H     H

H     H     H     H

H     H     H     H

H     H P   H     H

H     H *   H     H

H     * *         *

H H H H H H H H H H

How do you want to move? (u/d/l/r): d
Score: 37
Remaining Cookies: 3

H H H H H H H H H H

H   G             H

H                 H

H     H     H     H

H     H     H     H

H     H     H     H

H     H     H     H

H     H P   H     H

H     * *         *

H H H H H H H H H H

How do you want to move? (u/d/l/r): d
Score: 38
Remaining Cookies: 2

H H H H H H H H H H

H G               H

H                 H

H     H     H     H

H     H     H     H

H     H     H     H

H     H     H     H

H     H     H     H

H     * P         *

H H H H H H H H H H

How do you want to move? (u/d/l/r): r
Score: 38
Remaining Cookies: 2

H H H H H H H H H H

H                 H

H                 H

H     H     H     H

H     H     H     H

H     H     H     H

H     H     H     H

H     H     H     H

H     *   P     G *

H H H H H H H H H H

How do you want to move? (u/d/l/r): l
Score: 38
Remaining Cookies: 2

H H H H H H H H H H

H                 H

H                 H

H     H     H     H

H     H     H     H

H     H     H     H

H     H     H     H

H     G     H     H

H     * P         *

H H H H H H H H H H

How do you want to move? (u/d/l/r): l
Score: 39
Remaining Cookies: 1

H H H H H H H H H H

H                 H

H                 H

H     H     H     H

H     H     H     H

H     H     H     H

H     G     H     H

H     H     H     H

H     P           *

H H H H H H H H H H

How do you want to move? (u/d/l/r): r
Score: 39
Remaining Cookies: 1

H H H H H H H H H H

H                 H

H                 H

H     H     H     H

H     H     H     H

H     G     H     H

H     H     H     H

H     H     H     H

H       P         *

H H H H H H H H H H

How do you want to move? (u/d/l/r): r
Score: 39
Remaining Cookies: 1

H H H H H H H H H H

H                 H

H                 H

H     H     H     H

H     G     H     H

H     H     H     H

H     H     H     H

H     H     H     H

H         P       *

H H H H H H H H H H

How do you want to move? (u/d/l/r): r
Score: 39
Remaining Cookies: 1

H H H H H H H H H H

H                 H

H                 H

H     G     H     H

H     H     H     H

H     H     H     H

H     H     H     H

H     H     H     H

H           P     *

H H H H H H H H H H

How do you want to move? (u/d/l/r): r
Score: 39
Remaining Cookies: 1

H H H H H H H H H H

H                 H

H     G           H

H     H     H     H

H     H     H     H

H     H     H     H

H     H     H     H

H     H     H     H

H             P   *

H H H H H H H H H H

How do you want to move? (u/d/l/r): r
Score: 39
Remaining Cookies: 1

H H H H H H H H H H

H     G           H

H                 H

H     H     H     H

H     H     H     H

H     H     H     H

H     H     H     H

H     H     H     H

H               P *

H H H H H H H H H H

How do you want to move? (u/d/l/r): r
Score: 40
Remaining Cookies: 0

H H H H H H H H H H

H   G             H

H                 H

H     H     H     H

H     H     H     H

H     H     H     H

H     H     H     H

H     H     H     H

H                 P

H H H H H H H H H H

Congratulations! You win!
Final score: 40




Example 2: Losing the Game:



Welcome to Pac-Cookie!

Your goal is to eat all remaining cookies (at least 20) - before you escape!
But, beware the not-so-friendly ghosts...
They will eat the cookies... and YOU!

Ready to play? Let's go!

Score: 0
Remaining Cookies: 53

H H H H H H H H H H

H P * * * * * * * H

H * * * * * * * * H

H * * H * * H * * H

H * * H * * H * * H

H * * H * * H * * H

H * * H * * H * * H

H * * H * * H * * H

H * * * * * * * G *

H H H H H H H H H H

How do you want to move? (u/d/l/r): r
Score: 1
Remaining Cookies: 51

H H H H H H H H H H

H   P * * * * * * H

H * * * * * * * * H

H * * H * * H * * H

H * * H * * H * * H

H * * H * * H * * H

H * * H * * H * * H

H * * H * * H * G H

H * * * * * * *   *

H H H H H H H H H H

How do you want to move? (u/d/l/r): r
Score: 2
Remaining Cookies: 49

H H H H H H H H H H

H     P * * * * * H

H * * * * * * * * H

H * * H * * H * * H

H * * H * * H * * H

H * * H * * H * * H

H * * H * * H * G H

H * * H * * H *   H

H * * * * * * *   *

H H H H H H H H H H

How do you want to move? (u/d/l/r): r
Score: 3
Remaining Cookies: 47

H H H H H H H H H H

H       P * * * * H

H * * * * * * * * H

H * * H * * H * * H

H * * H * * H * * H

H * * H * * H * G H

H * * H * * H *   H

H * * H * * H *   H

H * * * * * * *   *

H H H H H H H H H H

How do you want to move? (u/d/l/r): r
Score: 4
Remaining Cookies: 45

H H H H H H H H H H

H         P * * * H

H * * * * * * * * H

H * * H * * H * * H

H * * H * * H * G H

H * * H * * H *   H

H * * H * * H *   H

H * * H * * H *   H

H * * * * * * *   *

H H H H H H H H H H

How do you want to move? (u/d/l/r): r
Score: 5
Remaining Cookies: 43

H H H H H H H H H H

H           P * * H

H * * * * * * * * H

H * * H * * H * G H

H * * H * * H *   H

H * * H * * H *   H

H * * H * * H *   H

H * * H * * H *   H

H * * * * * * *   *

H H H H H H H H H H

How do you want to move? (u/d/l/r): r
Score: 6
Remaining Cookies: 41

H H H H H H H H H H

H             P * H

H * * * * * * * G H

H * * H * * H *   H

H * * H * * H *   H

H * * H * * H *   H

H * * H * * H *   H

H * * H * * H *   H

H * * * * * * *   *

H H H H H H H H H H

How do you want to move? (u/d/l/r): r
Score: 7
Remaining Cookies: 39

H H H H H H H H H H

H               G H

H * * * * * * *   H

H * * H * * H *   H

H * * H * * H *   H

H * * H * * H *   H

H * * H * * H *   H

H * * H * * H *   H

H * * * * * * *   *

H H H H H H H H H H

You lose!



Example 3: Losing the Game:

How do you want to move? (u/d/l/r): u
Score: 13
Remaining Cookies: 8

H H H H H H H H H H

H                 H

H   *             H

H   * H     H     H

H   G H     H     H

H     H   * H     H

H P * H   * H     H

H     H   * H     H

H           *     *

H H H H H H H H H H

How do you want to move? (u/d/l/r): u
Score: 13
Remaining Cookies: 7

H H H H H H H H H H

H                 H

H   *             H

H   G H     H     H

H     H     H     H

H P   H   * H     H

H   * H   * H     H

H     H   * H     H

H           *     *

H H H H H H H H H H

How do you want to move? (u/d/l/r): u
Score: 13
Remaining Cookies: 6

H H H H H H H H H H

H                 H

H   G             H

H     H     H     H

H P   H     H     H

H     H   * H     H

H   * H   * H     H

H     H   * H     H

H           *     *

H H H H H H H H H H

You lose!


What to Submit:

  • Submit your completed Player.java, Ghost.java, Spooky.java, and Game.java files (make sure your name(s) are on all files) to Canvas.
    • Note: Please do not submit Character.java
  • One partner submits Player.java, Ghost.java, Spooky.java, and Game.java and the pair programming contract.
    • The other other partner only submits the pair programming contract.

How You Will Be Graded:

  • 100 points: The assignment works as shown in the sample output plus you added Spooky to the game. All required features are implemented and implemented correctly. You correctly implemented Spooky.java, and both of the Ghosts are featured in your game
  • 80-100 points: The assignment works mostly as shown in the sample output. Most required features are implemented and implemented correctly.
  • 40-80 points: Some of the assignment works as shown in the sample output. Some required features are implemented and implemented correctly.
  • 10-40 points: Serious problems in implementation and little correspondence between sample output and what is shown. Few of the features implemented or implemented correctly.
  • 0 points: Code does not compile or outputs an error at runtime.
  • 0 points: You altered the Character.java class from the starter code.
  • 5 point deduction for missing pair programming contract.
  • 5 point deduction for code that is not properly formatted (Note: Go to Source->Format on Eclipse).
  • 5 point deduction for submitting a zip file.
  • 5 point deduction for any package statements on any file - please remove before submitting.



Pair Programming Required (Or No Credit)

  • Both partners fill in, sign, date, and submit the pair programming contract
  • Upload the document(s) along with your Lab to Canvas.
  • Only ONE partner submits the lab assignment on Canvas. Please make sure both your names are on the source file(s).


Lab 6.1: The Strung Class (100 pts)

  • In this assignment you will write a class similar to Java's String class, including many identical or similar methods.
  • Begin by copying and pasting the below starter code into a file named Strung.java.
  • Then, implement the methods according to the Javadoc comment provided for each method.
  • As you write each method, run the test file to verify that your code is working properly.
  • Note that any error messages should be identical to those in the sample output.
Strung.java Starter Code:

/**
 * @author
 * @author
 * CIS 36B, Lab 6.1
 */
public class Strung {
    private char[] array;
    private int numChars;
   
    /**
     * Constructor for the Strung class
     * @param s a String to convert
     * to a Strung
     */
    public Strung(String s) {
       
    }
   
    /**
     * Constructor of the Strung class
     * @param a an array of chars
     */
    public Strung(char[] a) {
       
    }
   
    /**
     * Copy constructor for the Strung class
     * @param s another Strung
     * Makes a DEEP copy
     */
    public Strung(Strung s) {
       
    }
   
    /**
     * Returns the char at the given position
     * @param i the position of the char
     * @return the char located at i or a
     * null character in the case of error
     */
    public char charAt(int i) {
        return '\0'; //the null character
    }
   
    /**
     * Returns the location of a char
     * @param c the char to locate
     * @return the location of c
     */
    public int indexOf(char c) {
        return -1;
    }
   
    /**
     * Returns the number of characters
     * @return the number of characters
     */
    public int length() {
        return -1;
    }
   
    /**
     * Determines if a specified char is
     * contained within the Strung
     * @param c the char to locate
     * @return whether c is in Strung
     */
    public boolean contains(char c) {
       
        return false;   
    }
   
    /**
     * Returns a smaller Strung from start to end
     * @param start starting index in the Strung
     * @param end ending index in the Strung
     * @return another Strung or null in the case
     * of error
     */
    public Strung substrung(int start, int end) {
        return null;
    }
   
    /**
     * Returns a smaller Strung from start
     * to the end of the Strung
     * @param start starting index in the Strung
     * @return another Strung or null in
     * the case of error
     */
    public Strung substrung(int start) {
        return null;
    }
   
    /**
     * Converts this Strung to
     * all lower case characters
     */
    public void toLowerCase() {
       
    }
   
    /**
     * Converts this Strung to
     * all upper case characters
     */
    public void toUpperCase() {
       
    }
   
    /**
     * ToString method for the Strung class
     * @return a String of all characters
     * with no spaces in between any character
     */
    @Override public String toString(){
        return null;
    }
   
    /**
     * Determines whether this Strung
     * is equal to another o
     * Two Strungs are equal if they contain
     * the same chars in the same order
     */
    @Override public boolean equals(Object o){
        return false;  
    }
}

StrungTest.java:

/**
 * @author parrishj
 * CIS 36B, Lab 6.1
 */
public class StrungTest {
    public static void main(String[] args) {
        /*Constructors*/
        System.out.println("\n***Testing Constructors***");
        Strung s = new Strung("ABC");
        System.out.println("Testing String Constructor: Should print ABC: " + s);
        Strung s1 = new Strung("");
        System.out.println("Testing String Constructor: Should print an empty String: " + s1);
        Strung s2 = new Strung(s);
        System.out.println("Testing Copy Constructor: Should print ABC: " + s2);
        s2.toLowerCase();
        System.out.println("Testing For Deep Copy: Copy should print abc: " + s2);
        System.out.println("Testing For Deep Copy: Original should print ABC: " + s);
        char[] array = {'a', 'b', 'c', 'd', 'e'};
        Strung s3 = new Strung(array);
        System.out.println("Testing Array Constructor: Should print abcde: " + s3);
       
       
        /*CharAt*/
        System.out.println("\n***Testing CharAt()***");
        System.out.println("Should print b: " + s3.charAt(1));
        System.out.println("Should print b: " + s2.charAt(1));
        System.out.print("Should print error: ");
        System.out.println(s.charAt(10));
       
        /*Substrung(start, end)*/
        System.out.println("\n***Testing Substrung(start, end)***");
        System.out.println("Should print b: " + s2.substrung(1,2));
        System.out.println("Should print abc: " + s3.substrung(0,3));
        System.out.print("Should print error message: ");
        s3.substrung(4, 3);
        System.out.print("Should print error message: ");
        s3.substrung(-1, 10);
       
        /*Substrung(start)*/
        System.out.println("\n***Testing Substrung(start)***");
        System.out.println("Should print bc: " + s2.substrung(1));
        System.out.println("Should print cde: " + s3.substrung(2));
        System.out.print("Should print error message: ");
        s3.substrung(-1);
        System.out.print("Should print error message: ");
        s3.substrung(10);
       
        /*Contains*/
        System.out.println("\n***Testing Contains***");
        System.out.println("Should print true: " + s2.contains('a'));
        System.out.println("Should print false: " + s2.contains('f'));
       
        /*IndexOf*/
        System.out.println("\n***Testing IndexOf***");
        System.out.println("Should print 0: " + s3.indexOf('a'));
        System.out.println("Should print 3: " + s3.indexOf('d'));
        System.out.println("Should print -1: " + s3.indexOf('f'));
       
        /*Length*/
        System.out.println("\n***Testing Length***");
        System.out.println("Should print 3: " + s.length());
        System.out.println("Should print 0: " + s1.length());
        System.out.println("Should print 3: " + s2.length());
        System.out.println("Should print 5: " + s3.length());
       
        /*ToLowerCase*/
        System.out.println("\n***Testing ToLowerCase***");
        s.toLowerCase();
        System.out.println("Should print abc: " + s);
       
        /*ToUpperCase*/
        System.out.println("\n***Testing ToUpperCase***");
        s.toUpperCase();
        System.out.println("Should print ABC: " + s);
        s2.toUpperCase();
        System.out.println("Should print ABC: " + s2);
       
        /*Equals*/
        System.out.println("\n***Testing Equals***");
        System.out.println("Should print true: " + s.equals(s2));
        s2.toLowerCase();
        System.out.println("Should print false: " + s.equals(s2));
        System.out.println("Should print false: " + s2.equals(s3));
        System.out.println("Should print false: " + s.equals("ABC"));
    }
}


StrungTest Output: Your Output must be IDENTICAL to the output below for full credit:



***Testing Constructors***
Testing String Constructor: Should print ABC: ABC
Testing String Constructor: Should print an empty String:
Testing Copy Constructor: Should print ABC: ABC
Testing For Deep Copy: Copy should print abc: abc
Testing For Deep Copy: Original should print ABC: ABC
Testing Array Constructor: Should print abcde: abcde

***Testing CharAt()***
Should print b: b
Should print b: b
Should print error: CharAt Error: Index must be in the range 0 to 2


***Testing Substrung(start, end)***
Should print b: b
Should print abc: abc
Should print error message: Substrung Error: starting index must be less than ending index
Should print error message: Substrung Error: Index must be in the range 0 to 4

***Testing Substrung(start)***
Should print BC: bc
Should print cde: cde
Should print error message: Substrung Error: Index must be in the range 0 to 4
Should print error message: Substrung Error: Index must be in the range 0 to 4

***Testing Contains***
Should print true: true
Should print false: false

***Testing IndexOf***
Should print 0: 0
Should print 3: 3
Should print -1: -1

***Testing Length***
Should print 3: 3
Should print 0: 0
Should print 3: 3
Should print 5: 5

***Testing ToLowerCase***
Should print abc: abc

***Testing ToUpperCase***
Should print ABC: ABC
Should print ABC: ABC

***Testing Equals***
Should print true: true
Should print false: false
Should print false: false
Should print false: false



What to Submit:

  • Submit your completed Strung.java file (make sure your both names are on the file) to Canvas.
  • One partner submits Strung.java and the pair programming contract.
    • The other other partner only submits the pair programming contract.

How You Will Be Graded:

  • 100 points: The assignment works as shown in the sample output
  • 80-100 points: The assignment works mostly as shown in the sample output. Most required features are implemented and implemented correctly.
  • 40-80 points: Some of the assignment works as shown in the sample output. Some required features are implemented and implemented correctly.
  • 10-40 points: Serious problems in implementation and little correspondence between sample output and what is shown. Few of the features implemented or implemented correctly.
  • 0 points: Code does not compile or outputs an error at runtime.
  • 5 point deduction for missing pair programming contract
  • 5 point deduction for code that is not properly formatted (Note: Go to Source->Format on Eclipse)

Lab 6.2: Valued Rewards Members (100 pts)
  • In this lab, we will be bring inheritance and static methods and variables to your User and Profile Assignment
  • In the same project folder as your previous assignment, create a new class named RewardMember.java
  • Here is the important information about this class:
  • RewardMember is a subclass of User
  • It has two private static variables:
    • numRewardMembers, an integer, which is initialized to 0
    • rewardNumber, an integer, which is initialized to 99556
  • It has one private (non static) variable:
    • memberNumber, a String
  • It has two constructors:
    • A default constructor, which calls the constructor of the super class, and also initializes memberNumber to be "number unknown"
    • A 6-argument constructor, which calls the 5-argument constructor of the super class, and also initializes memberNumber to be a value passed in as a parameter
  • It has one mutator method to update the value of member number.
    • The name of the mutator is setMemberNumber.
    • It takes in one String parameter
    • It returns nothing
  • It has one accessor method to return the value of member number:
    • The name of the accessor is getMemberNumber
    • It has no parameters
    • It returns a String
  • It has one static accessor method to return the value of numRewardsMembers
    • The name of the method is getNumRewardsMembers
    • It has no parameters
    • It returns an int
  • It has one static mutator method to increment the value of numRewardsMembers
      • The name of the method is updateNumRewardsMembers
      • It has no parameters
      • It returns nothing.
  • It has one additional static method as follows:
    • The name of the method is generateRewardNumber
    • It increments rewardNumber by 1
    • It returns rewardNumber as a String
  • It Overrides toString by calling the superclass toString and also concatenating the member number
  • Open up the User.java class and be ready to make some additional alterations, as follows:
    • Declare a private static variable at the top of the class named numUsers and initialize it to 0.
    • Add a static accessor method called getNumUsers:
      • This method is static
      • It returns an int for the number of users
      • It takes no parameters
    • Add a static mutator method called updateNumUsers
      • This method is static
      • It takes in no parameters and returns nothing
      • It updates the numUsers variable by 1
  • Now, we will also alter the names.txt input file. Copy and paste the below contents into names.txt file:
Jiming Wu
F
4082123458
jwu@gmail.com
abc123
RM
987684
James Brown
M
8315678432
jaime.boy.brown@hotmail.com
jjjbbb123
NRM
0
Leanna Perez
F
4087654433
leaperez@yahoo.com
letmein
NRM
0
Xing Li
M
8313214555
xing.li@sbcglobal.net
555!!!hi
NRM
0
Stacey Cahill
O
8312123333
scahill@gmail.com
r0tr@tr^n
RM
945544
Mohammed Abbas
M
4083134444
downtown_abbas@yahoo.com
1@m@bb@s
RM
945575
Kumari Chakrabarti
F
4086667777
kukuchakrabarti@hotmail.com
passw0rd
NRM
0
Shakil Smith
M
4082123333
shakattaq@gmail.com
qwerty
RM
945682
Jung Ahrin
F
8319257788
jung_ahrin@yahoo.com
password1
NRM
0
Pedro Martinez
M
4086162323
pedro2018@sbcglobal.net
123456789
RM
945873
Ally Gu
O
4089256776
i_am_ally@comcast.net
trustno1
NRM
0
Tamara White
F
8317778978
tamtastic@gmail.com
1qaz2wsx
RM
956689
Alvin Ngo
M
4089256677
drngo@hotmail.com
qwertyuiop
NRM
0
Abir Fadel
M
8316645325
greatabs@comcast.com
qazwsx
RM
942211
Brad Feinman
M
8312023443
bradisrad@gmail.com
11111
NRM
0
Xiaohang Yue
M
8318990033
yue95@yahoo.com
adobe123
NRM
0
  • Note that this file now contains information about whether each user is also a rewards member.
    • For those users who are rewards members, the acronym RM appears in the line below their passwords, along with a member number on the next line.
    • For those users who are not rewards members, the acronym NRM appears in the line below their passwords, along with a 0 on the next line to indicate no member number
  • In Profiles.java, declare a new ArrayList to store RewardMember objects.
  • As you read in the contents of the names.txt file, any User who is also a RewardMember should be inserted into both ArrayLists.
  • The program should then adapt to 4 different types of users:
    • Users who are rewards members
    • Users who are not rewards members
    • New users who do not appear in names.txt (must create an account) AND decide to become rewards members
    • New users who do not appear in names.txt (must create an account) and decide NOT to become rewards members
  • To search for rewards members, in the new ArrayList, alter the signature of linearSearch as follows:
public int linearSearch(String email, String password, ArrayList<RewardMember> rm)
  • Additionally, you will need bubbleSort and binary search:
public static void bubblesort(ArrayList<User> users)

      public static int binarySearch(String email, String password, ArrayList<User> users) {

  • Now, linearSearch will be used exclusively to search for rewards members in the new ArrayList
  • bubbleSort and binarySearch will be used exclusively to search for users in the users ArrayList
  • Make any additional changes you need to produce output like that shown below.
  • When you are finished, upload User.java, RewardMember.java and Profile.java to Canvas
  • Note that your program should still write the users ArrayList to accounts.txt before the program ends.

Sample Output - Example Showing User Who is Not a Reward Member:

Welcome!

We are proudly serving 16 users and counting!

Enter your email address: kukuchakrabarti@hotmail.com
Enter your password: passw0rd

Hi, Kumari Chakrabarti!
We have the following information on file for you:
Name: Kumari Chakrabarti
Gender: F
Phone: (408)666-7777
Email: kukuchakrabarti@hotmail.com


Sample Output - Example Showing User Who is a Reward Member:

Welcome!

We are proudly serving 16 users and counting!

Enter your email address: pedro2018@sbcglobal.net
Enter your password: 123456789

Welcome valued reward member, Pedro Martinez!

We have the following information on file for you:
Name: Pedro Martinez
Gender: M
Phone: (408)616-2323
Email: pedro2018@sbcglobal.net
Member Number: 945873

Thank you for being one of our 7 valued reward members.
To show our appreciation, enjoy 10% off all shopping today!

Have a great day!


Sample Output - Example Showing a New User Who Becomes a Reward Member:

Welcome!

We are proudly serving 16 users and counting!

Enter your email address: myEmail@gmail.com
Enter your password: iforgetit

Sorry! We don't have your account on file.
Let's create an account for you!


Enter your name: Joe Schmoe
Enter your gender: M
Enter your 10 digit phone number (no spaces or punctuation): 1112223344

Thank you, Joe Schmoe!
Your account has now been created.

Name: Joe Schmoe
Gender: M
Phone: (111)222-3344
Email: myEmail@gmail.com

Would you like to join our Reward Member program and save 10% off all purchases today?
Enter yes or no: Yes

Thank you! In exchange for becoming a valued member,
we reserve the right to collect detailed information about you
and your shopping habits and sell this information to other companies.

Here is your new member number: 99557

Have a great day!


Sample Output - Example Showing a New User Who Does Not Become a Reward Member:

Welcome!

We are proudly serving 16 users and counting!

Enter your email address: myEmail@gmail.com
Enter your password: iforgetit

Sorry! We don't have your account on file.
Let's create an account for you!


Enter your name: Joe Schmoe
Enter your gender: M
Enter your 10 digit phone number (no spaces or punctuation): 1112223344

Thank you, Joe Schmoe!
Your account has now been created.

Name: Joe Schmoe
Gender: M
Phone: (111)222-3344
Email: myEmail@gmail.com

Would you like to join our Reward Member program and save 10% off all purchases today?
Enter yes or no: no

Goodbye!


What to Submit:

  • Submit your completed User.java, Profile.java, RewardMember.java files (make sure both your names are on all files) to Canvas.
  • One partner submits the 3 Java files and the pair programming contract.
    • The other other partner only submits the pair programming contract.

How You Will Be Graded:

  • 100 points: The assignment works as shown in the sample output
  • 80-100 points: The assignment works mostly as shown in the sample output. Most required features are implemented and implemented correctly.
  • 40-80 points: Some of the assignment works as shown in the sample output. Some required features are implemented and implemented correctly.
  • 10-40 points: Serious problems in implementation and little correspondence between sample output and what is shown. Few of the features implemented or implemented correctly.
  • 0 points: Code does not compile or outputs an error at runtime.
  • 5 point deduction for missing pair programming contract
  • 5 point deduction for not removing package statements from the top of your files
  • 5 point deduction for code that is not properly formatted (Note: Go to Source->Format on Eclipse)





Lab 8.1: A Generic Container Class (100 pts)

  • This lab will give you an even better peek under the hood of a generic class - one that we will call Container
  • Note that Container can store data of any Object type - Strings, Integers, Doubles, Booleans, Characters, and more, including our own Object types.
  • Like the Strung and ListArray class, we will use an underlying array to store the data in the Container
  • However, although our class is generic, arrays of generic types are not allowed in Java (see Lesson 14 notes).
  • Therefore, on certain occasions, we will need to declare an array of Objects and cast it to be an array of type E (our generic type parameter)
  • For example, here should be your default constructor:
      /**
     * Default constructor
     * Creates a new Container of length 10
     */
    @SuppressWarnings("unchecked")
    public Container() {
        numItems = 0;
        array = (E[]) new Object[10];
    }

  • You will need to follow a similar model for the one-argument constructor, the copy constructor, and also the increaseCapacity method.
    • In other words, anywhere that you need to create a new array, you must first declare an array of Objects, and then cast this array to be of type E[]
    • This technique allows us to work around the restriction on generic arrays.
  • Note: Generic code can generate warnings when casting to a generic type (as in the above method).
    • There is no way for the compiler to verify that the types are compatible, when the type is unknown
    • We will suppress the warnings, using @SuppressWarnings("unchecked"), as we are confident that no runtime errors will occur
    • I have added the tags for you in the starter code below in any case that they are required
  • Copy and paste the following starter code into a new class file called Container.java:
/**
 * Container.java
 * @author
 * @author
 * CIS 36B, Lab 8.1
 */

public class Container<E> {
    private int numItems;
    private E[] array;
    
    /**Constructors*/
    
    /**
     * Default constructor
     * Creates a new Container of length 10
     */
    @SuppressWarnings("unchecked")
    public Container() {
        numItems = 0;
        array = (E[]) new Object[10];
    }
    
    /**
     * Constructor for Container class
     * @param initialCapacity the initial
     * length of the Container
     * Creates a Container of length
     * initialCapacity
     */
    @SuppressWarnings("unchecked")
    public Container(int initialCapacity) {
      
    }
    
    /**
     * Copy constructor for Container class
     * @param c another Container
     * Creates a Container that is a
     * copy of c
     */
    @SuppressWarnings("unchecked")
    public Container(Container<E> c) {
       
    }
    
    /**Mutators*/
    
    /**
     * Shifts all items down to
     * Insert a new item at the start
     * of the Container
     * Calls increaseCapacity when the
     * adding a new item when
     * numItems == array.length
     * @param item a new item
     */
    public void addStart(E item) {
       
    }
    
    /**
     * Inserts a new item at the
     * end of the Container

     * Calls increaseCapacity when the
     * adding a new item when
     * numItems == array.length
     * @param item a new item
     */
    public void addEnd(E item) {
       
    }
    
    /**
     * Inserts a new item at the
     * specified index of the Container
     * @param index the index at which
     * to insert
     * @param item a new item

     * Calls increaseCapacity when the
     * adding a new item when
     * numItems == array.length
     * Prints an error message if index < 0 or
     * index > numItems and returns null
     */
    public void add(int index, E item) {
       
    }
    
    /**
     * Removes the first element in the
     * container
     * Prints an error message if the
     * container is empty
     */
    public void removeStart() {
       
    }
    
    /**
     * Removes the item at the specified index
     * @param index of the item to remove
     * Prints an error message if index is
     * < 0 or index > numItems
     */
    public void remove(int index) {
       
    }
    
    /**
     * Removes the last element in the
     * container
     * Prints an error message if the
     * container is empty
     */
    public void removeEnd() {
       
    }
    
    /**Accessors*/
    
    /**
     * Counts the number of times
     * item appears in the container
     * @param item the item to search for
     * @return the number of times
     * item appears in the container
     */
    public int countOccurences(E item) {
        int count = 0;
       
        return count;
    }
    
    /**
     * Returns the item stored at
     * the given index
     * @param index the index of the
     * item to return
     * @return a random item
     * Prints an error message if index < 0 or
     * index > numItems and returns null
     */
    public E get(int index) {
       
        return null;
    }
    
    /**
     * Returns the number of items
     * in the Container
     * @return the number of items
     */
    public int length() {
        return 0;
    }
    
    /**Additional Operations*/
    
    /**
     * Resizes the container by making a new
     * array that has a length of
     * newCapacity
     * @param newCapacity the new length
     * of the array
     */
    @SuppressWarnings("unchecked")
    private void increaseCapacity(int newCapacity) {
       
    }
    
    /**
     * Searches for the specified item
     * in the Container
     * @param item the item to search for
     * @return the location (index) of the item
     */
    public int search(E item) {
       
        return -1;
    }
    
    /**
     * Determines if two Containers
     * store the same items in the
     * same order
     */
    @SuppressWarnings("unchecked")
    public boolean equals(Object o) {
        return false;
    }
    
    /**
     * Creates a String of all items
     * in the Container, separated by
     * a blank space, with a new line character
     * added to the end of the String
     */
    public String toString() {
        return "\n";
    }
}


  • Next, create a new file named ContainerTest.java and copy and paste the below test file into ContainerTest.java.
  • Your job is to write the above methods to pass the tests inside ContainerTest.java
  • Note that the output your Container.java file produces should match my sample output identically - including error messages - to receive full credit.
  • Please use the Javadoc comments as a guide when writing your methods.


ContainerTest.java File

/**
 * ContainerTest.java
 * @author parrishj
 * CIS 36B, Lab 8.1
 */
public class ContainerTest {
    public static void main(String[] args) {
       
        System.out.println("***Testing addStart***\n");
        Container<String> c1 = new Container<>();
        c1.addStart("A");
        c1.addStart("B");
        c1.addStart("C");
       
        System.out.println("Should print C B A: " + c1);
       
        System.out.println("\n***Testing addEnd***\n");
        c1.addEnd("D");
        c1.addEnd("E");
        System.out.println("Should print C B A D E: " + c1);
       
        System.out.println("\n***Testing add***\n");
        c1.add(1, "F");
        System.out.println("Should print C F B A D E: " + c1);
        c1.add(3, "Z");
        System.out.println("Should print C F B Z A D E: " + c1);
        System.out.println("Should print an error message: ");
        c1.add(-1, "A");
       
        System.out.println("\n***Testing increaseCapacity***\n");
        c1.addEnd("X");
        c1.addEnd("X");
        c1.addEnd("X");
        c1.addEnd("X");
        System.out.println("Should print C F B Z A D E X X X X: " + c1);
       
        System.out.println("\n***Testing length***\n");
        Container<Integer> c2 = new Container<>(5);
        System.out.println("Length of 0: " + c2.length());
        System.out.println("Length of 11: " + c1.length());
        c2.addEnd(1);
        c2.addEnd(2);
        c2.addEnd(3);
       
        System.out.println("\n***Testing copy constructor***\n");
        Container<Integer> c3 = new Container<>(c2);
        System.out.println("Original should be 1 2 3: " + c2);
        System.out.println("Copy should be 1 2 3: " + c3);
        Container<Double> c4 = new Container<>(null);
        System.out.println("Copy should be empty (nothing displayed): " + c4);
       
        System.out.println("\n***Testing for deep copy***\n");
        c3.addEnd(4);
        System.out.println("Original should be 1 2 3: " + c2);
        System.out.println("Copy should be 1 2 3 4: " + c3);
        System.out.println("Original length should be 3: " + c2.length());
        System.out.println("Copy length should be 4: " + c3.length());
       
        System.out.println("\n***Testing remove start***\n");
        c1.removeStart();
        System.out.println("Should print F B Z A D E X X X X: " + c1);
        System.out.println("Should print an error message: ");
        c4.removeStart();
       
        System.out.println("\n***Testing remove index***\n");
        c1.remove(1);
        System.out.println("Should print F Z A D E X X X X: " + c1);
        System.out.println("Should print an error message: ");
        c1.remove(-1);
       
        System.out.println("\n***Testing remove end***\n");
        c1.removeEnd();
        System.out.println("Should print F Z A D E X X X: " + c1);
        System.out.println("Should print an error message: ");
        c4.removeEnd();
       
        System.out.println("\n***Testing countOccurences***\n");
        System.out.println("Should print 3: " + c1.countOccurences("X"));
        System.out.println("Should print 0: " + c3.countOccurences(0));
       
        System.out.println("\n***Testing get***\n");
        System.out.println("Should print X: " + c1.get(5));
        System.out.println("Should print 1: " + c3.get(0));
        System.out.println("Should print an error: ");
        c3.get(-1);
       
        System.out.println("\n***Testing search***\n");
        System.out.println("Should print 5: " + c1.search("X"));
        System.out.println("Should print 1: " + c3.search(2));
       
        System.out.println("\n***Testing equals***\n");
        System.out.println("Should print false: " + c2.equals(c3));
        c3.remove(3);
        System.out.println("Should print true: " + c2.equals(c3));
        System.out.println("Should print false: " + c1.equals(c3));
       
        System.out.println("\n\n***End of Tests!***");
       
    }
}


Required Output:

***Testing addStart***

Should print C B A: C B A


***Testing addEnd***

Should print C B A D E: C B A D E


***Testing add***

Should print C F B A D E: C F B A D E

Should print C F B Z A D E: C F B Z A D E

Should print an error message:
Add error: index -1 is out of bounds.

***Testing increaseCapacity***

Should print C F B Z A D E X X X X: C F B Z A D E X X X X


***Testing length***

Length of 0: 0
Length of 11: 11

***Testing copy constructor***

Original should be 1 2 3: 1 2 3

Copy should be 1 2 3: 1 2 3

Copy should be empty (nothing displayed):


***Testing for deep copy***

Original should be 1 2 3: 1 2 3

Copy should be 1 2 3 4: 1 2 3 4

Original length should be 3: 3
Copy length should be 4: 4

***Testing remove start***

Should print F B Z A D E X X X X: F B Z A D E X X X X

Should print an error message:
RemoveStart error. Container is empty. Cannot remove

***Testing remove index***

Should print F Z A D E X X X X: F Z A D E X X X X

Should print an error message:
Remove error: index -1 is out of bounds.

***Testing remove end***

Should print F Z A D E X X X: F Z A D E X X X

Should print an error message:
RemoveEnd error. Container is empty. Cannot remove

***Testing countOccurences***

Should print 3: 3
Should print 0: 0

***Testing get***

Should print X: X
Should print 1: 1
Should print an error:
Get error: Index -1 is out of bounds

***Testing search***

Should print 5: 5
Should print 1: 1

***Testing equals***

Should print false: false
Should print true: true
Should print false: false


***End of Tests!***


What to Submit:

  • Submit your completed Container.java file (make sure your names are on the file) to Canvas.
  • Submit the pair programming worksheet to Canvas along with your Lab.
  • One partner submits Container.java and the pair programming contract.
    • The other other partner only submits the pair programming contract.

How You Will Be Graded:

  • You will receive 6.5 points for each correctly written method (15 methods)
  • -5 for any package statements - please remove package statements before submitting
  • -5 for missing pair programming contract
  • -5 for incorrect indentation. Please go to Source->Format to format your Container.java before submitting.



Pair Programming Required (Or No Credit)

  • Both partners fill in, sign, date, and submit the pair programming contract
  • Upload the document(s) along with your Lab to Canvas.
  • Only ONE partner submits the lab assignment on Canvas. Please make sure both your names are on the source file(s).


Lab 9.1: A Container Class with Exception Handling (100 pts)

due Thursday, June 6 at 11:59pm on Canvas
  • For this lab, we will updated our Container class to include exception handling.
  • Anywhere that we had previously written the method to print an error message to the console, we will now throw an exception instead.
  • For example, below is an updated version of the get method.
      /**
     * Returns the item stored at
     * the given index
     * @param index the index of the
     * item to return
     * @return a random item
     * @throws IndexOutOfBoundsException
     * if index < 0 or index > numItems

     */
    public E get(int index) throws IndexOutOfBoundsException {
        if (index < 0 || index > numItems) {
            throw new IndexOutOfBoundsException("Get error: Index " + index  + " is out of bounds.");
        }
        return array[index];
    }

  • Note the updates that have been made to this method (bolded above):
    • Javadoc comment rewritten to include the @throws tag
    • Method signature revised to indicate the method throws an exception
    • If statement now throws an exception rather than printing the error message to the console
  • You will need to follow a similar model for four additional methods.
  • Please see the bolded changes below to the starter code provided for the prior lab:

/**
 * Container.java
 * @author
 * @author
 * CIS 36B, Lab 9.1
 */

public class Container<E> {
    private int numItems;
    private E[] array;
   
    /**Constructors*/
   
    /**
     * Default constructor
     * Creates a new Container of length 10
     */
    @SuppressWarnings("unchecked")
    public Container() {
        numItems = 0;
        array = (E[]) new Object[10];
    }
   
    /**
     * Constructor for Container class
     * @param initialCapacity the initial
     * length of the Container
     * Creates a Container of length
     * initialCapacity
     */
    @SuppressWarnings("unchecked")
    public Container(int initialCapacity) {
       
    }
   
    /**
     * Copy constructor for Container class
     * @param c another Container
     * Creates a Container that is a
     * copy of c
     */
    @SuppressWarnings("unchecked")
    public Container(Container<E> c) {
       
    }
   
    /**Mutators*/
   
    /**
     * Shifts all items down to
     * Insert a new item at the start
     * of the Container
     * Calls increaseCapacity when the
     * adding a new item when
     * numItems == array.length
     * @param item a new item
     */
    public void addStart(E item) {
       
    }
   
    /**
     * Inserts a new item at the
     * end of the Container
     * @param item a new item
     * Calls increaseCapacity when the
     * adding a new item when
     * numItems == array.length
     */
    public void addEnd(E item) {
       
    }
   
    /**
     * Inserts a new item at the
     * specified index of the Container
     * @param index the index at which
     * to insert
     * @param item a new item
     * @throws IndexOutOfBoundsException
     * if index < 0 or index > numItems

     * Calls increaseCapacity when the
     * adding a new item when
     * numItems == array.length
     */
    public void add(int index, E item) throws IndexOutOfBoundsException {
       
    }
   
    /**
     * Removes the first element in the
     * container
     * @throws IllegalStateException
     * if the container is empty

     */
    public void removeStart() throws IllegalStateException {
       
    }
   
    /**
     * Removes the item at the specified index
     * @param index of the item to remove
     * @throws IndexOutOfBoundsException
     * if index < 0 or index > numItems

     */
    public void remove(int index) throws IndexOutOfBoundsException {
       
    }
   
    /**
     * Removes the last element in the
     * container
     * @throws IllegalStateException
     * if the container is empty

     */
    public void removeEnd() throws IllegalStateException {
       
       
    }
   
    /**Accessors*/
   
    /**
     * Counts the number of times
     * item appears in the container
     * @param item the item to search for
     * @return the number of times
     * item appears in the container
     */
    public int countOccurences(E item) {
        return -1;
    }
   
    /**
     * Returns the item stored at
     * the given index
     * @param index the index of the
     * item to return
     * @return a random item
     * @throws IndexOutOfBoundsException
     * if index < 0 or index > numItems

     */
    public E get(int index) throws IndexOutOfBoundsException {
        return null;
    }
   
    /**
     * Returns the number of items
     * in the Container
     * @return the number of items
     */
    public int length() {
        return -1;
    }
   
    /**Additional Operations*/
   
    /**
     * Resizes the container by making a new
     * array that has a length of
     * newCapacity
     * @param newCapacity the new length
     * of the array
     */
    @SuppressWarnings("unchecked")
    private void increaseCapacity(int newCapacity) {
       
    }
   
    /**
     * Searches for the specified item
     * in the Container
     * @param item the item to search for
     * @return the location (index) of the item
     */
    public int search(E item) {
       
        return -1;
    }
   
    /**
     * Determines if two Containers
     * store the same items in the
     * same order
     */
    @SuppressWarnings("unchecked")
    public boolean equals(Object o) {
        return false;
    }
   
    /**
     * Creates a String of all items
     * in the Container, separated by
     * a blank space, with a new line character
     * added to the end of the String
     */
    public String toString() {
        String result = "\n";
       
        return result;
    }
}

  • Please update your Lab 8.1 to incorporate the changes to the Javadoc comments and the method signatures.
  • Then, you will want to update the indicated methods to throw an exception rather than displaying an error message to the console.
  • Next, update your ContainerTest.java file to handle the exception by placing the method calls inside of a try-catch block.
  • Here is an example for the get method:
try {
    System.out.println("\n***Testing get***\n");
    System.out.println("Should print X: " + c1.get(5));
    System.out.println("Should print 1: " + c3.get(0));
    System.out.println("Should print an error: ");
    c3.get(-1);
} catch (IndexOutOfBoundsException e) {
System.out.println(e); //calling toString() on e
}
  • The above will produce the following output to the console:
***Testing get***

Should print X: X
Should print 1: 1
Should print an error:
java.lang.IndexOutOfBoundsException: Get error: Index -1 is out of bounds.
  • Copy and paste the below test program into your ContainerTest.java file from Lab 8, and place a try catch anywhere that the code is in bold (i.e. anywhere you had previously printed an error message):
/**
 * ContainerTest.java
 * @author parrishj
 * CIS 36B, Lab 9.1
 */
public class ContainerTest {
    public static void main(String[] args) {
       
        System.out.println("***Testing addStart***\n");
        Container<String> c1 = new Container<>();
        c1.addStart("A");
        c1.addStart("B");
        c1.addStart("C");
       
        System.out.println("Should print C B A: " + c1);
       
        System.out.println("\n***Testing addEnd***\n");
        c1.addEnd("D");
        c1.addEnd("E");
        System.out.println("Should print C B A D E: " + c1);
       
        System.out.println("\n***Testing add***\n");
        c1.add(1, "F");
        System.out.println("Should print C F B A D E: " + c1);
        c1.add(3, "Z");
        System.out.println("Should print C F B Z A D E: " + c1);
        System.out.println("Should print an error message: ");
        c1.add(-1, "A");

       
        System.out.println("\n***Testing increaseCapacity***\n");
        c1.addEnd("X");
        c1.addEnd("X");
        c1.addEnd("X");
        c1.addEnd("X");
        System.out.println("Should print C F B Z A D E X X X X: " + c1);
       
        System.out.println("\n***Testing length***\n");
        Container<Integer> c2 = new Container<>(5);
        System.out.println("Length of 0: " + c2.length());
        System.out.println("Length of 11: " + c1.length());
        c2.addEnd(1);
        c2.addEnd(2);
        c2.addEnd(3);
       
        System.out.println("\n***Testing copy constructor***\n");
        Container<Integer> c3 = new Container<>(c2);
        System.out.println("Original should be 1 2 3: " + c2);
        System.out.println("Copy should be 1 2 3: " + c3);
        Container<Double> c4 = new Container<>(null);
        System.out.println("Copy should be empty (nothing displayed): " + c4);
       
        System.out.println("\n***Testing for deep copy***\n");
        c3.addEnd(4);
        System.out.println("Original should be 1 2 3: " + c2);
        System.out.println("Copy should be 1 2 3 4: " + c3);
        System.out.println("Original length should be 3: " + c2.length());
        System.out.println("Copy length should be 4: " + c3.length());
       
        System.out.println("\n***Testing remove start***\n");
        c1.removeStart();
        System.out.println("Should print F B Z A D E X X X X: " + c1);
        System.out.println("Should print an error message: ");
        c4.removeStart();

       
        System.out.println("\n***Testing remove index***\n");
        c1.remove(1);
        System.out.println("Should print F Z A D E X X X X: " + c1);
        System.out.println("Should print an error message: ");
        c1.remove(-1);

       
        System.out.println("\n***Testing remove end***\n");
        c1.removeEnd();
        System.out.println("Should print F Z A D E X X X: " + c1);
        System.out.println("Should print an error message: ");
        c4.removeEnd();

       
        System.out.println("\n***Testing countOccurences***\n");
        System.out.println("Should print 3: " + c1.countOccurences("X"));
        System.out.println("Should print 0: " + c3.countOccurences(0));
       
        System.out.println("\n***Testing get***\n");
        System.out.println("Should print X: " + c1.get(5));
        System.out.println("Should print 1: " + c3.get(0));
        System.out.println("Should print an error: ");
        c3.get(-1);

       
        System.out.println("\n***Testing search***\n");
        System.out.println("Should print 5: " + c1.search("X"));
        System.out.println("Should print 1: " + c3.search(2));
       
        System.out.println("\n***Testing equals***\n");
        System.out.println("Should print false: " + c2.equals(c3));
        c3.remove(3);
        System.out.println("Should print true: " + c2.equals(c3));
        System.out.println("Should print false: " + c1.equals(c3));
       
        System.out.println("\n\n***End of Tests!***");
       
    }
}

  • Your test file should now give the following output:
***Testing addStart***

Should print C B A: C B A


***Testing addEnd***

Should print C B A D E: C B A D E


***Testing add***

Should print C F B A D E: C F B A D E

Should print C F B Z A D E: C F B Z A D E

Should print an error message:
java.lang.IndexOutOfBoundsException: Add error: index -1 is out of bounds.


***Testing increaseCapacity***

Should print C F B Z A D E X X X X: C F B Z A D E X X X X


***Testing length***

Length of 0: 0
Length of 11: 11

***Testing copy constructor***

Original should be 1 2 3: 1 2 3

Copy should be 1 2 3: 1 2 3

Copy should be empty (nothing displayed):


***Testing for deep copy***

Original should be 1 2 3: 1 2 3

Copy should be 1 2 3 4: 1 2 3 4

Original length should be 3: 3
Copy length should be 4: 4

***Testing remove start***

Should print F B Z A D E X X X X: F B Z A D E X X X X

Should print an error message:
java.lang.IllegalStateException: RemoveStart error. Container is empty. Cannot remove.

***Testing remove index***

Should print F Z A D E X X X X: F Z A D E X X X X

Should print an error message:
java.lang.IndexOutOfBoundsException: Remove error: index -1 is out of bounds.


***Testing remove end***

Should print F Z A D E X X X: F Z A D E X X X

Should print an error message:
java.lang.IllegalStateException: RemoveEnd error. Container is empty. Cannot remove
.

***Testing countOccurences***

Should print 3: 3
Should print 0: 0

***Testing get***

Should print X: X
Should print 1: 1
Should print an error:
java.lang.IndexOutOfBoundsException: Get error: Index -1 is out of bounds
.

***Testing search***

Should print 5: 5
Should print 1: 1

***Testing equals***

Should print false: false
Should print true: true
Should print false: false


***End of Tests!***
  • When your Container.java and ContainerTest.java produce the results as shown, please upload both Container.java and ContainerTest.java to Canvas.
  • Only one partner needs to submit the two files, but both partner should upload the pair programming contract.

How You Will Be Graded:

  • Each updated method and its associated test in ContainerTest.java is worth 20 points
  • 5 point deduction for missing pair programming contract
  • 5 point deduction for not removing package statements from the top of your files
  • 5 point deduction for code that has not been properly formatted - please go to Source->Format in Eclipse to format your code before submitting.


Lab 9.2: Project Proposal (100 pts)

due Monday, June 10 at 9:20am on Canvas
  • Complete this Project Proposal along with your project teammates
  • Please consult the course project directions as you are deciding on a topic
  • Note that ALL teammates should submit the Project Proposal to Canvas
    • 5 point deduction if you do not submit the Project Proposal but another teammate does submit it
    • No credit if no teammates submit the proposal

Part 2: List Array Class (100 pts)
due Monday, May 6 at 9:20am on Canvas

  • This lab will give you a peek under the hood of the ArrayList class, by asking you to write your own version of ArrayList called ListArray.
  • Note that we will not be able to make our ListArray class store data of any Object type.
    • Later this quarter, we will learn about generics, which will allow us to alter our classes to store all Object types
    • For now, we will only store Strings in our ListArray.
  • Copy and paste the following starter code into a new class file called ListArray.java
/**
 * ListArray.java
 * @author
 * @author
 * CIS 36B
 */

public class ListArray {
    private String[] array;
    private int numElements;
   
    /**Constructors*/
   
    /**
     * Default constructor for ListArray
     * Creates an empty array of length 10
     * Sets numElements to 0
     */
    public ListArray() {
     
    }
   
    /**
     * Constructor for ListArray
     * Creates an empty array of length size
     * Sets numElements to 0
     * @param size the initial size of the
     * ListArray
     */
    public ListArray(int size) {
    
    }
   
    /**
     * Copy constructor for ListArray
     * Creates a new list array of the
     * same size as the ListArray passed
     * in as a parameter, and copies the
     * parameter's data into the new
     * list array using a for loop
     * Also sets the numElements to be
     * the same as the parameter's
     * numElements
     * @param la the ListArray to copy
     */
 
    public ListArray(ListArray la) {
       
    }
   
    /**Accessor Methods*/
   
    /**
     * Returns whether the list array is
     * currently empty
     * @return whether the list array is
     * empty
     */
    public boolean isEmpty() {
        return false;
    }
   
    /**
     * Returns the current number of
     * elements stored in the list
     * array
     * @return the number of elements
     */
    public int size() {
        return -1;
    }
   
    /**
     * Returns the element at the specified
     * index. Prints an error message and
     * returns an empty String if index is
     * larger than or equal to numElements
     * @param index the index of the element
     * to access
     * @return the element at index
     */
    public String get(int index) {
        return null;
    }
   
    /**
     * Uses the linearSearch algorithm to
     * locate an element in the list array
     * @param str the element to locate
     * @return whether or not the element
     * is in the list array
     */
    public boolean contains(String str) {
        return false;
    }
   
    /**
     * Uses the linearSearch algorithm to
     * locate an element in the list array
     * @param str the element to locate
     * @return the location of the element
     * or -1 if the element is not in the
     * list array
     */
    public int indexOf(String str) {
        return -1;
    }
   
    /**
     * Determines whether the list array
     * is currently full
     * @return whether the list array
     * is at maximum capacity
     */
    private boolean atCapacity() {
        return false;
    }
   
    /**Mutator Methods*/
   
    /**
     * Resizes the list array by
     * and assigning a new length
     * to your array. Hint: call new
     * 10 larger than the current array's
     * length (capacity)
     */
    private void reSize() {
       
    }
   
    /**
     * Inserts a new element to the end
     * of the list array.
     * Resizes the list array if it is
     * at capacity before inserting
     * @param str the element to insert
     */
    public void add(String str) {
     
    }
   
    /**
     * Inserts a new element at the specified
     * index in the list array.
     * Resizes the list array if it is
     * at capacity before inserting
     * @param index the index at which to insert
     * @param str the element to insert
     */
    public void add(int index, String str) {
      
    }
   
    /**
     * Assigns a new value to the list array
     * at a specified index
     * @param index the index at which to update
     * @param str the new element
     */
    public void set(int index, String str) {
      
    }
   
    /**
     * Removes an element at a specified index in
     * the list array
     * @param index the index at which to remove
     * @return the element that was removed
     */
    public String remove(int index) {
        return null;
    }
   
    /**
     * Removes the first instance of the specified
     * element in the list array
     * @param str the element to remove
     * @return whether the element was successfully
     * removed
     */
    public boolean remove(String str) {
        return false;   
    }   
    /**Additional Methods*/
   
    /**
     * Creates a String of all elements,
     * with [] around the elements,
     * each element separated from the next
     * with a comma
     */
    @Override public String toString() {
        return null;
    }
}
  • It is your job to implement all of the above methods.
  • Read the Javadoc comment carefully for each method to get a good understanding of what that method is supposed to do.
  • Note that most of these methods are defined identically to those in the ArrayList class. Only a few have been tweaked by me.
  • **Before** you write your methods, also copy and paste the below starter code into a class file called ListArrayTest.java, which should be located inside of the same project folder at ListArray.java
  • As you write each of the methods, comment in the tests for the method and run the tests to ensure your method is working properly.
  • Note that you should test your methods as you go along. Do not write all of your code before you try to test the methods.
  • Your workflow should be:
  1. Write a method
  2. Uncomment the tests for that method
  3. Run the tests for that method
  4. Update your method as needed so that you get the correct output
  5. Repeat 1 - 4 with the next method
  • Below is the ListArrayTest.java file. Note that to aid you in the above process, I am providing the file mostly commented out.
/**
 * ListArrayTest.java
 * @author
 * @author
 * CIS 36B
 */

public class ListArrayTest {
    public static void main(String[] args) {
        System.out.println("***Testing Default Constructor and One Parameter Constructor***\n");
        ListArray test1 = new ListArray();
/*       
        System.out.println("After default constructor called:");
        System.out.println("Should print size of 0: "
                + test1.size());
        System.out.println("Should print the list array is empty - true: "
                + test1.isEmpty());
        System.out.println("Should print []: " + test1);
       
        ListArray test2 = new ListArray(15);
        System.out.println("\nAfter one parameter constructor called:");
        System.out.println("\nShould print size of 0: "
                + test2.size());
        System.out.println("Should print the list array is empty - true: "
                + test2.isEmpty());
        System.out.println("Should print []: " + test2);
       
        System.out.println("\n***Testing Add Methods***\n");
        test1.add("B");
        System.out.println("Adding B: ");
        System.out.println("Should print size of 1: "
                + test1.size());
        System.out.println("Should print the list array is empty - false: "
                + test1.isEmpty());
        System.out.println("Should print B at index 0: "
                + test1.get(0));
        System.out.println("Should print [B]: " + test1);
       
        test1.add("D");
        System.out.println("\nAdding D: ");
        System.out.println("Should print size of 2: "
                + test1.size());
        System.out.println("Should print the list array is empty - false: "
                + test1.isEmpty());
        System.out.println("Should print B at index 0: "
                + test1.get(0));
        System.out.println("Should print D at index 1: "
                + test1.get(1));
        System.out.println("Should print [B, D]: "
                + test1);
       
        System.out.println("\nShould print error message. Cannot add at index 10:");
        test1.add(10, "A");
   
        test1.add(0, "A");
        System.out.println("\nAdding A at index 0: ");
        System.out.println("Should print size of 3: "
                + test1.size());
        System.out.println("Should print the list array is empty - false: "
                + test1.isEmpty());
        System.out.println("Should print A at index 0: "
                + test1.get(0));
        System.out.println("Should print B at index 1: "
                + test1.get(1));
        System.out.println("Should print [A, B, D]: " + test1);
       
        test1.add(2, "C");
        System.out.println("\nAdding C at index 2: ");
        System.out.println("Should print size of 4: "
                + test1.size());
        System.out.println("Should print the list array is empty - false: "
                + test1.isEmpty());
        System.out.println("Should print A at index 0: "
                + test1.get(0));
        System.out.println("Should print C at index 2: "
                + test1.get(2));
        System.out.println("Should print [A, B, C, D]: " + test1);
       
        System.out.println("\nAdding 1-20 in ListArray of size 15. Should resize to 20:");
        for(int i = 1; i <= 20; i++) {
            test2.add("" + i);
        }
        System.out.println("Should print size of 20: "
                + test2.size());
        System.out.println("Should print the list array is empty - false: "
                + test2.isEmpty());
        System.out.println("Should print 1 at index 0: "
                + test2.get(0));
        System.out.println("Should print 20 at index 19: "
                + test2.get(19));
       
        System.out.println("\n***Testing Copy Constructor***\n");
        ListArray test3 = new ListArray(test1);
        System.out.println("Should print size of 4: "
                + test1.size());
        System.out.println("Should print the list array is empty - false: "
                + test3.isEmpty());
        System.out.println("Should print A at index 0: "
                + test3.get(0));
        System.out.println("Should print C at index 2: "
                + test3.get(2));
        System.out.println("Should print [A, B, C, D]: " + test3);
       
        System.out.println("\nTesting for deep copy: ");
        test3.add("A");
        test3.add("B");
        test3.add("C");
        System.out.println("Original list array size should be 4: "
                + test1.size());
        System.out.println("New list array size should be 7: "
                + test3.size());
        System.out.println("Printing original [A, B, C, D]: " + test1);
        System.out.println("Printing new [A, B, C, D, A, B, C]: " + test3);
       
        System.out.println("\n***Testing Set Method***\n");
        System.out.println("Should print error message when setting index 6: ");
        test1.set(6, "Z");
       
        test1.set(2, "Z");
        System.out.println("\nShould print size of 4: "
                + test1.size());
        System.out.println("Should print the list array is empty - false: "
                + test1.isEmpty());
        System.out.println("Should print A at index 0: "
                + test1.get(0));
        System.out.println("Should print Z at index 2: "
                + test1.get(2));
        System.out.println("Should print [A, B, Z, D]: " + test1);
       
        test1.set(0, "Z");
        System.out.println("\nShould print size of 4: "
                + test1.size());
        System.out.println("Should print the list array is empty - false: "
                + test1.isEmpty());
        System.out.println("Should print Z at index 0: "
                + test1.get(0));
        System.out.println("Should print Z at index 2: "
                + test1.get(2));
        System.out.println("Should print [Z, B, Z, D]: " + test1);
       
        System.out.println("\n***Testing Remove Methods***\n");
       
        System.out.println("Remove index 3, element D: "
                + test3.remove(3));
        System.out.println("Should print size of 6: "
                + test3.size());
        System.out.println("Should print the list array is empty - false: "
                + test3.isEmpty());
        System.out.println("Should print A at index 0: "
                + test3.get(0));
        System.out.println("Should print A at index 3: "
                + test3.get(3));
        System.out.println("Should print [A, B, C, A, B, C]: " + test3);
       
        System.out.println("\nRemove index 0, element A: "
                + test3.remove(0));
        System.out.println("Should print size of 5: "
                + test3.size());
        System.out.println("Should print the list array is empty - false: "
                + test3.isEmpty());
        System.out.println("Should print B at index 0: "
                + test3.get(0));
        System.out.println("Should print B at index 3: "
                + test3.get(3));
        System.out.println("Should print [B, C, A, B, C]: " + test3);
       
        System.out.println("\nRemove index 10, should print error message: ");
        test3.remove(10);
        System.out.println("Should print size of 5: "
                + test3.size());
        System.out.println("Should print the list array is empty - false: "
                + test3.isEmpty());
        System.out.println("Should print B at index 0: "
                + test3.get(0));
        System.out.println("Should print B at index 3: "
                + test3.get(3));
        System.out.println("Should print [B, C, A, B, C]: " + test3);
       
        System.out.println("\nRemove index of size - 1 (last element) C: "
                + test3.remove(test3.size() - 1));
        System.out.println("Should print size of 4: "
                + test3.size());
        System.out.println("Should print the list array is empty - false: "
                + test3.isEmpty());
        System.out.println("Should print B at index 0: "
                + test3.get(0));
        System.out.println("Should print B at index size - 1: "
                + test3.get(test3.size() - 1));
        System.out.println("Should print [B, C, A, B]: " + test3);
       
        System.out.println("\nCan remove B (first instance): "
                + test3.remove("B"));
        System.out.println("Should print size of 3: "
                + test3.size());
        System.out.println("Should print the list array is empty - false: "
                + test3.isEmpty());
        System.out.println("Should print C at index 0: "
                + test3.get(0));
        System.out.println("Should print B at index size - 1: "
                + test3.get(test3.size() - 1));
        System.out.println("Should print [C, A, B]: " + test3);
       
        System.out.println("\nCan remove B (only instance): "
                + test3.remove("B"));
        System.out.println("Should print size of 2: "
                + test3.size());
        System.out.println("Should print the list array is empty - false: "
                + test3.isEmpty());
        System.out.println("Should print C at index 0: "
                + test3.get(0));
        System.out.println("Should print A at index size - 1: "
                + test3.get(test3.size() - 1));
        System.out.println("Should print [C, A]: " + test3);
       
        System.out.println("\nShould print error message: ");
        System.out.println("Cannot remove Z (not stored): "
                + test3.remove("Z"));
        System.out.println("Should print size of 2: "
                + test3.size());
        System.out.println("Should print the list array is empty - false: "
                + test3.isEmpty());
        System.out.println("Should print C at index 0: "
                + test3.get(0));
        System.out.println("Should print A at index size - 1: "
                + test3.get(test3.size() - 1));
        System.out.println("Should print [C, A]: " + test3);
       
        test3.remove("C");
        System.out.println("\nRemove C:");
        System.out.println("Should print size of 1: "
                + test3.size());
        System.out.println("Should print the list array is empty - false: "
                    + test3.isEmpty());
        System.out.println("Should print A at index 1: "
                        + test3.get(0));
        System.out.println("Should print A at index size - 1: "
                        + test3.get(test3.size() - 1));
        System.out.println("Should print [A]: " + test3);
       
        test3.remove("A");
        System.out.println("\nRemove A:");
        System.out.println("Should print size of 0: "
                + test3.size());
        System.out.println("Should print the list array is empty - true: "
                + test3.isEmpty());
        System.out.println("Should print []: " + test3);
       
        System.out.println("\n***Testing Size Method***\n");
        System.out.println("Should print size of 0: "
                + test3.size());
        System.out.println("Should print size of 20: "
                + test2.size());
        System.out.println("Should print size of 4: "
                + test1.size());
       
        System.out.println("\n***Testing IsEmpty Method***\n");
        System.out.println("Should print true: "
                + test3.isEmpty());
        System.out.println("Should print false: "
                + test2.isEmpty());
        System.out.println("Should print false: "
                + test1.isEmpty());
       
        System.out.println("\n***Testing Contains Method***\n");
        System.out.println("Contains Z, should print true: "
                + test1.contains("Z"));
        System.out.println("Contains D, should print true: "
                + test1.contains("D"));
        System.out.println("Contains A, should print false: "
                + test1.contains("A"));
       
        System.out.println("\n***Testing IndexOf Method***\n");
        System.out.println("Index of Z, should print 0: "
                + test1.indexOf("Z"));
        System.out.println("Index of D, should print 3: "
                + test1.indexOf("D"));
        System.out.println("Index of A, should print -1: "
                + test1.indexOf("A"));
       
        System.out.println("\n***Testing Get Method***\n");
        System.out.println("Element at 0, should print Z: "
                + test1.get(0));
        System.out.println("Element at 3, should print D: "
                + test1.get(3));
        System.out.println("Element at 6, should print error message: ");
        test1.get(6);
        */
    }
}

  • Note that you will need to write the default constructor, followed by size(), followed by isEmpty(), followed by the toString() method as your first four methods in order to be able to use this test file properly.
  • Next, you should move onto the one argument constructor, followed by the add() methods, etc.
  • Below is the output that you should get when you run your complete ListArray.java file with the ListArrayTest.java file I have provided.
  • Note that your output should be ***identical*** including the wording of the error messages that get displayed.
  • When your output is identical, submit your ListArray.java file to Canvas.
Output of ListArrayTest.java

***Testing Default Constructor and One Parameter Constructor***

After default constructor called:
Should print size of 0: 0
Should print the list array is empty - true: true
Should print []: []

After one parameter constructor called:

Should print size of 0: 0
Should print the list array is empty - true: true
Should print []: []

***Testing Add Methods***

Adding B:
Should print size of 1: 1
Should print the list array is empty - false: false
Should print B at index 0: B
Should print [B]: [B]

Adding D:
Should print size of 2: 2
Should print the list array is empty - false: false
Should print B at index 0: B
Should print D at index 1: D
Should print [B, D]: [B, D]

Should print error message. Cannot add at index 10:
Error: Cannot add element A at index 10.
Index is outside the bounds of the list array.
Index: 10, Size: 2

Adding A at index 0:
Should print size of 3: 3
Should print the list array is empty - false: false
Should print A at index 0: A
Should print B at index 1: B
Should print [A, B, D]: [A, B, D]

Adding C at index 2:
Should print size of 4: 4
Should print the list array is empty - false: false
Should print A at index 0: A
Should print C at index 2: C
Should print [A, B, C, D]: [A, B, C, D]

Adding 1-20 in ListArray of size 15. Should resize to 20:
Should print size of 20: 20
Should print the list array is empty - false: false
Should print 1 at index 0: 1
Should print 20 at index 19: 20

***Testing Copy Constructor***

Should print size of 4: 4
Should print the list array is empty - false: false
Should print A at index 0: A
Should print C at index 2: C
Should print [A, B, C, D]: [A, B, C, D]

Testing for deep copy:
Original list array size should be 4: 4
New list array size should be 7: 7
Printing original [A, B, C, D]: [A, B, C, D]
Printing new [A, B, C, D, A, B, C]: [A, B, C, D, A, B, C]

***Testing Set Method***

Should print error message when setting index 6:
Error: Cannot set at index outside bounds of list array.
Index: 6 , Size: 4

Should print size of 4: 4
Should print the list array is empty - false: false
Should print A at index 0: A
Should print Z at index 2: Z
Should print [A, B, Z, D]: [A, B, Z, D]

Should print size of 4: 4
Should print the list array is empty - false: false
Should print Z at index 0: Z
Should print Z at index 2: Z
Should print [Z, B, Z, D]: [Z, B, Z, D]

***Testing Remove Methods***

Remove index 3, element D: D
Should print size of 6: 6
Should print the list array is empty - false: false
Should print A at index 0: A
Should print A at index 3: A
Should print [A, B, C, A, B, C]: [A, B, C, A, B, C]

Remove index 0, element A: A
Should print size of 5: 5
Should print the list array is empty - false: false
Should print B at index 0: B
Should print B at index 3: B
Should print [B, C, A, B, C]: [B, C, A, B, C]

Remove index 10, should print error message:
Error: Cannot remove element at index 10.
Index is outside bounds of list array.
Should print size of 5: 5
Should print the list array is empty - false: false
Should print B at index 0: B
Should print B at index 3: B
Should print [B, C, A, B, C]: [B, C, A, B, C]

Remove index of size - 1 (last element) C: C
Should print size of 4: 4
Should print the list array is empty - false: false
Should print B at index 0: B
Should print B at index size - 1: B
Should print [B, C, A, B]: [B, C, A, B]

Can remove B (first instance): true
Should print size of 3: 3
Should print the list array is empty - false: false
Should print C at index 0: C
Should print B at index size - 1: B
Should print [C, A, B]: [C, A, B]

Can remove B (only instance): true
Should print size of 2: 2
Should print the list array is empty - false: false
Should print C at index 0: C
Should print A at index size - 1: A
Should print [C, A]: [C, A]

Should print error message:
Error: Cannot remove element Z.
No such element in the list array.
Cannot remove Z (not stored): false
Should print size of 2: 2
Should print the list array is empty - false: false
Should print C at index 0: C
Should print A at index size - 1: A
Should print [C, A]: [C, A]

Remove C:
Should print size of 1: 1
Should print the list array is empty - false: false
Should print A at index 1: A
Should print A at index size - 1: A
Should print [A]: [A]

Remove A:
Should print size of 0: 0
Should print the list array is empty - true: true
Should print []: []

***Testing Size Method***

Should print size of 0: 0
Should print size of 20: 20
Should print size of 4: 4

***Testing IsEmpty Method***

Should print true: true
Should print false: false
Should print false: false

***Testing Contains Method***

Contains Z, should print true: true
Contains D, should print true: true
Contains A, should print false: false

***Testing IndexOf Method***

Index of Z, should print 0: 0
Index of D, should print 3: 3
Index of A, should print -1: -1

***Testing Get Method***

Element at 0, should print Z: Z
Element at 3, should print D: D
Element at 6, should print error message:
Error: Cannot get element at index 6.
Outside bounds of list array.
Index: 6, Size: 4

What to Submit:

  • Submit your completed ListArray.java file (make sure your name(s) are on both files) to Canvas.
  • Submit the pair programming worksheet to Canvas along with your Lab.
  • One partner submits ListArray.java and the pair programming contract.
    • The other other partner only submits the pair programming contract.

How You Will Be Graded:

  • You will receive 6.25 points for each correctly written method (16 methods)
    • The test file output for each method must match the above output *exactly* to receive full credit - including the wording of your error messages.
  • You will receive a 5 point deduction for not submitting the pair programming contract
  • You will receive a 10 point deduction for improperly formatted code
  • You will receive a 5 point deduction for any package statements - please remove the package statements before submitting

TEXTING TRANSLATOR

  • For this assignment, we are going to work with adding and removing data from arrays, linear search, and File I/O.

  • This program will act as a texting to English converter

  • This program will read a file containing a list of abbreviations used in texting and another file with their English translations. 

  • The abbreviations and translations need to be stored in two separate but parallel arrays.

  • In other words, the indices of the abbreviations array will match the indices of the translations array.

  • Thus the abbreviation at index 0, will match the translation at index 0, etc

  • Open up two new text files inside of Eclipse:

  • Name these text files abbreviations.txt and translations.txt

  • Copy and paste the following list of names into your abbreviations.txt file:


4
cu
ikr
k
l8
l8r
lmk
m8
nvm
r
smh
u
ur
wu
  • Copy and paste the following list of translations into your translations.txt file:


for
see you
I know right?
okay
late
later
let me know
mate
never mind
are
shaking my head
you
you are
what's up?
  • Read the contents of each file and store them in a separate arrays, one array called abbrevations and one array called translations.

  • You should declare arrays of length 150, and separately store information about the current number of values stored inside of the two arrays.

  • Hint: you can use a variable to count how many values are in each file as you are reading in the data, and use this information to save the number of values currently stored in each array.

  • Next, you will need to write a menu-driven program to allow the user to complete 3 tasks:

    • Add an Abbreviation

    • Remove an Abbreviation

    • Search for a Translation

    • Exit

  • For the add menu option, the program should do the following:

    • Prompt the user for an abbreviation and its transation to insert, and a position in the arrays at which to insert.

    • Call the insert method twice to insert the name and score into the respective arrays at the indicated position (index).

  • For the remove menu option, the program should do the following:

    • Prompt the user for the abbreviation to remove.

    • Next, call linearSearch to determine at which index in the array the abbreviation is placed

    • Confirm that it has located the correct abbreviation in the array by verifying the user wishes to remove the abbreviation.

    • Finally, call the remove method to remove both the abbreviation from the abbreviations array and the translation from the translations array

  • For the search for a translation menu option, the program should do the following:

    • Prompt the user for the abbreviation.

    • Next, call linearSearch to determine at which index in the array the abbreviation is placed

    • Print the translation that is located at that same index.

  • For the exit menu option, the program should do the following:

    • Prompt the user to enter the name of a file in which to print the abbreviations and translations

    • call the printFile method passing in the name of the indicated file

  • To begin, copy and paste the starter code into a file called TextTrans.java

  • Make sure that you implement and call all of the methods whose signatures are specified below

  • Note that you made add any additional methods that you like to complete the program

  • When your program is working correctly, upload it to Canvas.


Starter Code

/**

* @author

* @author

* CIS 36B

*/

import java.util.Scanner;

import java.io.File;

import java.io.IOException;

import java.io.PrintWriter;


public class TextTrans {

   

    public static void main(String[] args) throws IOException {

     

        Scanner input = new Scanner(System.in);

        System.out.println("Welcome to the Texting Translator!");


        System.out.println("\nGoodbye!");    

    }


   

    /**

     * Inserts a String element into an array at a specified index

     * @param array the list of String values

     * @param numElements the current number of elements stored

     * @indexToInsert the location in the array to insert the new element

     * @param newValue the new String value to insert in the array

     */

  

    public static void insert(String array[], int numElements,

            int indexToInsert, String newValue) {

     

    }

   

    /**

     * Removes a String element from an array at a specified index

     * @param array the list of String values

     * @param numElements the current number of elements stored

     * @param indexToRemove where in the array to remove the element

     */

   

    public static void remove(String array[], int numElements, int indexToRemove) {

        return;

    }


    /**

     * Print an array of Strings either to the console

     * or a file

     * @param names the list of abbreviations

     * @param translations the list of corresponding translations

     * @param numElements the current number of elements stored

     * @param file the file name

     */

    public static void printFile(String[] abbreviations, String[] translations,

            int numElements, String file) throws IOException {

        return;

    }

   

   /**

    * Searches for a specified String in a list

    * @param array the array of Strings

    * @param value the String to serach for

    * @param numElements the number of elements in the list

    * @return the index where value is located in the array

    */

   public static int linearSearch(String array[], String value, int numElements) {

      return -1;

   }


}



Sample Output


Welcome to the Texting Translator!

Below are the texting abbreviations:

0. 4
1. cu
2. ikr
3. k
4. l8
5. l8r
6. lmk
7. m8
8. nvm
9. r
10. smh
11. u
12. ur
13. wu

Please enter a menu option (A, R, S, X) below:

A. Add an Abbreviation
R. Remove an Abbreviation
S. Search for a Translation
X. Exit

Please enter your choice: A

Enter the abbreviation: rofl
Enter the position at which to add rofl: 10
Enter the translation of rofl: rolling on the floor laughing


Below are the texting abbreviations:

0. 4
1. cu
2. ikr
3. k
4. l8
5. l8r
6. lmk
7. m8
8. nvm
9. r
10. rofl
11. smh
12. u
13. ur
14. wu

Please enter a menu option (A, R, S, X) below:

A. Add an Abbreviation
R. Remove an Abbreviation
S. Search for a Translation
X. Exit

Please enter your choice: R

Please enter the abbreviation to remove: l8

Removing l8...
Is this correct (y/n): y

l8 has been removed.

Below are the texting abbreviations:

0. 4
1. cu
2. ikr
3. k
4. l8r
5. lmk
6. m8
7. nvm
8. r
9. rofl
10. smh
11. u
12. ur
13. wu

Please enter a menu option (A, R, S, X) below:

A. Add an Abbreviation
R. Remove an Abbreviation
S. Search for a Translation
X. Exit

Please enter your choice: S

Enter the abbreviation: u

The abbreviation "u" means: you

Below are the texting abbreviations:

0. 4
1. cu
2. ikr
3. k
4. l8r
5. lmk
6. m8
7. nvm
8. r
9. rofl
10. smh
11. u
12. ur
13. wu

Please enter a menu option (A, R, S, X) below:

A. Add an Abbreviation
R. Remove an Abbreviation
S. Search for a Translation
X. Exit

Please enter your choice: X

Enter the name of a file to write your abbreviations: output.txt

Goodbye!

Contents of corresponding output file (output.txt in my example - but user should specify the name):

0. 4: for

1. cu: see you

2. ikr: I know right?

3. k: okay

4. l8r: later

5. lmk: let me know

6. m8: mate

7. nvm: never mind

8. r: are

9. rofl: rolling on the floor laughing

10. smh: shaking my head

11. u: you

12. ur: you are

13. wu: what's up?

  • Note that the user should be able to enter any file name of their choice. It does not have to be output.txt.

  • Note that no error checking is required. You may assume that the user enters the inputs correctly.

What to Submit:

  • Submit your completed TextTrans.java file (make sure both your names are on the file) to Canvas.
  • One partner submits TextTrans.java. Both partners submit the pair programming contract.
    • 5 point deduction for missing contract
  • Please use the default package or remove any package statements from the top of your files before submission (5 point deduction)
  • Please do not submit your work as a zip file (5 point deduction)

How You Will Be Graded:

  • 100 points: The assignment works as shown in the sample output. All required features are implemented and implemented correctly.
  • 80-100 points: The assignment works mostly as shown in the sample output. Most required features are implemented and implemented correctly. Wording or spacing choices may differ from those shown
  • 40-80 points: Some of the assignment works as shown in the sample output. Some required features are implemented and implemented correctly.
  • 10-40 points: Serious problems in implementation and little correspondence between sample output and what is shown. Few of the features implemented or implemented correctly.
  • 0 points: Code does not compile or outputs an error at runtime.
Comments