I need to implement two classes for my java project.

hello, I have already implemented most of my project I just need to implement two classes. The two classes CombineLeftRight and CombineTopBottom are explained in detail at javadoc


the question: Overview

For this project you will implement classes that support displaying and animating diagrams similar to the ones you developed for the DrawingApp project. The video Sample Video illustrates some of the functionality that will be supported by the classes you need to implement. The program we executed for this video is GraphicalExampleDriver.java (part of the system package).

After reading this description, import the code example DiagramSystemLabExample.zip and go over the README file you will find along with the code distribution. This code provides an example of what you need to do for this project. 

Make sure you submit often so a backup is created in the submit server.

Grading

  • (65%) Release Tests
  • (15%) Secret Tests
  • (6%) Style
  • (14%) Student Tests

Code Distribution

The project's code distribution is available at DiagramSystem.zip. Download it and import it as you have imported our class examples. The code distribution provides you with the following:

  • app â†’ A package (folder) where you will place your implementation for the DrawingApp project. Make sure you fix any problems associated with the DrawingApp project. Notice that just because you got a 100 in the DrawingApp project, it does not mean it is bug-free. The secret and release tests for this project could find some of these bugs.
  • gui â†’ A package (folder) providing code that supports the graphical display and animation of a diagram. You will use the methods provided by the GraphicalUtilities.java class. Do not modify anything in this package.
  • system â†’ A package (folder) where you will implement the classes associated with this project.
  • tests â†’ A package (folder) where you will find a file called StudentTests.java were you are expected to write tests for your program.

Specifications

You need to implement the classes that are part of the system package (except GraphicalDriverExample.java). A description of the classes can be found at javadoc. You need to start with the TwoDimArrayUtil class (other classes depend on it) and continue with the HorizontalBars.java, VerticalBars.java and Flag.java classes. You can leave for last the CombineLeftRight.java and CombineTopBottom.java classes.

You can finish this project without ever running the Graphical utility methods that allow you to display a diagram graphically or that allow you to animate a diagram. If you provide the expected functionality for the classes in the system package, the graphical component will work as expected. You can run a Graphical demo by executing the GraphicalDriverExample.java class. Feel free to update that file with your own diagrams.

Before you start implementing this project, you need to copy to the app package the DrawingApp.java class you developed. Make sure you fix any problems that might exist with your code.

For style we will be focusing on the following items:

  • Good variable names and indentation
  • Avoid code duplication when possible.

Student Tests

Test your code as you develop it, by writing tests in the StudentTests.java file. Make sure your JUnit tests rely on assertions, otherwise you will lose credit. We expect to see at least one test for each of the public methods of classes you need to implement. Methods in the TestingSupport class can help you write tests (although you are not required to use them). You may not be able to get help during office hours unless you have student tests.

Keep in mind we grade the submission that scores the highest in the submit server after public/release/secret tests have been executed, without taking into consideration the points you may get for student tests.

