I need a raptor flowchart : Design a class named carthat has the following field
ID: 3604884 • Letter: I
Question
I need a raptor flowchart :
Design a class named carthat has the following fields:
- yearModel: the yearModel field is an integer that holds the car's year model.
- make: the make field references a string that holds the make of the car.
- speed: the speed field is an integer that holds the car's current speed.
In addition, the class should have the following constructor and other methods:
- Constructor: The constructor should accept the car's year model and make as arguments. These values should be assigned to the object's yearModel and make fields. The - constructor should also assign 0 to the speed field .
- Accessors: Design appropriate accessor methods to get the values stored in an object's yearModel, make, and speed fields .-
- 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.
Next, design 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.
( direction:
Create a Raptor file using the Object-Oriented mode to solve this question Using the UML tab, create a Car class containing the 3 given fields, a constructor, three accessor (getter) methods, plus the accelerate and brake methods. Complete the Car class with procedures on each of the tabs behind the Car tab. On the main tab, input the yearModel and the make value from the user and create a Car object setting those two values and a zero value for the speed. The speed value should be kept between zero to 25 within the accelerate and brake methods.
Use two loops, each with five iterations, to accelerate and then brake the car, displaying the speed on each iteration. Format out in complete sentences.)
Explanation / Answer
here is my code and hop it is usefull
public class Car {
private int yearmake; // Variable yearmake of car
private String model; //Variable of car company
private int speed; // Variable of your car speed
// here mainly the getter and setter method as the pojo class defines that will give getter and setter property for the every variable inside class as according to OP it wont let u change Variable directly
public String getModel() {
return model;
}
public void setModel(String model) {
this.model = model;
}
public int getSpeed() {
return speed;
}
public void setSpeed(int speed) {
this.speed = speed;
}
public int getYearmake() {
return yearmake;
}
public void setYearmake(int yearmake) {
this.yearmake = yearmake;
}
public Car(int speed) {
this.speed = speed;
}
// thus the constructor which will accepts and initialize your car with data i mean class
public Car(int yearmake, String model, int speed) {
this.yearmake = yearmake;
this.model = model;
this.speed = speed;
System.out.println("Year Make " + yearmake);
System.out.println("Model " + model);
System.out.println("Speed " + speed);
}
//here method of the making accelerate car by speed of 5
public int acclarate(int speed) {
speed = speed + 5;
System.out.println("Speed Acclarated " + speed);
return speed;
}
// method for reducing speed of 5
public int Breaking(int speed) {
speed = speed - 5;
System.out.println("Speed Breaking " + speed);
return speed;
}
// main method
public static void main(String[] args) {
// accept from user input
Scanner keyboard = new Scanner(System.in);
System.out.println("Enter the car's made year model: ");
int year = keyboard.nextInt();
keyboard.nextLine();
System.out.println("Enter the car's make Company: ");
String make = keyboard.nextLine();
System.out.println("Enter the car's speed: ");
int speedIn = keyboard.nextInt();
// initialize car model with constructor
Car c = new Car(year, make, speedIn);
//increasing speed with use of method and loop
for (int i = 0; i < 5; i++) {
int speedchange = c.acclarate(c.getSpeed());
c.setSpeed(speedchange);
}
//decreasing speed according to your requriement with use of method and loop
for (int i = 0; i < 5; i++) {
int decreasedpeed = c.Breaking(c.getSpeed());
c.setSpeed(decreasedpeed);
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.