Skip to content

Commit acdc3fc

Browse files
committedJun 10, 2014
Merge branch 'daisymarie128-master'
2 parents 11e9208 + 296b0fa commit acdc3fc

File tree

4 files changed

+238
-1
lines changed

4 files changed

+238
-1
lines changed
 

‎hackers/daisy_smith/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/daisy_smith/wk1d2/calc.rb

+158
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
def choice
2+
puts "choose calculator"
3+
print "(b)asic, (a)dvanced (m)ore : "
4+
gets.chomp.downcase
5+
end
6+
7+
def read_choice
8+
gets.chomp.downcase
9+
end
10+
11+
def basic_calc
12+
print "(a)dd, (s)ubtract, (m)ultiply, (d)ivide: "
13+
response = read_choice
14+
if response == "a"
15+
puts "first number you want to add?"
16+
number1 = gets.chomp.to_i
17+
puts "second number you want to add?"
18+
number2 = gets.chomp.to_i
19+
total = addition(number1, number2)
20+
elsif response == "s"
21+
puts "first number?"
22+
number1 = gets.chomp.to_i
23+
puts "second number?"
24+
number2 = gets.chomp.to_i
25+
total = subtract(number1, number2)
26+
elsif response == "m"
27+
puts "first number"
28+
number1 = gets.chomp.to_i
29+
puts "second number?"
30+
number2 = gets.chomp.to_i
31+
total = multiply(number1, number2)
32+
elsif response == "d"
33+
puts "first number?"
34+
number1 = gets.chomp.to_i
35+
puts "second number?"
36+
number2 = gets.chomp.to_i
37+
total = divide(number1, number2)
38+
end
39+
40+
puts total
41+
return choice
42+
end
43+
44+
def addition(num1, num2)
45+
num1 + num2
46+
end
47+
48+
def subtract(num1, num2)
49+
num1 - num2
50+
end
51+
52+
def multiply(num1, num2)
53+
num1 * num2
54+
end
55+
56+
def divide(num1, num2)
57+
num1 / num2
58+
end
59+
60+
def adv_choice
61+
gets.chomp
62+
end
63+
64+
def advanced_calc
65+
print "(p)ower, (s)qrt: "
66+
adv_response = adv_choice
67+
if adv_response == "p"
68+
puts "first number?"
69+
number1 = gets.chomp.to_i
70+
puts "second number?"
71+
number2 = gets.chomp.to_i
72+
total = power(number1, number2)
73+
elsif adv_response == "s"
74+
puts "what should we find the square root of?"
75+
number1 = gets.chomp.to_i
76+
total = sqrt(number1)
77+
end
78+
79+
puts total
80+
81+
end
82+
83+
84+
def power(num1, num2)
85+
num1 ** num2
86+
end
87+
88+
def sqrt(num1)
89+
Math.sqrt(num1)
90+
end
91+
92+
def additional_choice
93+
gets.chomp
94+
end
95+
96+
def additional_ft
97+
print "(m)ortgage, (b)mi, (t)trips"
98+
add_response = additional_choice
99+
if add_response == 'm'
100+
puts "What is the principal of the loan?"
101+
principal = gets.chomp.to_i
102+
puts "What is the interest rate?"
103+
interest = gets.chomp.to_i
104+
puts "What is the number of payments?"
105+
payments = gets.chomp.to_i
106+
total = monthly(principal, interest, payments)
107+
elsif add_response == 'b'
108+
puts "What is your weight?"
109+
weight = gets.chomp.to_i
110+
puts "What is your height?"
111+
height = gets.chomp.to_i
112+
total = bmi(weight, height)
113+
elsif add_response == 't'
114+
puts "How far will you drive?"
115+
distance = gets.chomp
116+
puts "What is the fuel efficiency of the car"
117+
mpg = gets.chomp
118+
puts "How much does gas cost per gallon?"
119+
pg = gets.chomp
120+
puts "How fast will you drive?"
121+
speed = gets.chomp
122+
total = trip_calc {"Your trip will take #{distance} and cost $#{pg}"}
123+
end
124+
125+
puts total
126+
127+
end
128+
129+
def monthly(principal, interest, payments)
130+
principal * interest *( 1 + interest ) * payments / ( 1 + interest ) * payments - 1
131+
end
132+
133+
def bmi(weight, height)
134+
weight / height * height
135+
end
136+
137+
def trip_calc(distance, mpg, pg,speed)
138+
distance / speed * mpg * pg
139+
end
140+
141+
# main program
142+
chosen = choice
143+
if chosen == "a"
144+
advanced_calc
145+
elsif chosen == "b"
146+
basic_calc
147+
elsif chosen == "m"
148+
additional_ft
149+
end
150+
151+
# return choice
152+
# return chosen
153+
chosen = choice
154+
puts "im here"
155+
156+
while chosen != 'q'
157+
chosen = choice
158+
end

‎hackers/daisy_smith/wk1d3/mta.rb

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
lines = {
2+
:n => {'Times Square' => 1, '34th' => 2, '28th' => 3, '23rd' => 4, 'Union Square' => 5, '8th' => 6},
3+
:l => {'8th' => 3, '6th' => 4, 'Union Square' => 5, '3rd' => 6, '1st' => 7},
4+
:six => {'Grand Central' => 1, '33rd' => 2, '28th' => 3, '23rd' => 4, 'Union Square' => 5, 'Astor Place' => 6}
5+
}
6+
7+
p "Are you on n, l or six?"
8+
line1 = gets.chomp
9+
p "What Station are you at?"
10+
current_location = gets.chomp
11+
p "Is your destination on n, l or six?"
12+
line2 = gets.chomp
13+
p "What Station are you going to?"
14+
destination = gets.chomp
15+
16+
station = lines[line1.to_sym][current_location]
17+
station2 = lines[line2.to_sym][destination]
18+
list = lines[line1.to_sym][current_location]..lines[line2.to_sym][destination]
19+
20+
stops = station2 - station
21+
if stops < 0
22+
stops = stops + station
23+
p "There are #{stops} stops between #{current_location} and #{destination} #{list}"
24+
else
25+
p "There are #{stops} stops between #{current_location} and #{destination}"
26+
end

‎homework/wk1d3/README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@
88
- The 6 line has the following stops: Grand Central, 33rd, 28th, 23rd, Union Square, and Astor Place.
99
- All 3 subway lines intersect at Union Square, but there are NO other intersection points.
1010
- For example, this means the 28th stop on the N line is different than the 28th street stop on the 6 line, so you'll have to differentiate this when you name your stops in the arrays.
11+
1112
- The program takes the line and stop that a user is getting on at and the line
13+
- The program takes the line and stop that a user is getting on at and the line
1214
and stop that user is getting off at and prints the total number of stops for the trip.
1315

1416
---
1517

16-
###Hints:
18+
###Hints:
1719
- Get the program to work for a single line before trying to tackle multiple lines.
1820
- Consider diagraming the lines by sketching out the subway lines and their stops and intersection.
1921
- Make subway lines keys in a hash, while the values are an array of all the stops on each line.

0 commit comments

Comments
 (0)
Please sign in to comment.