Requirements

  • Verify that your project passes the submit server tests (https://submit.cs.umd.edu/). Your score on the project will be based on results from the submit server.
  • You can release test your project any time, but for this project you have 3 tokens in a 24-hour period.
  • Do not use System.exit(0) in your programs.
  • For your code to compile in the submit server, you need to provide all the classes and the methods (or shells of them) you are expected to implement. You can make methods compile (even though you may not have implemented them) by adding the following statement

  • throw new UnsupportedOperationException("Not implemented");
  • If the parameter to the isRagged method is null, the method will throw an IllegalArgumentException. Any error message is fine.
  • You don't need to re-implement the DrawingApp class. You will use the class you developed for Project #3. That class will generate the basic diagrams (e.g., Flag) for you.
  • It is OK to use code you see in Sample Driver section.
  • You may not use ArrayLists or any other Collection class (e.g., maps) for this project. If you do, you will lose most of the points for the project.
  • You don't need to write student tests for the DrawingApp class.


Here are the classes already implemented:


Drawing App: package app;


import java.util.Random;


public class DrawingApp {



private static boolean isValidColor(char color) {


if (color == 'R' || color == 'G' || color == 'B' || color == 'Y' || color == '*' || color == '.') {


return true;


} else {


return false;


}


}


public static String getRectangle(int maxRows, int maxCols, char symbol) {


if (maxRows < 1 || maxCols < 1) {


return "";


} else {


String answer = "";


for (int i = 1; i <= maxRows; i++) {


for (int h = 1; h <= maxCols; h++) {


answer = answer + symbol;


}


if (i < maxRows) {


answer += "\n";


}


}


return answer;


}


}


public static void main(String args[]) {


DrawingApp.getHorizontalBars(12, 10, 3, 'R', 'G', 'B');


DrawingApp.getHorizontalBars(12, 10, 4, '*', '.', 'Y');


String bar2 = DrawingApp.getHorizontalBars(12, 10, 4, '*', '.', 'Y');


System.out.println(bar2);


String bar3 = DrawingApp.getHorizontalBars(12, 10, 5, '*', '.', 'Y');


System.out.println(bar3);


}


public static char getRandomColor(Random random) {


int color = random.nextInt(6);


if (color == 0) {


return 'R';


} else if (color == 1) {


return 'G';


} else if (color == 2) {


return 'B';


} else if (color == 3) {


return 'Y';


} else if (color == 4) {


return '*';


} else {


return '.';


}


}


public static String getHorizontalBars(int maxRows, int maxCols, int bars, char color1, char color2, char color3) {


int bars2 = maxRows / bars;


if (bars2 < 1 || color1 == ' ' || color2 == ' ' || color3 == ' ') {


return null;


}


String result = "";


for (int i = 0; i < bars; i++) {


for (int h = 0; h < bars2; h++) {


for (int k = 0; k < maxCols; k++) {


if (i % 3 == 0) {


result += color1;


} else if (i % 3 == 1) {


result += color2;


} else {


result += color3;


}


}


result += "\n";


}


}


return result.trim();


}


public static String getFlag(int size, char color1, char color2, char color3) {


if (size < 3) {


return null;


}


int numRows = size * 2;


int numCols = size * 5;


int rowCounter = 1;


String flag = "";


int flagWidth = 1;


while (rowCounter <= numRows) {


if (rowCounter <= size) {


for (int i = 0; i < flagWidth; i++) {


flag += color1;


}


for (int i = 0; i < numCols - flagWidth; i++) {


if (rowCounter == 1 || rowCounter == numRows || rowCounter == size || rowCounter == size + 1) {


flag += color2;


} else {


flag += color3;


}


}


flagWidth++;


flag += "\n";


} else if (rowCounter >= size) {


for (int i = 1; i < flagWidth; i++) {


flag += color1;


}


for (int i = 0; i < numCols - flagWidth + 1; i++) {


if (rowCounter == 1 || rowCounter == numRows || rowCounter == size || rowCounter == size + 1) {


flag += color2;


} else {


flag += color3;


}


}


flagWidth--;


flag += "\n";


}


rowCounter++;


}


return flag.trim();


}


public static String getVerticalBars(int maxRows, int maxCols, int bars, char color1, char color2, char color3) {


int vbars = maxCols / bars;


String str = "";


String result = "";


if (vbars < 1 || color1 == ' ' || color2 == ' ' || color3 == ' ') {


return null;


}


for (int i = 0; i <= bars;) {


for (int j = 0; j < vbars; j++) {


str += color1;


}


i++;


if (i == bars)


break;


for (int j = 0; j < vbars; j++) {


str += color2;


}


i++;


if (i == bars)


break;


for (int j = 0; j < vbars; j++) {


str += color3;


}


i++;


if (i == bars)


break;


}


str += '\n';


for (int i = 0; i < maxRows; i++) {


result += str;


}


return result.trim();


}


}


Diagram Class:


package system;


/**

 * Interface implemented by any class representing a Diagram. A diagram

 * is defined by a two-dimensional array of characters (board), where each character

 * represents a color.  Colors: Red ('R'), Green ('G'), Blue ('B'), Yellow ('Y'),

 * Black ('*'), White ('.').

 * 

 * @author cmsc132

 *

 */

public interface Diagram {

/**

* Returns a two-dimensional array of characters representing a diagram.

* @return

*/

public char[][] getBoard();

/**

* Returns the next two-dimensional array of characters to display during

* an animation.

* @return

*/

public char[][] nextAnimationStep();

/**

* Number of rows associated with the diagram.

* @return

*/

public int getNumberRows();

/**

* Number of columns associated with the diagram.

* @return

*/

public int getNumberCols();

}


Flag Class:


package system;


import app.DrawingApp;


public class Flag implements Diagram {

private int animationType;

    private char[][] board;


    public Flag(int size, char color1, char color2, char color3, int animationType) {

      

        this.animationType = animationType;

        String bar = DrawingApp.getFlag(size, color1, color2, color3);


        String[] displayBars = bar.split("\n");

        int row = displayBars.length;

        int col = displayBars[0].length();

        board = new char[row][col];


        for (int i = 0 ; i < row ; i++ ) {

            board[i] = displayBars[i].toCharArray();

        }

      


    }



  

    public char[][] getBoard(){

        return board;

    }

    public char[][] nextAnimationStep() {

        if ( animationType == 1) {

            TwoDimArrayUtil.rotateLeftOneColumn(board);

        }

        if ( animationType == 2) {

            TwoDimArrayUtil.rotateTopOneRow(board);

        }

        return board;

    }



    public int getNumberRows(){

        if ( board != null) {

        return board.length;

        }

        return 0;

    }


    public int getNumberCols() {

        if ( board != null) {

        return board[0].length;

        }

        return 0;

    }

}


Graphical Driver Example:


package system;

import javax.swing.JOptionPane;


import gui.*;


/**

 * Sample driver illustrating the displaying and animation of

 * diagrams.

 * 

 * @author cmsc132

 *

 */

public class GraphicalDriverExample {

public static void main(String[] args) {

char color1 = 'R', color2 = '.', color3 = 'Y';

int size = 9, animationType = 1;

/* Controls size of squares (cells) */

int cellDimensions = 15;

int animationSpeedInMilliSecs = 100;

/* Initializing display unit */

GraphicalUtilities.initDisplayUnit("Display", cellDimensions);

/* Flag example */

Flag flag = new Flag(size, color1, color2, color3, animationType);

/* Displaying flag */

GraphicalUtilities.displayDiagram(flag);

/* Animating flag */

JOptionPane.showMessageDialog(null, "Press OK to start animation");

GraphicalUtilities.animate(flag, animationSpeedInMilliSecs);

/* Horizontal bars example */

int maxRows = 12, maxCols = 10, bars = 2;

        color1 = 'R'; color2 = 'G'; color3 = 'B';

        animationType = 1;

HorizontalBars horizontalBars = new HorizontalBars(maxRows, maxCols, bars, 

color1, color2, color3, animationType);

/* Displaying bars */

GraphicalUtilities.displayDiagram(horizontalBars);

/* Animating bars */

JOptionPane.showMessageDialog(null, "Press OK to start animation");

GraphicalUtilities.animate(horizontalBars, animationSpeedInMilliSecs);

/* Vertical bars example */

maxRows = 12; maxCols = 10; bars = 2;

        color1 = 'R'; color2 = 'G'; color3 = 'B';

        animationType = 1;

VerticalBars verticalBars = new VerticalBars(maxRows, maxCols, bars, 

color1, color2, color3, animationType);

/* Displaying bars */

GraphicalUtilities.displayDiagram(verticalBars);

/* Animating bars */

JOptionPane.showMessageDialog(null, "Press OK to start animation");

GraphicalUtilities.animate(verticalBars, animationSpeedInMilliSecs);

/* Combining left and right */

horizontalBars = new HorizontalBars(maxRows, maxCols, bars, 

color1, color2, color3, animationType);

verticalBars = new VerticalBars(maxRows, maxCols, bars, 

  color1, color2, color3, animationType);

Diagram combined = new CombineLeftRight(horizontalBars, verticalBars, 1);

/* Displaying combined */

GraphicalUtilities.displayDiagram(combined);

/* Animating combined */

JOptionPane.showMessageDialog(null, "Press OK to start animation");

GraphicalUtilities.animate(combined, animationSpeedInMilliSecs);

/* Combining top and bottom */

horizontalBars = new HorizontalBars(maxRows, maxCols, bars, 

color1, color2, color3, animationType);

verticalBars = new VerticalBars(maxRows, maxCols, bars, 

  color1, color2, color3, animationType);

combined = new CombineTopBottom(horizontalBars, verticalBars, 1);

/* Displaying combined */

GraphicalUtilities.displayDiagram(combined);

/* Animating combined */

JOptionPane.showMessageDialog(null, "Press OK to start animation");

GraphicalUtilities.animate(combined, animationSpeedInMilliSecs);

System.exit(0);

}

}


Horizontal Bars Class:


package system;


import app.DrawingApp;


public class HorizontalBars implements Diagram {

private int animationType;

private char[][] board;

    public HorizontalBars(int maxRows, int maxCols, int bars, char color1, char color2, char color3, int animationType) {

      

        String bar = DrawingApp.getHorizontalBars(maxRows, maxCols, bars, color1, color2, color3);


        String[] displayBars = bar.split("\n");

        int row = displayBars.length;

        int col = displayBars[0].length();

        board = new char[row][col];


        for (int i = 0 ; i < row ; i++ ) {

            board[i] = displayBars[i].toCharArray();

        }

      


    }



  

    public char[][] getBoard(){

        return board;

    }

    public char[][] nextAnimationStep() {

        if (animationType == 1) {

            TwoDimArrayUtil.rotateTopOneRow(board);

        }

        return board;

    }



    public int getNumberRows(){

        if ( board != null) {

        return board.length;

        }

        return 0;

    }


    public int getNumberCols() {

        if ( board != null) {

        return board[0].length;

        }

        return 0;

    }}

}

}


