A New Car Price Calculator

Venit Case Study 3.6,

By: Nicholas Duchon

Links:

Table 4.3 - the data for this example:

Category
Option
Code
Price
Delta from cheapest
Delta from dearest
Engine
6 cylinder
S
150
0
-600
8 cylinder
E
475
325
-275
Diesel
D
750
600
0
Interior Trim
Vinyl
V
50
0
-750
Cloth
C
225
175
-575
Leather
L
800
750
0
Radio
AM/FM/CD/DVD
C
100
0
-300

with GPS
P
400
300
0

Analysis - the total cost is given by the following formula:

SellingPrice = BasePrice + EngineCost + TrimCost + RadioCost + ShippingCharge + Dealer Charge

Notes on variables:

What if:

Scenarios

Each scenario will require specifications of the 3 categories, and the base price.

Input
Calculation
Expected output
"The total price is: $" +
Notes
20000 S V C
20000 + 150 + 50 + 100 + 675
20,975
All valid selections
15000 D L P
15000 + 750 + 800 + 400 + 675
17,625
All valid selections
30000 D L P
30000 + 750 + 800 + 400 + 675
32,625
All valid selections
20000 q q r S F F V H H C
20000 + 150 + 50 + 100 + 657 20,975 Option 1
20000 q q r
20000 + 150 + 50 + 100 + 657
20,975 Option 2
20000 q q r
20000 + 750 + 800 + 400 + 675 22,625 Option 3

Pseudo-Code - General Comments

I have added some of the key features of pseudo-code we have discussed in class:

Option 2, the simplest

// Declare global variables:
Declare BasePrice, EngineCost, TrimCost, RadioCost, ShippingCharge, DealerCharge as Float
main
  ShippingCharge = 500
  DealerCharge = 175

  call welcomeMessage
  call getBasePrice
  call getEngineCost
  call getTrimCost
  call getRadioCost
  call displaySellingPrice
end main

module welcomeMessage
  write "Welcome to the New Car Price Calculator"
  write "Enter the base price, and codes for engine, trim and radio options"
  write "This program will determine the final cost of the car"
  write "including the shipping and dealer charges."
end module welcomeMessage

module getBasePrice
  write "What is the base price for this model?"
  input BasePrice
end module getBasePrice

module getEngineCost
  declare code as character
  write "Engine codes:"
  write "  S - 6 cylinder, $150"
  write "  E - 8 cylinder, $475"
  write "  D - Diesel, $750"
  write "Select your engine code (S, E, D):"
  input code
  Select Case of code
  Case "S"
    EngineCost = 150
    Break
  Case "E"
    EngineCost = 475
    Break
  Case "D"
    EngineCost = 750
    Break
  Default
    write "Invalid selection, defaulting to 6 cylinder"
    EngineCost = 150
  End Case
end module getEngineCost

module getTrimCost
  declare code as character
  write "Trim codes:"
  write "  V - vinyl, $50"
  write "  C - cloth, $225"
  write "  L - leather, $800"
  write "Select your trim code (V, C, L):"
  input code
  Select Case of code
  Case "V"
    TrimCost = 50
    Break
  Case "C"
   
TrimCost = 225
    Break
  Case "L"
   
TrimCost = 800
    Break
  Default
    write "Invalid selection, defaulting to cloth"
   
TrimCost = 50
  End Case
end module getTrimCost

module getRadioCost
  declare code as character
  write "Radio codes:"
  write "  C - AM/FM/CD/DVD, $100"
  write "  P - with GPS, $400"
  write "Select your radio code (C, P):"
  input code
  Select Case of code
  Case "C"
   
RadioCost = 100
    Break
  Case "C"
   
RadioCost = 400
    Break
  Default
    write "Invalid selection, defaulting to AM/FM/CD/DVD"
   
RadioCost = 100
  End Case
end module getRadioCost

module displaySellingPrice
  declare SellingPrice as Float
  SellingPrice = BasePrice + EngineCost + TrimCost + RadioCost + ShippingCharge + DealerCharge
  write "The total cost of this car is $" + SellingPrice
end module displaySellingPrice

Option 3, also simple

// Declare global variables:
Declare BasePrice, EngineCost, TrimCost, RadioCost, ShippingCharge, DealerCharge as Float
main
  ShippingCharge = 500
  DealerCharge = 175

  call welcomeMessage
  call getBasePrice
  call getEngineCost
  call getTrimCost
  call getRadioCost
  call displaySellingPrice
end main

module welcomeMessage
  write "Welcome to the New Car Price Calculator"
  write "Enter the base price, and codes for engine, trim and radio options"
  write "This program will determine the final cost of the car"
  write "including the shipping and dealer charges."
