Question: pls help me use java to do this 2048 program. testphase2.java is here public class TestA2Phase2 { //Test the simple constructor, the toString method, and

pls help me use java to do this 2048 program.pls help me use java to do this 2048 program.testphase2.java is herepublic class TestA2Phase2 { //Test the simple constructor, the toString method, andthe shift method //The others are tested indirectly by these. public statictestphase2.java is here

public class TestA2Phase2 { //Test the simple constructor, the toString method, and the shift method //The others are tested indirectly by these. public static void main(String[] args) { //Start with the same test board. Board2048 test = new Board2048(new int[][]{{2,0,2,4},{0,0,0,8},{2,2,2,2},{0,8,0,8}}); //Store the results of each shift in separate variables Board2048 test2,test3,test4,test5; //Test the constructor and also toString System.out.println("Blank 5x5 board: "+new Board2048(5)); System.out.println("Blank 2x2 board: "+new Board2048(2)); System.out.println("Test board is: "+test); //Test shift in all 4 directions System.out.println("After shifting LEFT: "+(test2=test.shift(Board2048.LEFT))); System.out.println("THEN shifting RIGHT: "+(test3=test2.shift(Board2048.RIGHT))); System.out.println("THEN shifting DOWN: "+(test4=test3.shift(Board2048.DOWN))); System.out.println("THEN shifting UP: "+(test5=test4.shift(Board2048.UP))); //Make sure the original remains untouched System.out.println("Original board should not have changed: "+test); } }

this is testphase 1 , but i have not done it , which is called shift one line.

import java.util.Arrays;

public class TestA2Phase1 { //Test only the alterOneLine method in Phase 1 of Assignment 2. //The test inputs to be run through the alterOneLine method private static int[][] testCases = { {0,2,0,0,8,0,4}, {0,0,0,0,8,2,4}, {2,4,2,0,0,0,0}, {2,0,2,4,0,0,4}, {2,0,4,2,0,0,4}, {2,0,2,2,0}, {2,0,2,2,0,2}, {2,0,2,4,0,8} };

public static void main(String[] args) { //run all the tests 1 time for(int i=0; i runTest(testCases[i],1); //except the last one, which is run 4 times. runTest(testCases[testCases.length-1],4); }//main private static void runTest(int[] testCase, int nTimes){ //Run nTimes tests on the given testCase for(int i=0; i System.out.print("testing "+Arrays.toString(testCase)+" "); boolean result = Board2048.alterOneLine(testCase); System.out.println("gives "+result+" and "+Arrays.toString(testCase)); }//for }//runTest }//TestPhase1 class

https://www.chegg.com/homework-help/questions-and-answers/pls-help-java-thx-muchtestphase1-testphase1-import-javautilarrays-public-class-testa2phase-q26776409 I have post a new one, pls answer it here.

Phase 2: Shift The Board Now modify the Board2048 object so that it will hold a 2-dimensional grid of tiles, which can be shifted in any direction. 1) Add instance variables to the Board2048 class so that a Board2048 object will contain a square grid of int values of any size. (The number of rows must always be equal to the number of columns.) Add public static final int constants UP, DOWN, LEFT, and RIGHT to represent the four possible directions. It doesn't matter what values you use to represent them Provide a constructor with one int parameter that specifies the desired size of the grid. (The normal game is played on a 4x4 grid but your program should handle any size.) The grid will always be square. The grid should initially be blank (all O's). 2) 3) Provide a second constructor with one int[1[1 parameter that specifies a particular grid of values to be used. You may assume that the supplied array will be square, but it may be any size. The values in the grid may be any numbers, not only powers of 2. 4) 5) Write a standard tostring method which will return a multi-line String representation of the grid. Use tab characters (\t) between the columns and newline ( ) characters between the rows. Use a '.' for a blank space. Page 2 of5

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!