Question

Please explain clearly with steps. Its a very small code . thanks I would rate positively....

Please explain clearly with steps. Its a very small code . thanks I would rate positively.

Write a class pixel in java with following properties.

A Pixel has x, y coordinates, which are both integer values. A Pixel also has the following behaviors:

  • It can return the value of its x and y coordinates. Use the follwoing method signatures to implement these behaviors. public int getX( ) public int getY( )
  • It can change the value of its x and y coordinates. Use the following method signatures to implement these behaviours. public void setX(int xCoord ) public void setY(int yCoord )
  • It can also return the x, y coordinates in a format exactly like (x,y). Use the method signature: public String toString( )
  • The Pixel also has a construcor that initilizes the values of x, y coordinates to their default values.
  • It also has a second constructor that initializes the coordinates to given values. Use the signature: public Pixel (int x, int y)
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Please find the code below::

Pixel.java

package classes5;

public class Pixel {
   private int x;
   private int y;
  
   public Pixel() {
       x = 0;
       y = 0;
   }
  
   public Pixel(int x, int y) {
       this.x = x;
       this.y = y;
   }

   public int getX() {
       return x;
   }
   public void setX(int x) {
       this.x = x;
   }
   public int getY() {
       return y;
   }
   public void setY(int y) {
       this.y = y;
   }
   @Override
   public String toString() {
       return "(" + x + "," + y + ")";
   }
  
  
   public static void main(String[] args) {
      
       Pixel pixel = new Pixel(10, 20);
       System.out.println("Pixel is : "+pixel);
      
   }
  
  
}

output:

Console X <terminated > Pixel [Java Application) C:\Prog Pixel is : (10, 20)

Add a comment
Know the answer?
Add Answer to:
Please explain clearly with steps. Its a very small code . thanks I would rate positively....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I need help with my java code i am having a hard time compiling it //...

    I need help with my java code i am having a hard time compiling it // Cristian Benitez import java.awt.Color; import java.awt.Graphics; import java.util.ArrayList; import javax.swing.JPanel; Face class public class FaceDraw{ int width; int height; int x; int y; String smileStatus; //default constructor public FaceDraw(){ } // Getters and Setters for width,height,x,y 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 int getX(){ return...

  • Extend the code from Lab6.A template is given to you with CircleHeader.h, Circle.cpp and CircleMain.cpp Use...

    Extend the code from Lab6.A template is given to you with CircleHeader.h, Circle.cpp and CircleMain.cpp Use the same Circle UML as below and make extensions as marked and as needed. Given below is a UML for the Painting Class. You will need to write PaintingHeader.h and Painting.cpp. The Painting Class UML contains a very basic skeleton. You will need to flesh out this UML and add more instance variables and methods as needed. You do NOT need to write a...

  • I have some problems with my code. In Mimer I get this result for the code...

    I have some problems with my code. In Mimer I get this result for the code bellow: tests.cpp:29: Failure The difference between p1.distanceTo(p2) and 5.0 is 0.75735931288071523, which exceeds EPS, where p1.distanceTo(p2) evaluates to 4.2426406871192848, 5.0 evaluates to 5, and EPS evaluates to 1.0000000000000001e-05. Can I get some help what I did wrong here, The assignment is below: Write a class called Point that contains two doubles that represent its x- and y-coordinates. It should have get and set methods...

  •     class Circle    {    public:        enum Color {UNDEFINED, BLACK, BLUE, GREEN, CYAN,...

        class Circle    {    public:        enum Color {UNDEFINED, BLACK, BLUE, GREEN, CYAN, RED};        Circle(int = 0, int = 0, double = 0.0, Color = UNDEFINED);        void setX(int);        void setY(int);        void setRadius(double);        void setColor(Color);        int getX() const;        int getY() const;        double getRadius() const;        Color getColor() const;           private:        int x;        int y;   ...

  • In Java please! Problem You will be using the point class discussed in class to create...

    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 +...

  • Must be in Java. Show proper reasoning with step by step process. Comment on the code...

    Must be in Java. Show proper reasoning with step by step process. Comment on the code please and show proper indentation. Use simplicity. Must match the exact Output. CODE GIVEN: LineSegment.java LineSegmentTest.java Point.java public class Point { private double x, y; // x and y coordinates of point /** * Creates an instance of Point with the provided coordinates * @param inX the x coordinate * @param inY the y coordinate */ public Point (double inX, double inY) { this.x...

  • Java Help 2. Task: Create a client for the Point class. Be very thorough with your...

    Java Help 2. Task: Create a client for the Point class. Be very thorough with your testing (including invalid input) and have output similar to the sample output below: ---After declaration, constructors invoked--- Using toString(): First point is (0, 0) Second point is (7, 13) Third point is (7, 15) Second point (7, 13) lines up vertically with third point (7, 15) Second point (7, 13) doesn't line up horizontally with third point (7, 15) Enter the x-coordinate for first...

  • I am having trouble understanding how this code is able to use the contents of the...

    I am having trouble understanding how this code is able to use the contents of the header file. Can someone please provide comments in the main code to describe what is happening? (especially on the bool isNumber) THE MAIN CODE: #include<bits/stdc++.h> #include "MyCartesianPoint.h" #include <math.h> #include <iostream> using namespace std; bool isNumber(string s) {    if(!isdigit (s[0]))    {        if(s[0] != '-')        return false;               else if(s.length() == 1)        return false;...

  • I am having trouble understanding how this code is able to use the contents of the...

    I am having trouble understanding how this code is able to use the contents of the header file. Can someone please provide brief comments in the top code to show what is happening? THE CODE: #include<bits/stdc++.h> #include "MyCartesianPoint.h" #include <math.h> #include <iostream> using namespace std; bool isNumber(string s) {    if(!isdigit (s[0]))    {        if(s[0] != '-')        return false;               else if(s.length() == 1)        return false;    }       for...

  • Task 1 of 3 Game Rules Presented here, is an outline of the rules of the...

    Task 1 of 3 Game Rules Presented here, is an outline of the rules of the game around which this assignment is centred. This is not meant to be a completely exhaustive explanation, as you should defer to the specics provided in the Task descriptions for more detail, but rather this is to esh out the design and intention behind the game. 2.1.1 Game Board The game is played on a square board made of NxN characters where N is...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT