-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
jascination
authored and
jascination
committed
Apr 9, 2015
0 parents
commit a9e51e3
Showing
1,481 changed files
with
204,450 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.DS_Store |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
WDI LDN12 Lesson Notes & Completed Examples | ||
=========================================== | ||
|
||
If you want to edit something in one of the notes, please create a comment and/or create a pull request. |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title></title> | ||
<script type="text/javascript" src="./script.js"></script> | ||
</head> | ||
<body> | ||
|
||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
var calculationType = prompt("Which operation would you like to do ? b(a)sic, (m)ortgage, (b)mi, (t)rip or (q)uit"); | ||
|
||
while(calculationType != "q"){ | ||
switch(calculationType){ | ||
case "a" :// basic calc | ||
var num1 = parseFloat(prompt("first number")); | ||
var operationType = prompt("(a)dd, (s)ubtract, (m)ultiply or (d)ivide"); | ||
var num2 = parseFloat(prompt("second number")); | ||
switch(operationType){ | ||
case "a": | ||
var answer = num1 + num2; | ||
break; | ||
case "s": | ||
var answer = num1 - num2; | ||
break; | ||
case "m": | ||
var answer = num1 * num2; | ||
break; | ||
case "d": | ||
var answer = num1 / num2; | ||
break; | ||
} | ||
alert("The result is "+ answer) | ||
|
||
break; | ||
case "m" : | ||
var loan = parseFloat(prompt("loan ($)")); | ||
var apr = parseFloat(prompt("apr")) / 100 / 12; | ||
var term = parseInt(prompt("Term (months)")); | ||
|
||
var temp = Math.pow((1 + apr), term); | ||
var payment = (loan * apr * temp / (temp - 1)).toFixed(2); | ||
alert(" Your monthly payment will be $" + payment) | ||
break; | ||
|
||
case "b" : | ||
var mass = parseFloat(prompt("Mass (KG)")); | ||
var height = parseFloat(prompt("height (Meters)")); | ||
|
||
var bmi = (mass / Math.pow(height, 2)).toFixed(2); | ||
|
||
alert(" Your BMI is " + bmi); | ||
break; | ||
|
||
case "t" : | ||
var dist = parseFloat(prompt("Distance (miles)")); | ||
var mpg = parseFloat(prompt("Miles per gallon")); | ||
var cost = parseFloat(prompt("Cost ($/gallon)")); | ||
var speed = parseFloat(prompt("MPH")); | ||
|
||
var time = (dist / speed).toFixed(2); | ||
|
||
if(mpg > 60){ | ||
var actualMPG = mpg - (speed - 60) * 2; | ||
} else{ | ||
var actualMPG = mpg; | ||
} | ||
|
||
var cost = (dist / actualMPG * cost); | ||
|
||
alert("Your trip will take " + time + "hours and cost $" + cost) | ||
|
||
break; | ||
} | ||
var calculationType = prompt("Which operation would you like to do ? b(a)sic, (m)ortgage, (b)mi, (t)rip or (q)uit"); | ||
} | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#This is the Subway Stops Calculator | ||
|
||
mta_lines = { | ||
n: ["Times Square","34th", "28th", "23rd", "Union Square", "8th"], | ||
s: ["Grand Central", "33rd", "28th", "23rd", "Union Square", "Astor Palace"], | ||
l: ["8th", "6th", "Union Square", "3rd", "1st"] | ||
} | ||
|
||
def get_lines(information) | ||
puts information | ||
puts "Which line, n, l or s ?" | ||
gets().chomp | ||
end | ||
|
||
def get_stop(information) | ||
puts information | ||
puts "Which Station?" | ||
gets().chomp | ||
end | ||
|
||
def get_distance(line, first_stop, last_stop) | ||
(mta_lines[line.to_sym].index(first_stop) - mta_lines[line.to_sym].index(last_stop)).abs | ||
end | ||
|
||
#That' everything defined, now start the execution of code. | ||
# First Gather Info | ||
on_line = get_lines("Enter your Getting On Line") | ||
puts "You chose to get on the #{on_line} line" | ||
|
||
on_stop = get_stop("Enter Your on Station") | ||
puts "You chose to get on the #{on_stop} Station" | ||
|
||
off_line = get_lines("Enter your getting off line") | ||
puts "You chose to get off the #{off_line} line" | ||
|
||
off_stop = get_stop("Enter Your off Station") | ||
puts "You chose to get off the #{off_stop} Station" | ||
|
||
# calculations | ||
distance =if (on_line == off_line) # if the stations are on the same line | ||
get_distance(on_line, on_stop, off_stop) | ||
else # second case is for stops on different lines | ||
get_distance(on_line, on_stop, "Union Square") + get_distance(off_line, off_stop, "Union Square") | ||
end | ||
puts "Your Journey Distance is #{distance} Stops" |
15 changes: 15 additions & 0 deletions
15
completed_examples/w2_d1_ruby_airport_lab/airport/airport.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
class Airport | ||
|
||
attr_reader :name | ||
attr_accessor :flights | ||
|
||
def initialize(name) | ||
@name = name | ||
@flights = [] | ||
end | ||
|
||
def add_flight(number_of_seats, destination) | ||
flights << Flight.new(number_of_seats, destination) | ||
end | ||
|
||
end |
20 changes: 20 additions & 0 deletions
20
completed_examples/w2_d1_ruby_airport_lab/airport/flight.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
class Flight | ||
|
||
attr_reader :number_of_seats | ||
attr_accessor :passengers, :destination | ||
|
||
def initialize(number_of_seats, destination) | ||
@number_of_seats = number_of_seats | ||
@destination = destination | ||
@passengers = [] | ||
end | ||
|
||
def add_passenger(passenger) | ||
passengers << passenger | ||
end | ||
|
||
def to_s | ||
"#{destination} with #{number_of_seats} passengers." | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
require_relative 'airport' | ||
require_relative 'flight' | ||
require_relative 'passenger' | ||
|
||
airport = Airport.new("London Heathrow") | ||
|
||
def menu | ||
puts `clear` | ||
puts "*** Welcome to Heathrow Airport ***\n\n" | ||
puts '1 : Add a flight' | ||
puts '2 : List flights' | ||
puts '3 : Add passenger to flight' | ||
puts '4 : List passengers of a flight' | ||
puts "Q : Quit\n\n" | ||
print '--> ' | ||
gets.chomp | ||
end | ||
|
||
def list_flights(airport) | ||
airport.flights.each_with_index do |flight, index| | ||
puts "#{index}.\t#{flight}" | ||
end | ||
end | ||
|
||
def list_passengers(flight) | ||
flight.passengers.each_with_index do |passenger, index| | ||
puts "#{index}. #{passenger.name}" | ||
end | ||
end | ||
|
||
response = menu | ||
|
||
while response.upcase != 'Q' | ||
case response | ||
when '1' # Add a flight | ||
puts "How many passengers are on this flight?" | ||
number_of_passengers = gets.chomp.to_i | ||
puts "What is the flight's destination?" | ||
destination = gets.chomp | ||
puts airport.add_flight(number_of_passengers, destination) | ||
gets | ||
|
||
when '2' # List flights | ||
puts "Here is a list of the flights:" | ||
list_flights(airport) | ||
gets | ||
|
||
when '3' # Add passenger to flight | ||
puts "What is the passenger name?" | ||
name = gets.chomp | ||
passenger = Passenger.new(name) | ||
|
||
puts "What flight do you want to add a passenger to?" | ||
list_flights(airport) | ||
flight_number = gets.chomp.to_i | ||
flight = airport.flights[flight_number] | ||
flight.add_passenger(passenger) | ||
puts "#{passenger.name} added to #{flight}" | ||
gets | ||
|
||
when '4' # List passengers of a flight | ||
puts "What flight do you want to list the passengers of?" | ||
list_flights(airport) | ||
|
||
flight_number = gets.chomp.to_i | ||
flight = airport.flights[flight_number] | ||
|
||
puts "The passenger list for this flight is:" | ||
list_passengers(flight) | ||
gets | ||
|
||
end | ||
|
||
response = menu | ||
end |
9 changes: 9 additions & 0 deletions
9
completed_examples/w2_d1_ruby_airport_lab/airport/passenger.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
class Passenger | ||
|
||
attr_reader :name | ||
|
||
def initialize(name) | ||
@name = name | ||
end | ||
|
||
end |
Oops, something went wrong.