Skip to content

Commit 81e4515

Browse files
committed
Merge branch 'master' of github.com:epoch/wdi5_homework
2 parents acdc3fc + 6cfe62f commit 81e4515

File tree

18 files changed

+1308
-0
lines changed

18 files changed

+1308
-0
lines changed
File renamed without changes.

hackers/david mesaros/wk1d2/cal.rb

+129
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
def greet
2+
print "Welcome, would you like to use (b)asic, (a)dvance, ,(m)ortgage repayment ,check your bm(i) or (t)rips"
3+
greet = gets.chomp.downcase
4+
end
5+
6+
def menu_one
7+
greeting = greet
8+
if greeting == 'b'
9+
puts "basic calc"
10+
basic_calc
11+
elsif greeting == 'a'
12+
puts "advance calc"
13+
advance_calc
14+
15+
elsif greeting == 'm'
16+
puts "mortgage repayment"
17+
mortgage_repayment
18+
elsif greeting == "i"
19+
puts "BMI"
20+
bmi
21+
22+
elsif greeting == "t"
23+
puts "Trip Calculator"
24+
trip_calc
25+
26+
27+
elsif greeting == 'q'
28+
puts "Quitting"
29+
Kernel.exit
30+
end
31+
end
32+
33+
34+
def basic_calc
35+
print "(a)dd, (s)ubtract, (m)ultiply, (d)ivide: "
36+
basic_response = gets.chomp
37+
case basic_response
38+
when "a"
39+
print ""
40+
x = gets.to_i
41+
print ""
42+
y = gets.to_i
43+
puts "= " + (x + y).to_s
44+
when "s"
45+
print ""
46+
x = gets.to_i
47+
print ""
48+
y = gets.to_i
49+
puts "= " + (x - y).to_s
50+
when "m"
51+
print ""
52+
x = gets.to_i
53+
print ""
54+
y = gets.to_i
55+
puts "= " + (x * y).to_s
56+
when "d"
57+
print ""
58+
x = gets.to_i
59+
print ""
60+
y = gets.to_i
61+
puts "= " + (x / y).to_s
62+
end
63+
end
64+
65+
def advance_calc
66+
print "(p)ower, sq(r)t: "
67+
advance_response = gets.chomp
68+
case advance_response
69+
when "p"
70+
print ""
71+
x = gets.to_i
72+
print ""
73+
y = gets.to_i
74+
puts "= " + (x ** y).to_s
75+
when "r"
76+
print ""
77+
x = gets.to_f
78+
puts "= " + Math.sqrt(x).to_s
79+
end
80+
end
81+
82+
def mortgage_repayment
83+
print " Principal of the loan($) = "
84+
p = gets.chomp.to_f
85+
print " Interest rate(%) = "
86+
i = gets.chomp.to_f/100
87+
print " Number of payments = "
88+
n = gets.chomp.to_i
89+
puts "Monthly payments = $#{ p * i * (1 + i) ** n / ((1 + i) ** n - 1)}".to_f.round(2)
90+
91+
end
92+
93+
def bmi
94+
# print " Weight in Kilograms ="
95+
# x = gets.chomp.to_f
96+
# print " Height in Meters ="
97+
# y = gets.chomp.to_f
98+
99+
# puts "Your BMI is = #{x/(y * y)}"
100+
print "Height(m) = "
101+
x = gets.chomp.to_f
102+
print "Weight(kg) = "
103+
y = gets.chomp.to_f
104+
puts "BMI = #{y / x ** 2}."
105+
end
106+
107+
def trip_calc
108+
print "How far will you drive? "
109+
dist = gets.chomp.to_i
110+
print "What is the fuel efficiency of the car? "
111+
mpg = gets.chomp.to_i
112+
print "How much does gas cost per gallon? ($) "
113+
cpg = gets.chomp.to_f
114+
print "How fast will you drive? "
115+
speed = gets.chomp.to_i
116+
117+
new_mpg = ((speed - 60) * 2 - mpg).abs
118+
cost = ((dist / new_mpg) * cpg).abs
119+
time = dist / speed.to_f
120+
puts "Your trip will take #{time} hours and cost $#{cost}."
121+
end
122+
123+
124+
while true
125+
menu_one
126+
127+
end
128+
129+