end module welcomeMessage

module getBasePrice
  write "What is the base price for this model?"
  input BasePrice
end module getBasePrice

module getEngineCost
  declare code as character
  write "Engine codes:"
  write "  S - 6 cylinder, $150"
  write "  E - 8 cylinder, $475"
  write "  D - Diesel, $750"
  write "Select your engine code (S, E, D):"
  input code
  Select Case of code
  Case "S"
    EngineCost = 150
    Break
  Case "E"
    EngineCost = 475
    Break
  Case "D"
    EngineCost = 750
    Break
  Default
    write "Invalid selection, defaulting to Diesel"
    EngineCost = 750
  End Case
end module getEngineCost

module getTrimCost
  declare code as character
  write "Trim codes:"
  write "  V - vinyl, $50"
  write "  C - cloth, $225"
  write "  L - leather, $800"
  write "Select your trim code (V, C, L):"
  input code
  Select Case of code
  Case "V"
    TrimCost = 50
    Break
  Case "C"
   
TrimCost = 225
    Break
  Case "L"
   
TrimCost = 800
    Break
  Default
    write "Invalid selection, defaulting to leather"
   
TrimCost = 800
  End Case
end module getTrimCost

module getRadioCost
  declare code as character
  write "Radio codes:"
  write "  C - AM/FM/CD/DVD, $100"
  write "  P - with GPS, $400"
  write "Select your radio code (C, P):"
  input code
  Select Case of code
  Case "C"
   
RadioCost = 100
    Break
  Case "C"
   
RadioCost = 400
    Break
  Default
    write "Invalid selection, defaulting to AM/FM/CD/DVD with GPS"
   
RadioCost = 400
  End Case
end module getRadioCost

module displaySellingPrice
  declare SellingPrice as Float
  SellingPrice = BasePrice + EngineCost + TrimCost + RadioCost + ShippingCharge + DealerCharge
  write "The total cost of this car is $" + SellingPrice
end module displaySellingPrice

Option 1, rather more complex

// Declare global variables:
Declare BasePrice, EngineCost, TrimCost, RadioCost, ShippingCharge, DealerCharge as Float
main
  ShippingCharge = 500
  DealerCharge = 175

  call welcomeMessage
  call getBasePrice
  call getEngineCost
  call getTrimCost
  call getRadioCost
  call displaySellingPrice
end main

module welcomeMessage
  write "Welcome to the New Car Price Calculator"
  write "Enter the base price, and codes for engine, trim and radio options"
  write "This program will determine the final cost of the car"
  write "including the shipping and dealer charges."
end module welcomeMessage

module getBasePrice
  write "What is the base price for this model?"
  input BasePrice
end module getBasePrice

module getEngineCost
  declare code as character
  boolean invalidFlag
  do
    invalidFlag = false
    write "Engine codes:"
    write "  S - 6 cylinder, $150"
    write "  E - 8 cylinder, $475"
    write "  D - Diesel, $750"
    write "Select your engine code (S, E, D):"
    input code
    Select Case of code
    Case "S"
      EngineCost = 150
      Break
    Case "E"
      EngineCost = 475
      Break
    Case "D"
      EngineCost = 750
      Break
    Default
      write "Invalid selection, try again"
      invalidFlag = true
    End Case
  while (invalidFlag)
end module getEngineCost

module getTrimCost
  declare code as character
  boolean invalidFlag
  do
    invalidFlag = false
 
  write "Trim codes:"
    write "  V - vinyl, $50"
    write "  C - cloth, $225"
    write "  L - leather, $800"
    write "Select your trim code (V, C, L):"
    input code
    Select Case of code
    Case "V"
      TrimCost = 50
      Break
    Case "C"
     
TrimCost = 225
      Break
    Case "L"
     
TrimCost = 800
      Break
    Default
      write "Invalid selection, try again"
      invalidFlag = true
    End Case
  while (invalidFlag)
end module getTrimCost

module getRadioCost
  declare code as character
  boolean invalidFlag
  do
    invalidFlag = false
    write "Radio codes:"
    write "  C - AM/FM/CD/DVD, $100"
    write "  P - with GPS, $400"
    write "Select your radio code (C, P):"
    input code
    Select Case of code
    Case "C"
     
RadioCost = 100
      Break
    Case "C"
     
RadioCost = 400
      Break
    Default
      write "Invalid selection, try again"
     
invalidFlag = true
    End Case
  while (invalidFlag)
end module getRadioCost

module displaySellingPrice
  declare SellingPrice as Float
  SellingPrice = BasePrice + EngineCost + TrimCost + RadioCost + ShippingCharge + DealerCharge
  write "The total cost of this car is $" + SellingPrice
end module displaySellingPrice