Programming Logic

Programming logic exam solved assignment

This is solved assignment of programming logic course. If you are looking for assistance in programming logic, you can contact us at rakesh@xamnation.com

Programming logic exam problem

For this project, create a program with a class named Car. 

Car Class

Design a class named Car that has the following fields:

  • yearModel: The yearModelfield is an Integer that holds the car’s year model.
  • make: The makefield references a String that holds the make of the car.
  • speed: The speedfield 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 yearModeland make 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
  • accelerate: The acceleratemethod should add 5 to the speed field each time it is called.
  • brake: The brakemethod 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.

 

Grading criteria for Programming Logic and Design

Your instructor will grade your project as follows:

  • Used the lessons learned in this course to create the pseudocode for this program: 25 points
  • Created the main module for an effective program: 25 points
  • Created the Car class: 25 points
  • Used the appropriate flowchart shapes to create a flowchart: 25 points

Programming Logic Exam solution

Pennfoster programming logic exam solved

Class Car
Private Integer yearModel
Private String make
Private Integer speed

Public Module Car(Integer y, String m)
Set yearModel = y
Set make = m
End Module

Public Module setYearModel(Integer y)
Set yearModel = y
End Module

Public Module setMake(String m)
Set make = m
End Module

Public Module setSpeed(Integer s)
Set speed = 0
End Module

Public Function Integer getYearModel()
Return yearModel
End Function

Public Function String getMake()
Return make
End Function

Public Function Integer getSpeed()
Return speed
End Function

Public Function Integer accelerate()
Return speed =speed+5
End Function

Public Function Integer brake()
Return speed =speed-5
End Function
End Class

Module main()
Constant Integer repeatNumber = 0
Constant Integer repeatNumber2 = 0
Declare String modelYear
Declare String makeType
Declare Car car
Set car = New Car()


Display "Enter the year model"
Input modelYear
car.setYearModel(modelYear)

Display "Enter the make"
Input makeType
car.setMake(makeType)

While repeatNumber<5
Call car.accelerate()
Display "New Speed is $",getSpeed()
set repeatNumber=repeatNumber+1
End While

While repeatNumber2<5
Call car.brake()
Display "New Speed is $",getSpeed()
set repeatNumber2=repeatNumber2+1
End While

End Module

End Note

We, at Xamnation, are helping students in their assignment and project work for IT courses. Students can get online tutoring, personal mentorship and project help from us. Learn how to create pseudocode, flowchart and write computer programs. Email us your assignment to info@xamnation.com and we will gladly help you. 

1 thought on “Programming logic exam solved assignment”

  1. Pingback: Flowchart Tutorial | Learn how to create Flowchart – Xamnation

Leave a Comment

Your email address will not be published. Required fields are marked *