hackers/david mesaros/wk1d3/mta.rb

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
lines = {
2+
:n =>["Times Square", "34th", "28th", "23rd", "Union Square", "8th" ],
3+
:l => ["8th", "6th", "Union Square", "3rd", "1st"],
4+
:"L6" => ["Grand Central" , "33rd", "28th", "23th", "Union Square", "Astor Place"]
5+
}
6+
7+
8+
def user_choice
9+
puts "Welcome, which NYC Subway line would like to go on"
10+
puts "(n) line "
11+
puts "(l) line "
12+
puts "(L6) line "
13+
14+
user_pick = gets.chomp.downcase
15+
end
16+
user_pick = user_choice.downcase
17+
18+
19+
20+
# Try changing 'n' to 'l' below to see the other line:
21+
user_choice = 'n' # pretend we read this from the keyboard with gets.chomp
22+
stops = lines[ user_choice.to_sym ] # need to convert 'n' string to :n symbol
23+
24+
25+
stops.each do |stop|
26+
puts "Here is the stop on this line: #{stop}"
27+
end
28+
29+
30+
31+
32+
33+
34+
35+
36+
37+
38+
39+
40+
41+
42+
43+
44+
45+
46+
47+
48+
49+

hackers/david_mesaros/wk1d2/README.md

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Calculator
2+
3+
###Objectives:
4+
- Practice with functions, loops, conditions, user-input, switch/case
5+
6+
###Activity:
7+
- Students should work on this lab in groups.
8+
9+
###Explanation
10+
- You will be building a calculator. A calculator can perform multiple arithmetic operations. Your function should allow the user to choose which operation is expected, enter in the values to perform the operation on, and ultimately view the result.
11+
- The instructor should carefully step through the lab with the students, as they type out the requirements for each specification.
12+
- Consider having the students make git commits as they finish each phase, so they can see the history
13+
14+
###Specification:
15+
- A user should be given a menu of operations
16+
- A user should be able to choose from the menu
17+
- A user should be able to enter numbers to perform the operation on
18+
- A user should be shown the result
19+
- This process should continue until the user selects a quit option from the menu
20+
21+
#####Phase 1
22+
- Calculator functionality
23+
- Calculator should be able to do basic arithmetic (+,-, *, /)
24+
25+
#####Phase 2
26+
- Advanced Calculator functionality
27+
- Calculator should be able to do basic arithmetic (exponents, square roots)
28+
29+
#####Phase 3
30+
- User should be given a menu of Calculator functionality
31+
- User should be able to choose indented functionality
32+
33+
## Mortgage & BMI Calculators
34+
35+
Add additional features to your calculators:
36+
37+
* [Mortgage:](http://www.wikihow.com/Sample/Mortgage-Payment)
38+
* Calculate the monthly payment when given the other variables as input.
39+
* [BMI:](http://www.wikihow.com/Image:BMI.jpg)
40+
* Calculate the BMI when given the height and weight.
41+
42+
## Trip Calculator
43+
44+
* This option asks the user for four inputs:
45+
* Distance – how far will you drive?
46+
* MPG – what is the fuel efficiency of the car?
47+
* $PG – how much does gas cost per gallon?
48+
* Speed – how fast will you drive?
49+
50+
* The output is a string: "Your trip will take 3.5 hours and cost $255.33."
51+
* For every 1 MPH over 60 MPH, reduce the the MPG by 2 MPG. (i.e. a car that normally gets 30 mpg would only get 28 mpg if its speed were 61 mph. Yes this gets silly at high speed where mpg goes to zero or gets negative.)

hackers/david_mesaros/wk1d2/cal.rb

+129
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
def greet
2+
print "Welcome, would you like to use (b)asic, (a)dvance, ,(m)ortgage repayment ,check your bm(i) or (t)rips"
3+
greet = gets.chomp.downcase
4+
end
5+
6+
def menu_one
7+
greeting = greet
8+
if greeting == 'b'
9+
puts "basic calc"
10+
basic_calc
11+
elsif greeting == 'a'
12+
puts "advance calc"
13+
advance_calc
14+
15+
elsif greeting == 'm'
16+
puts "mortgage repayment"
17+
mortgage_repayment
18+
elsif greeting == "i"
19+
puts "BMI"
20+
bmi
21+
22+
elsif greeting == "t"
23+
puts "Trip Calculator"
24+
trip_calc
25+
26+
27+
elsif greeting == 'q'
28+
puts "Quitting"
29+
Kernel.exit
30+
end
31+
end
32+
33+
34+
def basic_calc
35+
print "(a)dd, (s)ubtract, (m)ultiply, (d)ivide: "
36+
basic_response = gets.chomp
37+
case basic_response
38+
when "a"
39+
print ""
40+
x = gets.to_i
41+
print ""
42+
y = gets.to_i
43+
puts "= " + (x + y).to_s
44+
when "s"
45+
print ""
46+
x = gets.to_i
47+
print ""
48+
y = gets.to_i
49+
puts "= " + (x - y).to_s
50+
when "m"
51+
print ""
52+
x = gets.to_i
53+
print ""
54+
y = gets.to_i
55+
puts "= " + (x * y).to_s
56+
when "d"
57+
print ""
58+
x = gets.to_i
59+
print ""
60+
y = gets.to_i
61+
puts "= " + (x / y).to_s
62+
end
63+
end
64+
65+
def advance_calc
66+
print "(p)ower, sq(r)t: "
67+
advance_response = gets.chomp
68+
case advance_response
69+
when "p"
70+
print ""
71+
x = gets.to_i
72+
print ""
73+
y = gets.to_i
74+
puts "= " + (x ** y).to_s
75+
when "r"
76+
print ""
77+
x = gets.to_f
78+
puts "= " + Math.sqrt(x).to_s
79+
end
80+
end
81+
82+
def mortgage_repayment
83+
print " Principal of the loan($) = "
84+
p = gets.chomp.to_f
85+
print " Interest rate(%) = "
86+
i = gets.chomp.to_f/100
87+
print " Number of payments = "
88+
n = gets.chomp.to_i
89+
puts "Monthly payments = $#{ p * i * (1 + i) ** n / ((1 + i) ** n - 1)}".to_f.round(2)
90+
91+
end
92+
93+
def bmi
94+
# print " Weight in Kilograms ="
95+
# x = gets.chomp.to_f
96+
# print " Height in Meters ="
97+
# y = gets.chomp.to_f
98+
99+
# puts "Your BMI is = #{x/(y * y)}"
100+
print "Height(m) = "
101+
x = gets.chomp.to_f
102+
print "Weight(kg) = "
103+
y = gets.chomp.to_f
104+
puts "BMI = #{y / x ** 2}."
105+
end
106+
107+
def trip_calc
108+
print "How far will you drive? "
109+
dist = gets.chomp.to_i
110+
print "What is the fuel efficiency of the car? "
111+
mpg = gets.chomp.to_i
112+
print "How much does gas cost per gallon? ($) "
113+
cpg = gets.chomp.to_f
114+
print "How fast will you drive? "
115+
speed = gets.chomp.to_i
116+
117+
new_mpg = ((speed - 60) * 2 - mpg).abs
118+
cost = ((dist / new_mpg) * cpg).abs
119+
time = dist / speed.to_f
120+
puts "Your trip will take #{time} hours and cost $#{cost}."
121+
end
122+
123+
124+
while true
125+
menu_one
126+
127+
end
128+
129+

0 commit comments

Comments
 (0)