Question

In: Computer Science

Project 1: Frequent Flyer Miles Calculator Write a Ruby program that calculates how many frequent flyer...

Project 1: Frequent Flyer Miles Calculator

Write a Ruby program that calculates how many frequent flyer miles are needes for a free ticket on a new startup airline, CorsairAir. Frequent flyer miles are charged for a free ticket depending on the class of service (more for first class, less for coach), depending on the day flying (more if flying on Friday, Saturday or Monday, less for other days of the week), depending on the distance traveled, and a surcharge if flying to Canada, Mexico or the Carribean. Tickets start with a cost of 10,000 frequent flyer miles. Then, you should calculate the distance charge which is 1,000 frequent flyer miles for each 250 miles flown. Then, you should charge an additional 40% charge of frequent flyer miles if the passenger wants to fly first class. If flying on a Friday, Saturday or Monday, the ticket will cost an additional 5,000 frequent flyer miles. Travel to Canada, Mexico or the Carribean needs to cost an additional 7,500 frequent flyer miles. Be sure your program does not allow for negative miles flown or incorrect answers to the yes/no questions asked.
The sample program dialogs below should help you to see how to perform this calculation.

CorsairAir Calculator
How far are your flying:-20
Sorry Charlie!

Continue(y/n)? y

How far are you flying (in miles):500
Want first class (y/n):y
Flying on a Friday, Saturday or Monday (y/n):n
Flying to Canada, Mexico or the Carribean (y/n):n
10000 base cost
2000 distance charge
4800 First class charge
You will need 16800 frequent flyer miles for this ticket. Enjoy your trip!

Continue(y/n)? y

How far are you flying (in miles):500
Want first class (y/n):n
Flying on a Friday, Saturday or Monday (y/n):y
Flying to Canada, Mexico or the Carribean (y/n):n
10000 base cost
2000 distance charge
5000 day of the week charge
You will need 17000 frequent flyer miles for this ticket. Enjoy your trip!

Continue(y/n)? y

How far are you flying (in miles):500
Want first class (y/n):n
Flying on a Friday, Saturday or Monday (y/n):y
Flying to Canada, Mexico or the Carribean (y/n):foobar
Sorry Charlie!

Continue(y/n)? y

How far are you flying (in miles):500
Want first class (y/n):n
Flying on a Friday, Saturday or Monday (y/n):n
Flying to Canada, Mexico or the Carribean (y/n):n
10000 base cost
2000 distance charge
You will need 12000 frequent flyer miles for this ticket. Enjoy your trip!

Continue(y/n)? n

Solutions

Expert Solution

****This requires a lot of effort so please drop a like if you are satisfied with the solution..*****

Ruby Code

puts "CorsairAir Calculator"

loop do

basePrice=10000

distanceCharge=0

firstClass=0

dayOfTheWeekCharge=0

placeCharge=0

puts "How far are you flying(in miles):"

miles=gets.to_i

if miles>0

distanceCharge=(miles/250)*1000

puts "Want first class(y/n):"

choice=gets

if(choice <=> "y")==1

firstClass=(distanceCharge+basePrice)*0.4

elsif(choice <=> "n")==-1

puts "Sorry Charlie!"

puts "continue (y/n):"

choice=gets

if(choice <=> "y")==1

next

else

break

end

end

puts "Flying on a Friday, Saturday or Monday (y/n):"

choice=gets

if (choice <=>"y")==1

dayOfTheWeekCharge=5000

elsif(choice <=> "n")==-1

puts "Sorry Charlie!"

puts "continue (y/n):"

choice=gets

if(choice <=> "y")==1

next

else

break

end

end

puts "Flying to Canada, Mexico or the Carribean (y/n):"

choice=gets

if (choice <=>"y")==1

placeCharge=7500

elsif(choice <=> "n")==-1

puts "Sorry Charlie!"

puts "continue (y/n):"

choice=gets

if(choice <=> "y")==1

next

else

break

end

end

puts "#{basePrice} base cost"

if distanceCharge>0

puts "#{distanceCharge} distance charge"

end

if firstClass>0

puts "#{firstClass} first class charge"

end

if dayOfTheWeekCharge>0

puts "#{dayOfTheWeekCharge} day of the week charge"

end

if placeCharge>0

puts "#{placeCharge} Destination Charge"

end

puts "You will need #{basePrice+distanceCharge+firstClass+dayOfTheWeekCharge+placeCharge} frequent flyer miles for this ticket. Enjoy your trip!"

else

puts "Sorry Charlie!"

end

puts "continue (y/n):"

choice=gets

break if (choice <=>"y")==-1

end

output obtained:

ruby 2.5.5p157 (2019-03-15 revision 67260) [x86_64-linux]
   
CorsairAir Calculator
How far are you flying(in miles):
 -20
Sorry Charlie!
continue (y/n):
 y
How far are you flying(in miles):
 500
Want first class(y/n):
 y
Flying on a Friday, Saturday or Monday (y/n):
 n
Flying to Canada, Mexico or the Carribean (y/n):
 n
10000 base cost
2000 distance charge
4800.0 first class charge
You will need 16800.0 frequent flyer miles for this ticket. Enjoy your trip!
continue (y/n):
 y
How far are you flying(in miles):
 500
Want first class(y/n):
 n
Flying on a Friday, Saturday or Monday (y/n):
 y
Flying to Canada, Mexico or the Carribean (y/n):
 n
10000 base cost
2000 distance charge
5000 day of the week charge
You will need 17000 frequent flyer miles for this ticket. Enjoy your trip!
continue (y/n):
 y
How far are you flying(in miles):
 500
Want first class(y/n):
 n
Flying on a Friday, Saturday or Monday (y/n):
 y
Flying to Canada, Mexico or the Carribean (y/n):
 foobar
Sorry Charlie!
continue (y/n):
 y
How far are you flying(in miles):
 500
Want first class(y/n):
 n
Flying on a Friday, Saturday or Monday (y/n):
 n
Flying to Canada, Mexico or the Carribean (y/n):
 n
10000 base cost
2000 distance charge
You will need 12000 frequent flyer miles for this ticket. Enjoy your trip!
continue (y/n):
 n
=> nil


Related Solutions

4. An airline wants to know the impact of method of redeeming frequent-flyer miles and the...
4. An airline wants to know the impact of method of redeeming frequent-flyer miles and the age group of customers on how the number of miles they redeemed. To do so, they perform a two-way analysis of variance on the data for miles redeemed shown on cells L35 to O43 on the answers sheet. a. Identify the null and alternative hypotheses for each of the two main effects and the interaction. b. Use two-way analysis of variance to test each...
4. An airline wants to know the impact of method of redeeming frequent-flyer miles and the...
4. An airline wants to know the impact of method of redeeming frequent-flyer miles and the age group of customers on how the number of miles they redeemed. To do so, they perform a two-way analysis of variance on the data for miles redeemed shown on cells L35 to O43 on the answers sheet. a. Identify the null and alternative hypotheses for each of the two main effects and the interaction. b. Use two-way analysis of variance to test each...
Using Loops for the Hotel Occupancy calculator. You will write a program that calculates the occupancy...
Using Loops for the Hotel Occupancy calculator. You will write a program that calculates the occupancy of a hotel. Rules: 1# The hotel must have more than 2 floors and less than or equal 5 floors. 2# Each floor in the hotel can have a different number of rooms on the floor. 3# You must set the number of occupied rooms. Again, there must less rooms occupied than the number of rooms. 4# Using the total number of rooms and...
Airlines and hotels have many frequent-flyer and frequent-visitor programs in which individuals who fly the airline...
Airlines and hotels have many frequent-flyer and frequent-visitor programs in which individuals who fly the airline or stay at the hotel receive bonuses that are the equivalent to discounts. Give two reasons why these companies have such programs rather than simply offering lower prices. Can you give other examples of such programs? What is a likely reason why firms whose employees receive these benefits do not require their employees to give benefits to the firm?
Airlines and hotels have many frequent-flyer and frequent-visitor programs in which individuals who fly the airline...
Airlines and hotels have many frequent-flyer and frequent-visitor programs in which individuals who fly the airline or stay at the hotel receive bonuses that are the equivalent to discounts. Give two reasons why these companies have such programs rather than simply offering lower prices. Can you give other examples of such programs? What is a likely reason why firms whose employees receive these benefits do not require their employees to give benefits to the firm?
An airline is planning on making changes to its Frequent Flyer program. Before implementing them, they...
An airline is planning on making changes to its Frequent Flyer program. Before implementing them, they want to know what their customers think about the changes. They plan to sample a portion of their customers who are members of their Frequent Flyer program. They have two lists: One sorted by what level of frequent flyer the customer is: Gold (15 or more flights a year; about 15% of customers), Silver (5 to 14 flights a year; about 25% of customers);...
I have to write a c program for shipping calculator. anything that ships over 1000 miles,...
I have to write a c program for shipping calculator. anything that ships over 1000 miles, there is an extra 10.00 charge. I have tried everything. no matter what I put, it will not add the 10.00. please help here is my code #include <stdio.h> #include <stdlib.h> int main() { double weight, miles, rate, total; printf("Enter the weight of the package:"); scanf("%lf", &weight); if (weight > 50.0) { puts("we only ship packages of 50 pounds or less."); return 0; }...
Write a program that calculates the occupancy rate for a hotel. The program should start by asking the user how many floors the hotel has.
Use JAVAProgram #1: Hotel Occupancy: Write a program that calculates the occupancy rate for a hotel. The program should start by asking the user how many floors the hotel has. A for loop should then iterate once for each floor. In each iteration of the for loop, the program should ask the user for the number of rooms of the floor and how many of them are occupied. After all of the iterations are complete the program should display how...
DESIGH A FLOWCHART IN FLOWGORITHM Speeding Violation Calculator. Design a program that calculates and displays the...
DESIGH A FLOWCHART IN FLOWGORITHM Speeding Violation Calculator. Design a program that calculates and displays the number of miles per hour over the speed limit that a speeding driver was doing. The program should ask for the speed limit and the driver's speed. Validate the input as follows: The speed limit should be at least 20, but not greater than 70. The driver's speed should be at least the value entered for the speed limit (otherwise the driver was not...
Airlines and hotels give bonus frequent-flyer miles, gifts, and free companion tickets to attract the business traveler. These promotions are often provided
Airlines and hotels give bonus frequent-flyer miles, gifts, and free companion tickets to attract the business traveler. These promotions are often provided in lieu of a price cut. The traveler benefits personally, although their company does not get the benefit of lower rates. Is this ethical?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT