Let us worry about your assignment instead!

We Helped With This JAVA Programming Assignment: Have A Similar One?

SOLVED
CategoryProgramming
SubjectJAVA
DifficultyCollege
StatusSolved
More InfoHomework Help Java
190111

Short Assignment Requirements

I need a java program that prints the desired output. I am able to do that but struggling with the required things/requirements. I have attached the pdf file and the incomplete eclipse java files below.

Assignment Code



/**
 * A shape of a rectangle that can be drawn in its <code>Panel2D parentPanel</code>.
 * 
 * @author Unknown
 */
public class Box {
	private Panel2D parentPanel;
	private Point2D topLeft, bottomRight;
	private char stroke;

	/**
	* Create an instance of a rectangle shape.
	* 
	* @param x1 
	*   Horizontal position of the top-left corner.
	* @param y1 
	*   Vertical position of the top-left corner.
	* @param x2 
	*   Horizontal position of the bottom-right corner.
	* @param y2 
	*   Vertical position of the bottom-right corner.
	* @param stroke 
	*   The character used to draw the rectangle.
	*/
	Box(int x1, int y1, int x2, int y2, char stroke) {
		topLeft = new Point2D(x1, y1);
		bottomRight = new Point2D(x2, y2);
		this.stroke = stroke;
	}

	/**
	* Set the <code>parentPanel</code> to draw inside for later.
	* 
	* @param parentPanel
	*   An instance of a <code>Panel2D</code> to be used for drawing inside later.
	*/
	void setParent(Panel2D parentPanel) {
		this.parentPanel = parentPanel;
	}

	/**
	* Draws the rectangle shape in the <code>parentPanel</code>.
	*/
	void draw() {
		Point2D topRight = new Point2D(bottomRight.x, topLeft.y);
		Point2D bottomLeft = new Point2D(topLeft.x, bottomRight.y);

		parentPanel.drawLine(topLeft, topRight, stroke);
		parentPanel.drawLine(topRight, bottomRight, stroke);
		parentPanel.drawLine(bottomRight, bottomLeft, stroke);
		parentPanel.drawLine(bottomLeft, topLeft, stroke);
	}
}

Assignment Code


import java.util.ArrayList;

/**
 * Replace with more description.
 * 
 * @author YOUR NAME HERE
 */
public class Console {
	private final static char[] COLOURS = {' ', '.', '-', '=', '+', '*', '#'};
	
	/**
	 * Program execution starts here. Replace with more description.
	 * 
	 * @param args 
	 *   An array of Strings that we can use to pass data into our program when it runs.
	 */
	public static void main(String[] args) {
		
		Panel2D panel = new Panel2D();
		panel.display();
		
		System.out.println(); // blank line
	}
}

Assignment Code


import java.util.Arrays;

/**
 * We could have many different instances of 2D char arrays that could
 * display different graphics we design. This class encapsulates (hides) 
 * the confusion of working with the 2D char array directly elsewhere 
 * in our program. 
 * 
 * @author Unknown
 */
public class Panel2D {
	public final static int WIDTH = 80;
	public final static int HEIGHT = 30;
	private char fill = '`';
	private char[][] panel;

	Panel2D() {
		panel = new char[HEIGHT][WIDTH];
		clear();
	}
	
	/**
	 * This will fill the 2D char array with backtick <code>`</code>
	 * characters (usually under the tilde <code>~</code> in the 
	 * top-left corner of a keyboard).
	 */
	void clear() {
		// every character in the screen is set to a default char
		for (int i = 0; i < panel.length; i++) {
			Arrays.fill(panel[i], fill);
		}
	}

	/**
	 * This method swaps the order of the <code>x</code> and 
	 * <code>y</code> values for us (so we don't have to swap them
	 * everywhere else in our code) when we want access to the
	 * characters stored in the <code>panel</code> 2D char array. 
	 * 
	 * @param x 
	 *   The horizontal position inside the 2D char array.
	 * @param y 
	 *   The vertical position inside the 2D char array.
	 * @return
	 *   The character stored at position <code>(x, y)</code> in
	 *   the <code>panel</code> 2D char array.
	 */
	char get(int x, int y) {
		return panel[y][x];
	}
	
