Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This is Ruby Language Problem Directions: Please complete the following assignme

ID: 3687610 • Letter: T

Question

This is Ruby Language Problem

Directions:

Please complete the following assignment to signify your completion of Unit 9. All programming projects need to be completed and submitted electronically, following the Electronic Submission Guidelines discussed in class.

Background:

The purpose of this assignment is to get practice working with classes. Within an object-oriented programming universe, classes and object make up the backbone of any given software system. The programming project below will ask you to learn some of these new capabilities.

Project 1: CarDealer
I'd like you to create the classes CarDealer and Vehicle as described below. There will be two separate classes that are connected in the sense that client code will ask the CarDealer to sell it a Vehicle.

HINT #1: Please start by creating the class Vehicle. It represents an Automobile, such as a Ford or a Honda. Create accessors and mutators for the datafields shown above (make, model, engine and price).

HINT #2: CarDealer should track the number of cars it has sold and the total price paid for them all. Each call to.sellCar( ... ) should return a Vehicle object to the client code. This is referred to as a "factory design pattern".

IN ORDER TO RECEIVE FULL CREDIT, YOUR CODE SHOULD PROPERLY DEFINE TWO CLASSES AND HAVE CLIENT CODE WORK WITH THESE TWO TYPES.

Below is sample driver code which illustrates the kind of code I am looking for.

d = CarDealer.new()
dodge = d.sellCar( :Dodge, :Dart, "gas", 19500 )
# arguments are make, model, engine and price
puts( "here is your dart!!" )
puts dodge
puts( "here is your CarDealer!!" )
puts d
volt = d.sellCar( :Chevy, :Volt, "electric", 35000 )
puts( "here is your volt!" )
puts volt
puts( "here is your CarDealer!" )
puts d

here is your dart!!
A $19500 Dodge Dart with a gas engine
here is your CarDealer!!
A dealer having sold 1 car with revenue of $19500 so far!
here is your volt!!
A $35000 Chevy Volt with an electric engine
here is your CarDealer!!
A dealer having sold 2 cars with revenue of $54500 so far!

Client Code And Sample Output

d = CarDealer.new()
dodge = d.sellCar( :Dodge, :Dart, "gas", 19500 )
# arguments are make, model, engine and price
puts( "here is your dart!!" )
puts dodge
puts( "here is your CarDealer!!" )
puts d
volt = d.sellCar( :Chevy, :Volt, "electric", 35000 )
puts( "here is your volt!" )
puts volt
puts( "here is your CarDealer!" )
puts d

here is your dart!!
A $19500 Dodge Dart with a gas engine
here is your CarDealer!!
A dealer having sold 1 car with revenue of $19500 so far!
here is your volt!!
A $35000 Chevy Volt with an electric engine
here is your CarDealer!!
A dealer having sold 2 cars with revenue of $54500 so far!

Explanation / Answer

class CarDealer
   @@count = 1
# constructor method
def CarDealer(p)
@totalSales = p
puts "revenue is : #Totalsales"
puts " sold is : #@@count"
@@count += 1
end

# instance method
def sellCar(m1,m2,e,p)
@make, @model , @engine , @price = m1, m2 , e , p
end
  
end

# create an object
d = CarDealer.new()
dodge = d.sellCar( :Dodge, :Dart, "gas", 19500 )
# arguments are make, model, engine and price
puts( "here is your dart!!" )
puts dodge
puts( "here is your CarDealer!!" )
puts d
volt = d.sellCar( :Chevy, :Volt, "electric", 35000 )
puts( "here is your volt!" )
puts volt
puts( "here is your CarDealer!" )
puts d

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote