Starting from:
$35

$29

Homework Assignment #1 Solution




Instructions: You must submit a k.java file per problem where k is the problem number. For instance, if this assignment has 4 problems, you need to submit 4 files 1.java, 2.java, 3.java, and 4.java. Note that we use Java 8 or higher. Submit your files on Blackboard.




Grading: Each programming problem is graded as follows




A submission which does not compile gets 0.



A submission which compiles but does something completely irrelevant gets 0.



A submission which works (partially) correctly, gets (up to) %80 of the total credit.



%20 is reserved for the coding style. Follow the coding style described in the book.












Problem 1 [10pts]. One way to measure the amount of energy that is expended during exercise is to use metabolic equivalents (METs). Here are some METs for for various activ-ities:




– Running at 6mph 10 METs




– Basketball 8 METs




– Sleeping 1 MET




The number of calories burned per minute can be estimated using the following formula CaloriesMinute = 0:0175 MET Weight (Kg)




Write a program that calculates and outputs the total number of calories burned for a 150-pound person who runs 6mph for 30 minutes, plays basketball for 60 minutes, and then sleeps for 8 hours. Note: 1Kg = 2.2lbs.




1
Problem 2 [10pts]. Cyclists can calculate their speed if the gear size and cadence are known. Gear size refers to the effective diameter of the wheel. Gear size multiplied by gives the distance traveled with one revolution of the pedals. Cadence refers to the number of pedal revolutions per minute (rpm). The speed in miles per hour is calculated by the following




Speed = Gear size (inches)
1(ft)
1(miles)
Cadence (rpm)
60(minutes)










12(inches)
5280(ft)
1(hour)



Write a program that calculates the speed for a gear size of 100 inches and a cadence of 90rpm.




Problem 3 [4pts]. The following program will compile and run, but it uses a poor pro-gramming style. Modify the code so that it uses the coding conventions described in the book.




p u b l i c
c l a s s
mess
{






p u b l i c
s t a t i c
v o i d
main ( S t r i n g [ ]
a r g s )


{












d o u b l e TIME ;
d o u b l e PACE;






System . out . p r i n t l n ( ” T h i s
program
c a l c u l a t e s p a c e ” ) ;
TIME =
35.5;
/∗ 35
m i n u t e s and 30
s e c o n d s
∗/
PACE = TIME /
d i s t a n c e ;






System . out . p r i n t l n ( ” Pace
i s ” + PACE + ”
m i l e s p e r hour . ” ) ;
d o u b l e d i s t a n c e = 6 . 2 1 .






}












}















Refer to §1.4 (Program Style) in your book.


















































































2

More products