	/**
	 * Similar to the <code>get</code> method, but assign a char
	 * value to an <code>x</code> and <code>y</code> position in 
	 * the <code>panel</code> 2D char array.
	 * 
	 * @param x 
	 *   The horizontal position inside the 2D char array.
	 * @param y 
	 *   The vertical position inside the 2D char array.
	 * @param c 
	 *   The character to be stored in the <code>panel</code> 2D char array.
	 */
	void set(int x, int y, char c) {
		// check if the point is outside the screen boundaries
		if (0 <= x && x < WIDTH && 0 <= y && y < HEIGHT)
			panel[y][x] = c;
	}
	
	/**
	 * Actually print the <code>panel</code> 2D char array to output.
	 */
	void display() {
		// different from shown during explanations; this executes much faster
		StringBuilder output = new StringBuilder("");
		for (int y = HEIGHT - 1; y >= 0; y--) {
			output.append(panel[y]); // append an entire row of the 2D array
			output.append('
'); // finish the line for this row
		}
		System.out.print(output);
	}
	
	/**
	 * Avoids using floating-point arithmetic for a faster drawing of a line.
	 * Feel free to ask me about the math and why it works.
	 * 
	 * @param first 
	 *   The start position of the straight line.
	 * @param second 
	 *   The end position of the straight line.
	 * @param stroke 
	 *   The character used to draw the line.
	 */
	void drawLine(Point2D first, Point2D second, char stroke) {

		// Bresenham's Line Algorithm
		int x1 = first.x;
		int y1 = first.y;
		int x2 = second.x;
		int y2 = second.y;
		byte stepx, stepy;

		int dx = x2 - x1;
		int dy = y2 - y1;

		// Simplify keeping track of distance by removing direction (sign)
		// from the amount of changes in position for each step.
		// Let the direction be taken care of with step variables.
		if (dy < 0) { dy = -dy; stepy = -1; } else { stepy = 1; }
		if (dx < 0) { dx = -dx; stepx = -1; } else { stepx = 1; }
		dy <<= 1; // dy is now 2*dy
		dx <<= 1; // dx is now 2*dx
		set(x1, y1, stroke);

		// the algorithm is simplified by ensuring slope m is always -1 < m < 1
		if (dx > dy) {
			int error = dy - (dx >> 1);
			while (x1 != x2) {
				x1 += stepx;
				error += dy;
				if (error >= 0) {
					y1 += stepy;
					error -= dx;
				}
				set(x1, y1, stroke);
			}
		} else { // but this means we may have to swap roles of dy and dx
			int error = dx - (dy >> 1);
			while (y1 != y2) {
				y1 += stepy;
				error += dx;
				if (error >= 0) {
					x1 += stepx;
					error -= dy;
				}
				set(x1, y1, stroke);
			}
		}
	} // end of drawLine method
}

Assignment Code



/**
 * A coordinate point in the 2D plane.
 * 
 * @author Unknown
 */
public class Point2D {
	public int x = 0;
	public int y = 0;
	
	/**
	 * A simple constructor for creating instances of a coordinate point in 2D space.
	 *
	 * @param x
	 *   The horizontal position of this coordinate.
	 * @param y
	 *   The vertical position of this coordinate.
	 */
	Point2D(int x, int y) {
		this.x = x;
		this.y = y;
	}
}

Assignment Code


/**
 * This class helps you generate random integers. It is a version that will
 * generate each possible value with approximately equal probability.
 * 
 * @author Unknown
 */
public class Random {
	// Variable count makes sure generated values are different when
	// the processor executes calls quickly within the same millisecond.
	private static int count = 0;
	
	/**
	 * This class (static) method generates a pseudorandom integer in the range [0, max).
	 * 
	 * @param max
	 *   The strict upper bound for possible integers that will be generated.
	 * 
	 * @return
	 *   The generated pseudorandom integer.
	 */
	public static int rand(int max) {
		final int PRIME_1 = 2113; // different primes will change the random behaviour
		final int PRIME_2 = 7369; // its generally better to use larger primes
		long time = System.currentTimeMillis() % 1000000;
		long seed = time + count;
		double trig = Math.sin(PRIME_1 * seed + PRIME_2); // value between -1 and 1
		double func = Math.abs(PRIME_1 * trig); // make it positive and larger
		double frac = func - Math.floor(func); // digits past the decimal seem random
		count++;
		return (int) (frac * max); // get an integer in our range [0, max)
	}
}

Assignment Description

 

 

|Assignment #2|

 

Objectives

 

1.  work with multiple classes

2.  use collections from java.util package

3.  pass arguments into parameters

4.  practice using loops, and enhanced for-loops

 

 

It is fundamental to continue practice working with objects:

       Be patient with yourself. Read *all* the instructions once before starting.

 

       A Panel2D object instance is able to store, modify, and print a 2D char array:

            { it is by default filled with backticks ` (below the _ character at the top-left of most keyboards)             { this way a fresh Panel2D can at least output something

 

       Be mindful of starting a job with programming. It could mean you have to learn a whole library of classes you have never seen before-written by previous programmers at the company.

 

 

Use Javadoc to document your work. Use doc comments to describe each class, and each method in the class. Keep it simple, and only use the @author, @param, @return tags. To keep it organized, compile your documentation web pages into a doc folder within your Assignment2 folder.

 

Many doc comments are already written, and you will find it useful to generate the documentation to help yourself as you work. Also, you will use the one command needed to generate Javadoc for the midterm, so make yourself comfortable with it now.

 

Having a concise UML of classes can be helpful:

 

What you need to do:

 

1.  create a class called MySprite that uses a 5 by 5 int array to design a small bitmap image:

  _ store 0 in the 2D array to not draw a char at this spot

  _ store 1 in the 2D array to draw a char at this spot

  _ store a Point2D coordinate for the bottom-left corner position of where to draw the 5 by 5 image

  _ make it draw copies in a Panel2D called parentPanel

  _ pass a char colour" from COLOURS to the MySprite constructor (like the stroke of Box)

  _ store a String message in each instance of MySprite you create

  _ use a Box instance to draw a box around the message printed to a Panel2D with one character      padding between the message and the box

  _ use a Fill instance (see below) to blank out the background of the message box

 

2.  write doc comments for your MySprite class and its methods

 

3.  create a class called Fill:

   _ it should draw a _lled rectangle in a Panel2D (do not use the Box class)

   _ each char inside the rectangle must be assigned some stroke char

   _ use an instance of Fill to draw a large background behind your MySprite instances and their        box messages (the example output uses a period '.' to _ll)

 

4.  write doc comments for your Fill class and its methods

 

5.  use the Fill and Random classes to design a frame around the edges of your _nal Panel2D drawing    _ choose random COLOURS to _ll

   _ use Fill instances in a pattern around the border near the edges of a Panel2D

   _ the Fill instances may be spaced to give you more freedom in your design

   _ there should be a clear pattern, with placement controlled by simple calculations

   _ there is enough choice here that your design is expected to be unique

 

6.  write doc comments for the Console class and any methods you write for it All instance variables of MySprite and Fill classes should be private.

 

For now, all methods in your classes should be public. If you only use them inside the class itself, then they can be private.

 

An example of what your finished output could look like is on the next page.

 

An example of what output could look like for your work:

 

 

--__ __ __##__**__..__==__++__**__##__**__..__##__ __--__++__++__**__**__++++

--__ __ __##__**__..__==__++__**__##__**__..__##__ __--__++__++__**__**__++++

________________________________________________________________________________

(do NOT try to make your output look exactly like this)

 

Work on parts of this code one at a time, and do not try to write all your code at once. A suggested order (compile, run, and debug after each):      _ get a MySprite instance to display on a Panel2D

     _ add code to the MySprite draw method to output its instance message nearby in the Panel2D

     _ add code to draw a box around its message (you will need an instance of a Box)

     _ make an ArrayList<MySprite> collection (java.util package), and add three instances to it, each         with a di_erent colour, and short message. Use an enhanced for-loop to draw each instance.        (you should NOT write code to draw messages or boxes in this loop|it belongs in MySprite)      _ make the Fill class, and use one instance to _ll a large part of the background of a Panel2D with a         char from the COLOURS array you did not use for your sprites.

     _ use an instance of Fill to blank out the backgrounds of messages (belongs in MySprite)      _ design a pattern around the border with an ArrayList<Fill> collection      _ do not forget your doc comments!

 

Some issues to deal with are described below.

The order that data is initialized in 2D arrays lists rows in backward order from how we want to print data to a Panel2D.

 

private static int[][] sprite = {

{ 0, 1, 1, 1, 0 },

{ 1, 1, 0, 1, 1 },

{ 0, 1, 1, 1, 0 },

{ 0, 0, 1, 0, 0 },

{ 1, 1, 1, 1, 1 }

};

Note that the above initialization would be output upside down if we used a for-loop to iterate through the row indices from 0 to 4.

 

The solution to this problem is not to write the initialization of our data upside down (because we do not want to think upside down while designing).

 

Instead, write a method inside your MySprite class called get to return the value stored in the 2D sprite array such that fixes this upside-down problem. It is similar to the get method of Panel2D, but it is not fixing the same problem.

 

In other words, when you use get within the draw method of MySprite, it should print your design with the same vertical positions given in an initialization of sprite.

 

Note that you need if-statements within your draw method of MySprite to control when a stroke char should be set in a parentPanel. Testing for 0 or 1 values returned with calls to get will help you do this.

 

This is not the only way to solve this problem, but it is good practice writing extremely short methods that save you a lot of trouble in both your code and design issues at the same time.

 

| make sure to delete any test code before submitting your work |

 

 

Submit Instructions and Marking....................+++...........................____

____.........................................++.++..........................____ **__..........................................+++...........................__..

**__......%%%%%%%%%%%%%%%%%....................+............................__..

____......% %..................+++++..........................____

____......% Hello, World! %.................................................____

##__......% %.................................................__##

##__......%%%%%%%%%%%%%%%%%....%%%%%%%%%%%%%%%%%%%%%........................__##

____...........................% %........................____

____.###.......................% Feed me, Seymour! %........................____

**__##.##......................% %........................__##

**__.###.......................%%%%%%%%%%%%%%%%%%%%%........................__##

____..#.....................................................................____

____#####.................***...............................................____

..__.....................**.**..............................................__++ ..__......................***...............................................__++

___________________________*____________________________________________________

 

Frequently Asked Questions

Is it free to get my assignment evaluated?

Yes. No hidden fees. You pay for the solution only, and all the explanations about how to run it are included in the price. It takes up to 24 hours to get a quote from an expert. In some cases, we can help you faster if an expert is available, but you should always order in advance to avoid the risks. You can place a new order here.

How much does it cost?

The cost depends on many factors: how far away the deadline is, how hard/big the task is, if it is code only or a report, etc. We try to give rough estimates here, but it is just for orientation (in USD):

Regular homework$20 - $150
Advanced homework$100 - $300
Group project or a report$200 - $500
Mid-term or final project$200 - $800
Live exam help$100 - $300
Full thesis$1000 - $3000

How do I pay?

Credit card or PayPal. You don't need to create/have a Payal account in order to pay by a credit card. Paypal offers you "buyer's protection" in case of any issues.

Why do I need to pay in advance?

We have no way to request money after we send you the solution. PayPal works as a middleman, which protects you in case of any disputes, so you should feel safe paying using PayPal.

Do you do essays?

No, unless it is a data analysis essay or report. This is because essays are very personal and it is easy to see when they are written by another person. This is not the case with math and programming.

Why there are no discounts?

It is because we don't want to lie - in such services no discount can be set in advance because we set the price knowing that there is a discount. For example, if we wanted to ask for $100, we could tell that the price is $200 and because you are special, we can do a 50% discount. It is the way all scam websites operate. We set honest prices instead, so there is no need for fake discounts.

Do you do live tutoring?

No, it is simply not how we operate. How often do you meet a great programmer who is also a great speaker? Rarely. It is why we encourage our experts to write down explanations instead of having a live call. It is often enough to get you started - analyzing and running the solutions is a big part of learning.

What happens if I am not satisfied with the solution?

Another expert will review the task, and if your claim is reasonable - we refund the payment and often block the freelancer from our platform. Because we are so harsh with our experts - the ones working with us are very trustworthy to deliver high-quality assignment solutions on time.

Customer Feedback

"Thanks for explanations after the assignment was already completed... Emily is such a nice tutor! "

Order #13073

Find Us On

soc fb soc insta


Paypal supported