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: 3681613 • Letter: T

Question

This is Ruby Language problem

Directions:

Please complete the following assignment to signify your completion of Unit 5. 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 loops and functions. Loops are very useful in programming and, often, programs use loops in situations where new programmers might not spot a loop. When working with loops, it is important that you make progress toward the goal of getting the loop to stop. Otherwise, your loops will run forever, which is a very common programming problem for new programmers. Functions are the backbone of Ruby programs. We need to get very comfortable with how to define and call functions. Functions are a problem-solving strategy. Functions break a large, complex problem into smaller, more manageable pieces.

Project 1: College Student Fees
Create a Ruby program which calculates student fees for those attending College. IN ORDER TO RECEIVE FULL CREDIT, YOU MUST CREATE AND CALL FUNCTIONS WITH PARAMETERS TO SOLVE THIS PROBLEM. IN ADDITION IN ORDER TO RECEIVE FULL CREDIT, YOU MUST THROW AND CATCH EXCEPTIONS WHEN THE USER ENTERS INVALID DATA VALUES.

Summarized in the chart below is the cost calculations I want your program to perform.

COLLEGE STUDENT FEES (as of Fall, 2015)

Enrollment Fee

$ 46.00/ unit for California Residents
$ 335.00/ unit for F1/Non-Residents

Student Services Fee
(AS Sticker fee is Optional, saving $19.50)
(ID Card fee is Optional, saving $13)

$ 48.50 Winter/Summer
$ 51.50 Fall/Spring

Parking Decal (Optional)

$ 45.00 Winter/Summer
$ 85.00 Fall/Spring

A number of different program dialogues describe the program I am looking for.

College Fee Calculator
Enter number of units enrolled: 18
Is this Fall[0], Winter[1], Spring[2] or Summer[3] session: 0
Are you a state resident[0] or not[1]: 0
Want a parking decal? [y/n]: n
Want an AS sticker? [y/n]: n
Want an ID card? [y/n]: n
For Fall semester, your total fees are $ 847.00

College Fee Calculator
Enter number of units enrolled: 6
Is this Fall[0], Winter[1], Spring[2] or Summer[3] session: 1
Are you a state resident[0] or not[1]: 1
Want a parking decal? [y/n]: y
Want an AS sticker? [y/n]: y
Want an ID card? [y/n]: y
For Winter semester, your total fees are $ 2103.50

College Fee Calculator
Enter number of units enrolled: 18
Is this Fall[0], Winter[1], Spring[2] or Summer[3] session: 2
Are you a state resident[0] or not[1]: 1
Want a parking decal? [y/n]: y
Want an AS sticker? [y/n]: y
Want an ID card? [y/n]: y
For Spring semester, your total fees are $ 6166.50

Enrollment Fee

$ 46.00/ unit for California Residents
$ 335.00/ unit for F1/Non-Residents

Student Services Fee
(AS Sticker fee is Optional, saving $19.50)
(ID Card fee is Optional, saving $13)

$ 48.50 Winter/Summer
$ 51.50 Fall/Spring

Parking Decal (Optional)

$ 45.00 Winter/Summer
$ 85.00 Fall/Spring

Explanation / Answer

assignment.rb
# program that calculates student fees for those attending Santa Monica college

require_relative 'unit5test'

puts "SMC Fee Calculator"

begin

   print "Is this Fall[0], Winter[1], Spring[2] or Summer[3] session: "
   semester = gets.chomp.to_i

   print "Enter number of units enrolled: "
   units = gets.chomp.to_i

   print "Are you a state resident[0] or not[1]: "
   resident = gets.chomp.to_i

   print "Want a parking decal? [y/n]: "
   decal = gets.chomp

   print "Want an AS sticker? [y/n]: "
   sticker = gets.chomp

   print "Want an ID card? [y/n]: "
   card = gets.chomp

   semester = session_type(semester)
   fees = 0
   fees += (unit_fee( units, resident, fees ) + decal_fee( decal, semester, fees ) + services_fee( sticker, card, semester, fees ))
   fees = '%.2f' % fees
   print "For ", semester, " semester, your total fees are $ ", fees

rescue

   puts "Sorry, you've entered an incorrect number of units for the semester! Please try again."

end

test.rb

# contains functions for the SMC Fee Calculator

def session_type ( semester )
   if (semester == 0)
       semester = "Fall"
   elsif (semester == 1)
       semester = "Winter"
   elsif (semester == 2)
       semester = "Spring"
   elsif (semester == 3)
       semester = "Summer"
   end

   return semester
end

def unit_fee ( units, resident, fees )

   # if (semester == 0 or semester == 2)
       if (units < 0 or units > 16)
           raise "inappropriate number of units entered for semester"
       end
   # elsif (semester == 1 or semester == 3)
       # if (units < 0 or units > 8)
           # raise "inappropriate number of units entered for session"
       # end
   # end

   if (resident == 0)
       fees += (units * 46.00)
   elsif (resident == 1)
       fees += (units * 325.00)
   end

   return fees
end

def decal_fee ( decal, semester, fees )

   if (semester == 0 or semester == 2)
       if (decal == 'y')
           fees += 85.00
       end
   elsif (semester == 1 or semester == 3)
       if (decal == 'y')
           fees += 45.00
       end
   end

   return fees
end

def services_fee ( semester, sticker, card, fees )

   if (semester == 0 or semester == 2)
       fees += 50.50
       if (sticker == 'n')
           fees -= 19.50
       end
       if (card == 'n')
           fees -= 13.00
       end
   elsif (semester == 1 or semester == 3)
       fees += 47.50
       if (sticker == 'n')
           fees -= 19.50
       end
       if (card == 'n')
           fees -= 13.00
       end
   end

   return fees
end

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