create a java class with the name
Brick class:
For this part of the assignment, you will create a class that
allows you to specify a colored brick that is capable of drawing
itself given a specified Graphics object. Note that this is a
regular Java class and does not extend the JApplet
class.
Your class should a constructor with the following signature:
Identifier: |
Brick(int xPosition, int yPosition, int width, int height, Color color) |
Parameters: |
xPosition – an int representing the x coordinate for the upper-left corner yPosition – an int representing the y coordinate for the upper-left corner width – an int representing the width of the Brick height – an int representing the height of the Brick color – A Color representing the color of the Brick |
Return Value: |
|
Other: |
Your class should include accessor and mutator methods for each of the different instance variables as well as the following method:
Identifier: |
draw(Graphics g) |
Parameters: |
g – A Graphics object |
Return Value: |
Void |
Other: |
Given an object reference to a Graphics object, this method should be able to create a solid (filled-in) block of the correct size and color at the appropriate position based on the values of the instance variables. |
If you have any problem with the code feel free to comment.
Program
import java.awt.Color;
import java.awt.Graphics;
class Brick {
//instance variables
private int xPosition, yPosition, width, height;
private Color color;
//constructor
public Brick(int xPosition, int yPosition, int width,
int height, Color color) {
this.xPosition = xPosition;
this.yPosition = yPosition;
this.width = width;
this.height = height;
this.color = color;
}
//all accessor and mutator
public int getxPosition() {
return xPosition;
}
public void setxPosition(int xPosition) {
this.xPosition = xPosition;
}
public int getyPosition() {
return yPosition;
}
public void setyPosition(int yPosition) {
this.yPosition = yPosition;
}
public int getWidth() {
return width;
}
public void setWidth(int width) {
this.width = width;
}
public int getHeight() {
return height;
}
public void setHeight(int height) {
this.height = height;
}
public Color getColor() {
return color;
}
public void setColor(Color color) {
this.color = color;
}
//for drawing the brick
public void draw(Graphics g) {
g.drawRect(xPosition, yPosition,
width, height);
g.setColor(color);
}
}
create a java class with the name Brick class: For this part of the assignment, you...
For this question you must write a java class called Rectangle and a client class called RectangleClient. The partial Rectangle class is given below. (For this assignment, you will have to submit 2 .java files: one for the Rectangle class and the other one for the RectangleClient class and 2 .class files associated with these .java files. So in total you will be submitting 4 files for part b of this assignment.) // A Rectangle stores an (x, y) coordinate...
Making a rectangle class in java write a simple class that will represent a rectangle. Later on, we will see how to do this with graphics, but for now, we will just have to use our imaginations for the visual representations ofWthe rectangles. Instance Variables Recall that an object is constructed using a class as its blueprint. So, think about an rectangle on your monitor screen. To actually draw a rectangle on your monitor screen, we need a number of...
Java program GCompound Practice Exercise CS141 Assignment Write a class that represents a digital snowman. Your class should follow these guidelines: 1. Store the following private class variables bodyColor of type Color b. int x, int y for the upper left corner Graphics g. a. C. 2. Create two different constructor methods a. A (int x, int y, Graphics myG) parameter constructor that makes the snowman a light gray color by default and makes x and y the upper left...
The purpose of this assignment is to write a class Checker that can be used as a part of a checker game program. Open an New Project in Qt Creator, and name it ChGame. Right click on the name of the class, and add a new C++ class named Checker. This will create the new les Checker.h and Checker.cpp. You will need to modify both Checker.h and Checker.cpp for this assignment. (The main function I used for testing my functions...
JAVA Create a Java project to implement a simple Name class. This class will have the following class variable: First Name, Middle Name, Last Name, and Full Name Create the accessor/getter and mutator/setter methods. In addition to these methods, create a toString() method, which overrides the object class toString() method. This override method prints the current value of any of this class object. Create a main() method to test your project.
In Java please! Problem You will be using the point class discussed in class to create a Rectangle class. You also need to have a driver class that tests your rectangle. Requirements You must implement the 3 classes in the class diagram below and use the same naming and data types. Following is a description of what each method does. Point Rectangle RectangleDriver - x: int - top Left: Point + main(args: String[) - y: int - width: int +...
Room Class....... in JAVA!!!!! Write a class named Room that has the following fields: Length: Double variable that holds the rooms length(in feet). Breadth: The double variable that holds the rooms breadth(in feet). Height: Double variable that holds rooms height in feet. Color: String object that holds the color you want the room to be painted with. The class should have a constructor to initialize the fields for a particular instance (or object) of the class as given: All double...
java language please. thank you T-Mobile 9:00 AM For this assignment, create a Java class named "MyRectangle3d" Your class must have the following attributes or variables · x (the x coordinate of the rectangle, an integer) * y (the y coordinate of the rectangle, an integer) * length (the length of the rectangle, an integer) * width (the width of the rectangle, an integer) * height (the height of the rectangle, an integer) * color( the color of the rectangle,...
Java Program Please help me with this. It should be pretty basic and easy but I am struggling with it. Thank you Create a superclass called VacationInstance Variables destination - String budget - double Constructors - default and parameterized to set all instance variables Access and mutator methods budgetBalance method - returns the amount the vacation is under or over budget. Under budget is a positive number and over budget is a negative number. This method will be overwritten in...
In JAVA 1. Create a class called Rectangle that has integer data members named - length and width. Your class should have a default constructor (no arg constructor) Rectangle() that initializes the two instance variables of the object Rect1. The second overloading constructor should initializes the value of the second object Rect2. The class should have a member function named GetWidth() and GetLength() that display rectangle's length and width. OUTPUT: Rectl width: 5 Rectl length: 10 Enter a width :...