Question

In: Computer Science

Car class Question Design a class named car that has the following fields: YearModel: The yearModel...

Car class Question

Design a class named car that 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. The 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 cals the accelerate method fibe times. After each call to the accelerate method, get the current speed of the car and display it. Then call the brake method 5 times. After each call to the brake method, get the current speed of the car and display it..........

Thanks for the help guys pseudocode and flowchart please

Solutions

Expert Solution

|| UPDATED ||

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

JAVA CODE :-

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

CAR Class :

public class Car {

   private int yearModel;
   private String make;
   private int speed;
  
   public Car(int yM, String m){
       setYearModel(yM);
       setMake(m);
       setSpeed(0);
   }
   void accelerate() {
       setSpeed(getSpeed()+5);
   }
   void brake() {
       setSpeed(getSpeed()-5);
   }
   public int getYearModel() {
       return yearModel;
   }
   public void setYearModel(int yearModel) {
       this.yearModel = yearModel;
   }
   public String getMake() {
       return make;
   }
   public void setMake(String make) {
       this.make = make;
   }
   public int getSpeed() {
       return speed;
   }
   public void setSpeed(int speed) {
       this.speed = speed;
   }
   void getCurrentSpeed() {
       System.out.println("Current Speed of the Car object "+getMake()+" "+getYearModel()+" is "+getSpeed());
   }
}

PSEUDOCODE :-

car class

   private interger variable 'yearModel'
   private String variable 'make'
   private interger variable 'speed'
  
   public contructor 'car' takes two arguments - 'integer argument1 , String argument2'
       set the year of model to argument1
       set maker to argument2
       set speed to 0
  
  
   void method 'accelerate'
       increase the value of variable 'speed' of object by 5 units
  
  
   void method 'brake'
       decrease the value of variable 'speed' of object by 5 units
  

   public integer method 'getYearModel'
       returns the variable 'yearModel'


   public void method 'setYearModel' takes an integer argument
       set the value of passed argument to the variable 'yearModel'
  

   public String method 'getMake'
       returns the variable 'make'
  

   public void method 'setMake' takes an String argument
       set the value of passed argument to the variable 'make'
  

   public integer method 'getSpeed'
       returns the value of variable 'speed'


   public void method 'setSpeed' takes an integer argument
       set the value of passed argument to the variable 'speed'
  

   void method 'getCurrentSpeed'
       appends the details of the car object on console

exit

FLOW CHART :-

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

MAIN Class :

public class Main {

   public static void main(String[] args) {
      
       Car car1 = new Car(1998,"FORD");
       Car car2 = new Car(1995,"LOTUS");
      
       for(int i = 0 ; i < 5 ; i++ ) {
           car1.accelerate();
           car1.getCurrentSpeed();
       }
      
       for(int i = 0 ; i < 5 ; i++ ) {
           car1.brake();
           car1.getCurrentSpeed();
       }
      
       for(int i = 0 ; i < 5 ; i++ ) {
           car2.accelerate();
           car2.getCurrentSpeed();
       }
      
       for(int i = 0 ; i < 5 ; i++ ) {
           car2.brake();
           car2.getCurrentSpeed();
       }
      
   }
  
}

PSEUDOCODE :-

main class

main method
  
   first object of car is initiated using constructor
   second object of car is initiated using constructor


   for range 0 to 4
       first object of car accelerates
       appends the updated speed

   for range 0 to 4
       first object of car decelerates
       appends the updated speed

   for range 0 to 4
       second object of car accelerates
       appends the updated speed

   for range 0 to 4
       second object of car decelerates
       appends the updated speed

exit

FLOWCHART :-

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

OUTPUT :-

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

|SORRY FOR ANY INCONVENIENCE|


Related Solutions

