Coding Basic dr.Java codes, programming homework help

Coding Basic dr.Java codes, programming homework help

1. Write a class called Rectangle that represents a rectangular two-dimensional region. Your Rectangle objects should have the following methods:

Public Rectangle (int x, int y, int width, int height)

Construct a new Rectangle whose top-left corner is specified by the given coordinates and with the given width and height.

public int getHeight()

Returns the Rectangle’s height.

public int getWidth()

Returns the Rectangle’s width.

public int getX()

Returns the Rectangle’s x-coordinate.

public int getY()

Returns this Rectangle’s y-coordinate.

Also write a small client program to test the methods of the class (i.e. use the client program to create a rectangle object from this class, and call the methods getHeight(),getWidth() …etc.

2. Write a class named Car that has the following fields:

  • yearModel: The yearModel field is an int that holds the car’s year model.
  • make: The make field references a String object that holds the make of the car.
  • speed: The speed field is an int that holds the car’s speed

In addition, the class should have the following constructor and other methods:

  • Car: accepts the car’s year model and make as arguments. These values should be assigned to the object’s yearModel and make. Sets speed to 0.
  • getYearModel: returns the year
  • getMake: returns the make
  • getSpeed: returns the speed
  • accelerate: The accelerate method should add 5 to the speed field each time it is called.
  • brake: The brake method should subtract 5 from the speed field each time it is called.

Demonstrate the class in a program that creates a Car object, and then calls the accelerate method five times. After each call to the accelerate method, get the current speed of the car and display it. Then call the brake method five times. After each call to the brake method, get the current speed of the car and display it.

"You need a similar assignment done from scratch? Our qualified writers will help you with a guaranteed AI-free & plagiarism-free A+ quality paper, Confidentiality, Timely delivery & Livechat/phone Support.


Discount Code: CIPD30



Click ORDER NOW..

order custom paper