From af353020ea625b3ad458b1a0a0e35c193c75bc44 Mon Sep 17 00:00:00 2001 From: M King Date: Fri, 26 Mar 2021 23:13:40 -0700 Subject: [PATCH 1/2] Submit SQL and Ruby assignment --- sql.txt | 5 ++++- years_to_hours.rb | 20 ++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 years_to_hours.rb diff --git a/sql.txt b/sql.txt index 5351a54..435e81f 100644 --- a/sql.txt +++ b/sql.txt @@ -3,9 +3,12 @@ SELECT with JOIN practice: Join the OrderDetails and Products tables, to show a report where the columns are OrderID, ProductName, and Quantity. Paste the SQL statement you used below. +SELECT od.OrderID, prod.ProductName, od.Quantity FROM OrderDetails od INNER JOIN Products prod ON od.ProductID = prod.ProductID; Join the Orders, OrderDetails, and Employees tables to return a report with with the EmployeeName, ProductID, and Quantity. Paste the SQL statement you used below. Hint: EmployeeName is not a column in the Employee table, but you can generate a report with EmployeeName by starting your SQL this way: SELECT (Employees.FirstName || " " || Employees.LastName) AS EmployeeName, - +SELECT (e.FirstName || " " || e.LastName) AS EmployeeName, od.ProductID, od.Quantity FROM Orders o + INNER JOIN OrderDetails od ON o.OrderID = od.OrderID + INNER JOIN Employees e ON o.EmployeeID = e.EmployeeID; diff --git a/years_to_hours.rb b/years_to_hours.rb new file mode 100644 index 0000000..3a66a36 --- /dev/null +++ b/years_to_hours.rb @@ -0,0 +1,20 @@ +#Write a program which asks the user for a number of years, and then prints out how many hours are in that many years. +puts "Enter a number of years" +years = gets.chomp # this returns a string +years = years.to_i # this converts a string to an integer +hours = years * 365 * 24 +puts "That's #{hours} hours." + +#Then it asks for a number of decades, and prints out the number of minutes are in that many decades. +puts "Enter a number of decades" +decades = gets.chomp +decades = decades.to_i +minutes = decades * 10 * 365 * 24 * 60 +puts "That's #{minutes} minutes in #{decades} decades." + +#Then it asks for the user's age, and prints out the number of seconds old the user is. Call this program years_to_hours.rb. +puts "Enter your age" +age = gets.chomp +age = age.to_i +seconds = age * 365 * 24 * 60 * 60 +puts "You're #{seconds} seconds old." From 0168755644af14562d681ce49e7ed85c66d87ee3 Mon Sep 17 00:00:00 2001 From: myang1010 Date: Mon, 29 Mar 2021 16:03:26 -0700 Subject: [PATCH 2/2] Add leap years counting --- years_to_hours.rb | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/years_to_hours.rb b/years_to_hours.rb index 3a66a36..2f51baa 100644 --- a/years_to_hours.rb +++ b/years_to_hours.rb @@ -6,15 +6,20 @@ puts "That's #{hours} hours." #Then it asks for a number of decades, and prints out the number of minutes are in that many decades. +def years_to_days(years) + leap_years = years/4 + leap_years * 366 + (years - leap_years) * 365 +end + puts "Enter a number of decades" decades = gets.chomp decades = decades.to_i -minutes = decades * 10 * 365 * 24 * 60 +minutes = years_to_days(decades * 10) * 24 * 60 puts "That's #{minutes} minutes in #{decades} decades." #Then it asks for the user's age, and prints out the number of seconds old the user is. Call this program years_to_hours.rb. puts "Enter your age" age = gets.chomp age = age.to_i -seconds = age * 365 * 24 * 60 * 60 +seconds = years_to_days(age) * 24 * 60 * 60 puts "You're #{seconds} seconds old."