Problem Statement Design a class named Car that has the following fields: year: The year field...
Problem Statement Design a class named Car that has the following fields: year: The year field is an integer that holds the car’s year. make: the make field is 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 parameters. These values should be...
Create a class named “Car” which has the following fields. The fields correspond to the columns...
Create a class named “Car” which has the following fields. The fields correspond to the columns in the text file except the last one. i. Vehicle_Name : String ii. Engine_Number : String iii. Vehicle_Price : double iv. Profit : double v. Total_Price : double (Total_Price = Vehicle_Price + Vehicle_Price* Profit/100) 2. Write a Java program to read the content of the text file. Each row has the attributes of one Car Object (except Total_Price). 3. After reading the instances of...
In java, design a class named Motorcycle that has the following fields: • year – The...
In java, design a class named Motorcycle that has the following fields: • year – The year field is an int that holds the motorcycle’s year • make – The make field references a String object that holds the make of the motorcycle. • speed – The speed field is an int that holds the motorcycle’s current speed The class should have the following constructor and other methods: • Constructor – the constructor should accept the motorcycle’s year and make...
Write a class named Car that has the following fields: • yearModel: The yearModel field is...
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 is a String object that holds the make of the car. • speed: The speed field is an int that holds the car's current speed. In addition, the class should have the following methods: • Constructor: The constructor should accept the car's year model and make as arguments. These values should...
Complete the following C++ tasks: a. Design a class named BaseballGame that has fields for two...
Complete the following C++ tasks: a. Design a class named BaseballGame that has fields for two team names and a final score for each team. Include methods to set and get the values for each data field. Create the class diagram and write the pseudocode that defines the class. b. Design an application that declares three BaseballGame objects and sets and displays their values. c. Design an application that declares an array of 12 BaseballGame objects. Prompt the user for...
Design a class named Employee. The class should keep the following information in fields: ·         Employee...
Design a class named Employee. The class should keep the following information in fields: ·         Employee name ·         Employee number in the format XXX–L, where each X is a digit within the range 0–9 and the L is a letter within the range A–M. ·         Hire date Write one or more constructors and the appropriate accessor and mutator methods for the class. Next, write a class named ProductionWorker that inherits from the Employee class. The ProductionWorker class should have fields...
Design a class named Employee. The class should keep the following information in fields: ·         Employee...
Design a class named Employee. The class should keep the following information in fields: ·         Employee name ·         Employee number in the format XXX–L, where each X is a digit within the range 0–9 and the L is a letter within the range A–M. ·         Hire date Write one or more constructors and the appropriate accessor and mutator methods for the class. Next, write a class named ProductionWorker that inherits from the Employee class. The ProductionWorker class should have fields...
Design a class named Employee. The class should keep the following information in fields: • Employee...
Design a class named Employee. The class should keep the following information in fields: • Employee name • Employee number in the format XXX–L, where each X is a digit within the range 0–9, and the L is a letter within the range A–M. • Hire date Write one or more constructors and the appropriate accessor and mutator methods for the class. Next, write a class named ProductionWorker that inherits from the Employee class. The ProductionWorker class should have fields...
Question 2: Design a class named Square that contains data fields side and surfaceArea, and a...
Question 2: Design a class named Square that contains data fields side and surfaceArea, and a method called getSurfaceArea(). Create a child class named Cube. Cube contains a getCubeSurfaceArea() method that calculates the cube surface area. Write a program called DemoSquare that instantiates a Square object and a Cube object and displays the surface areas of the objects. Use the methods created to set the value of the side, and return the surface area. Hint: square area= side*side, Cube surface...
[20 marks] (TestRobot.java) Design a class named Robot. The Robot class has three private data fields:...
[20 marks] (TestRobot.java) Design a class named Robot. The Robot class has three private data fields: position x, position y, and the direction (east, south, west, and north). Assume that positive x points to the east and positive y points to the south, and initially x = 0, y = 0, direction = "east". Create a no-arg constructor and another constructor which sets the three data fields. Create the accessors and mutators for the three data fields. Create a method...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT