Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I got errors import java.awt.Color; import java.awt.Graphics; public class SimpleBotView { private Color robot; private Color wall; private Color Robot; private Color trail; private DrawingPanel

I got errors

import java.awt.Color; import java.awt.Graphics; public class SimpleBotView { private Color robot; private Color wall; private Color Robot; private Color trail; private DrawingPanel dp; private Color background; private int size; private int r; private int c; private char[][] initial; private void drawPanel() { // Initializing the graphics object Graphics g = dp.getGraphics(); // This for loop is used to chose the shape of the object present in te initial array // Initial is a 2D matrix for(int i=0 ; i for(int j=0; j // Switch case is used to perform operations based on the value of initial element switch( initial[i][j] ) { // This block is executed if initial element is w case 'w': // Setting color of the graphics object which is stored in wall g.setColor( wall ); // Filling a rectangle with x-cordinate, y-coordinate, width and height respectively as arguments g.fillRect(j*size, i*size, size, size); break; // This block is executed if initial element is t case 't': // Setting color of the graphics object which is stored in trail g.setColor( trail ); // Filling a rectangle with x-cordinate, y-coordinate, width and height respectively as arguments g.fillRect(j*size, i*size, size, size); break; // This block is executed if initial element is r case 'r': // Setting color of the graphics object which is stored in robot g.setColor( robot ); // Filling a rectangle with x-cordinate, y-coordinate, width and height respectively as arguments g.fillRect(j*size, i*size, size, size); break; // This block is executed if initial element is b case 'b': // Setting color of the graphics object which is stored in background g.setColor( background ); // Filling a rectangle with x-cordinate, y-coordinate, width and height respectively as arguments g.fillRect(j*size, i*size, size, size); break; } } } } // Constructor triggered to initalize variables private SimpleBotView(char[][] initial, Color robot, Color wall, Color trail, Color background, int size) { this.initial = initial; this.robot = robot; this.wall = wall; this.trail = trail; this.background = background; this.size = size; // Assign the length of the initial matrix to r which is the no of rows r = initial.length; // Assign the length of the initial matrix of first row to c which is the no of columns c = initial[0].length; // initializing the drawing panel with width = r*size and height = c*size dp = new DrawingPanel(r*size, c*size); // Displaying the drawing panel dp.setVisible(true); // Calling the method drawPanel(); } // Method used to move the shapes private void move(char direction) { // Iterating over the complete drawing panel for(int j=0 ; j for(int i=0 ; i // If the matrix value is r if( initial[j][i] == 'r' ) { // If the director is up switch( direction ) { case 'u': // If the x coordinate greater than 0 and matix value is not equal to w if( i - 1 > 0 && initial[i-1][j] != 'w' ) { initial[j][i] = 't'; initial[j-1][i] = 'r'; } break; // If the director is down case 'd': // If the x coordinate less than row value and matix value is not equal to w if( j + 1 < r && initial[j+1][i] != 'w' ) { initial[j][i] = 't'; initial[j+1][i] = 'r'; } break; // If the director is left case 'l': // If the x coordinate greater than 0 and matix value is not equal to w if( i - 1 > 0 && initial[j][i-1] != 'w' ) { initial[j][i] = 't'; initial[j][i-1] = 'r'; } break; // If the director is right case 'r': // If the y coordinate less than column value and matix value is not equal to w if( j + 1 < c && initial[i][j+1] != 'w' ) { initial[i][j] = 't'; initial[i][j+1] = 'r'; } break; } break; } } } drawPanel(); } }

import java.awt.Color; public class SimpleBotViewTester { public static void main(String[] args) { char[][] init = {{'w', 'w', 'w', 'w'}, {'b', 'b', 'b', 'b'}, {'r', 'b', 'b', 'b'}}; int sleep = 100; SimpleBotView view = new SimpleBotView(init, Color.GREEN, Color.ORANGE, Color.PINK, Color.YELLOW, 100); try { Thread.sleep(sleep); } catch(Exception e) { } view.move('u'); try { Thread.sleep(sleep); } catch(Exception e) { } view.move('u'); try { Thread.sleep(sleep); } catch(Exception e) { } view.move('r'); try { Thread.sleep(sleep); } catch(Exception e) { } view.move('r'); try { Thread.sleep(sleep); } catch(Exception e) { } view.move('r'); try { Thread.sleep(sleep); } catch(Exception e) { } view.move('d'); try { Thread.sleep(sleep); } catch(Exception e) { } view.move('d'); try { Thread.sleep(sleep); } catch(Exception e) { } view.move('l'); try { Thread.sleep(sleep); } catch(Exception e) { } view.move('l'); try { Thread.sleep(sleep); } catch(Exception e) { } view.move('l'); } }

SimpleBotViewTester.java:14: error: SimpleBotView(char[][],Color,Color,Color,Color,int) has private access in SimpleBotView SimpleBotView view = new SimpleBotView(init, Color.ORANGE, ^ SimpleBotViewTester.java:17: error: move(char) has private access in SimpleBotView view.move('u'); ^ SimpleBotViewTester.java:19: error: move(char) has private access in SimpleBotView view.move('l'); ^ SimpleBotViewTester.java:21: error: move(char) has private access in SimpleBotView view.move('d'); ^ SimpleBotViewTester.java:23: error: move(char) has private access in SimpleBotView view.move('d'); ^ SimpleBotViewTester.java:25: error: move(char) has private access in SimpleBotView view.move('d'); ^ SimpleBotViewTester.java:27: error: move(char) has private access in SimpleBotView view.move('d'); ^ SimpleBotViewTester.java:29: error: move(char) has private access in SimpleBotView view.move('r'); ^ SimpleBotViewTester.java:31: error: move(char) has private access in SimpleBotView view.move('r'); ^ SimpleBotViewTester.java:33: error: move(char) has private access in SimpleBotView view.move('r'); ^ 10 errors

how i can fix?

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Programming The Perl DBI Database Programming With Perl

Authors: Tim Bunce, Alligator Descartes

1st Edition

1565926994, 978-1565926998

More Books

Students also viewed these Databases questions

Question

Did the team members feel that their work mattered

Answered: 1 week ago

Question

3. What may be the goal of the team?

Answered: 1 week ago