TwoDimArray Class:


package system;


import java.util.Arrays;


public class TwoDimArrayUtil {


public static boolean isRagged(char[][] array) {

        return false;

    }


    public static void rotateTopOneRow(char[][] array) {

      

        for ( int col = 0 ; col < array[0].length ; col++ ) {

            char tmp = array[0][col] ;

            for( int row = 0 ; row < array.length -1 ; row++ ) {

                array[row][col] = array[row+1][col];

            }

            array[array.length -1][col] = tmp;

        }


    }

    public static void rotateLeftOneColumn(char[][] array){

      

        for ( int row = 0 ; row < array.length ; row++ ) {

            char tmp = array[row][0] ;

            for( int col = 0 ; col < array[0].length -1 ; col++ ) {

                array[row][col] = array[row][col+1];

            }

            array[row][array[0].length -1] = tmp;

        }

      

        TwoDimArrayUtil.toString(array);

    }


    public static void toString(char[][] array ){

        for(int i =0 ; i< array.length ; i++){

            System.out.println( " --> " + Arrays.toString(array[i]));

        }

    }


    public static void copyArray( char[][] array1 , char[][] array2 , int row , int col ) {


        for( int i = 0 ; i < array2.length ; i++ ) {

            for ( int j = 0 ; j < array2[0].length ; j++ ) {

                array1[row + i][col + j ] = array2[i][j];

            }


        }


    }


