Answer on Question #46863, Programming, Java
Problem.
Use Java code to convert the command line arguments to an array of integers.
Solution.
Code (Rectangle.java)
public class Rectangle {
private float topLeftX;
private float topLeftY;
private float bottomRightX;
private float bottomRightY;
/**
* Create square by top left corner and side.
* @param topLeftX x coordinate of top left corner.
* @param topLeftY y coordinate of top left corner.
* @param side length of side.
*/
Rectangle(float topLeftX, float topLeftY, float side) {
this.topLeftX = topLeftX;
this.topLeftY = topLeftY;
this.bottomRightX = topLeftX + side;
this.bottomRightY = topLeftY + side;
}
/**
* Move top left corner to another point.
* @param topLeftX x coordinate of top left corner.
* @param topLeftY y coordinate of top left corner.
*/
void moveTo(float topLeftX, float topLeftY) {
bottomRightX = topLeftX + (bottomRightX - this.topLeftX);
bottomRightY = topLeftY + (bottomRightY - this.topLeftY);
this.topLeftX = topLeftX;
this.topLeftY = topLeftY;
}
}Code (Main.java)
public class Main {
public static void main(String[] args) {
Rectangle square = new Rectangle(10, 20, 40);
square.moveTo(20, 20);
}
}http://www.AssignmentExpert.com/