    public static char[][] appendTopBottom(char[][] top, char[][] bottom) {

        int numRows = top.length + bottom.length;

        int numCols = (top[0].length > bottom[0].length) ? top[0].length : bottom[0].length;

        System.out.println(" Rows " + numRows + " Cols " + numCols );

        char[][] retArray = new char[numRows][numCols] ;


        TwoDimArrayUtil.copyArray(retArray,top, 0,0);

        TwoDimArrayUtil.copyArray(retArray,bottom, top.length,0);


     

        return retArray;

    }


    public static char[][] appendLeftRight(char[][] left, char[][] right) {


        int numRows = (left.length > right.length )? left.length : right.length;

        int numCols = left[0].length + right[0].length;

        char[][] retArray = new char[numRows][numCols] ;


        TwoDimArrayUtil.copyArray(retArray,left, 0,0);

        TwoDimArrayUtil.copyArray(retArray,right, 0,left[0].length);

        return retArray;

    }




}

}


Vertical Bars class:


package system;


import app.DrawingApp;


public class VerticalBars implements Diagram {

private int animationType;

    private char[][] board;


    public VerticalBars(int maxRows, int maxCols, int bars, char color1, char color2, char color3, int animationType) {

  

        this.animationType = animationType;


        String bar = DrawingApp.getVerticalBars(maxRows, maxCols, bars, color1, color2, color3);


        String[] displayBars = bar.split("\n");

        int row = displayBars.length;

        int col = displayBars[0].length();

        board = new char[row][col];


        for (int i = 0 ; i < row ; i++ ) {

            board[i] = displayBars[i].toCharArray();

        }

      


    }


    public char[][] getBoard(){

        return board;

    }


    public char[][] nextAnimationStep() {

        if ( animationType == 1) {

            TwoDimArrayUtil.rotateLeftOneColumn(board);

        }

        return board;

    }



    public int getNumberRows(){

        if ( board != null) {

        return board.length;

        }

        return 0;

    }


    public int getNumberCols() {

        if ( board != null) {

        return board[0].length;

        }

        return 0;

    }

}

Get Help With a similar task to - I need to implement two classes for my java project.

Login to view and/or buy answers.. or post an answer

Related Questions

Similar orders to I need to implement two classes for my java project.
5
Views
0
Answers
Creating a DNS server (written in C)
WANT >=50% due to being swamped (only standard option minimal, don't care about cache or non-blocking). I require periodic updates of code with a description as there is a Git commit tracking. Also require a makefile according to the specifications and a g...
20
Views
0
Answers
Create inheritance project for a restaurant
Projects must include: -at least three different levels of inheritance - at least nine classes total -the highest superclass must have at least two methods -every subclass must contain a unique method that was not present in its super...
16
Views
0
Answers
Python Code for Suggesting Pets
Must have ___init___ ; ___str___ ; for loops ; while loops ; and must define a function which returns something, I wrote down what idea I had in that form so its best to follow it, this is an entry-level computer science project so it should be pretty easy...
22
Views
0
Answers
Quick HW Computer Science on LL(1) and object creation
Due at 12:00pm today. The question details are in the files attached. One question is on the impact of a parser being LL(1) or not. Another is on imagining a mistake in object creation. The answers are probably max 2 lines long....