Docsity

CS201 Homework 1: Algorithm Design and Java Programming - Prof. Kenrick J. Mock, Study notes of Computer Science

Toggle sidebar
bg1
CS201
HW#1, 40 points total
Due: Midnight, Wednesday, 9/17
Submit your programs/code via Blackboard
Algorithm Design
1. (8 points). Running. You have finished a race and would like to know at what pace
you ran the race. Describe an algorithm (i.e. an English description that illustrates
step by step how to solve the problem) that takes as input the distance of the race in
miles, and the finishing time in hours, minutes, and seconds. Your algorithm should
compute the pace per mile in minutes and seconds.
To test your algorithm, an input of 26.2 miles, 3 hours, 16 minutes, and 30 seconds
should result in a pace of 7:30 per mile.
For this part, give an algorithm only, do not write code.
Short Answer
2. (4 points) Given the algebraic equation
y = ax
3
+ 2x + 7
Which of the following, if any, are correct Java statements for this equation?
a. y=a*x*x*x+2*x+7;
b. y=a*x*x*x+2*(x+7);
c. y=a*(x*x*x+(2*x)+7);
d. y=(a*x)*x*x+7+x*2;
e. y=a*(x*x*x)+(2*x)+7;
3. (4 points) State the order of evaluation of the operators in each of the following Java
statements, and show the value of x after each statement is performed.
a. x=7+3*6/2-1;
b. x=2 % 2+2*2-2/2;
c. x=(3*9*(3+(9*3/(3))));
pf3

Partial preview of the text

Download CS201 Homework 1: Algorithm Design and Java Programming - Prof. Kenrick J. Mock and more Study notes Computer Science in PDF only on Docsity!

CS

HW#1, 40 points total Due: Midnight, Wednesday, 9/ Submit your programs/code via Blackboard

Algorithm Design

  1. (8 points). Running. You have finished a race and would like to know at what pace you ran the race. Describe an algorithm (i.e. an English description that illustrates step by step how to solve the problem) that takes as input the distance of the race in miles, and the finishing time in hours, minutes, and seconds. Your algorithm should compute the pace per mile in minutes and seconds.

To test your algorithm, an input of 26.2 miles, 3 hours, 16 minutes, and 30 seconds should result in a pace of 7:30 per mile.

For this part, give an algorithm only, do not write code.

Short Answer

2. (4 points) Given the algebraic equation

y = ax^3 + 2x + 7

Which of the following, if any, are correct Java statements for this equation? a. y=axxx+2x+7; b. y=axxx+2(x+7); c. y=a(xxx+(2x)+7); d. y=(ax)xx+7+x2; e. y=a(xxx)+(2x)+7;

3. (4 points) State the order of evaluation of the operators in each of the following Java statements, and show the value of x after each statement is performed. a. x=7+36/2-1; b. x=2 % 2+22-2/2; c. x=(39(3+(9*3/(3))));

Programming Exercises

For programming exercises, turn in a copy of your code. For all exercises use the Unix environment, not TextPad or 5etBeans. We will mostly use TextPad or NetBeans for the rest of the class, but you’ll have your choice of which environment to use. Turn in your Java files along with any other answers. Your answers can be placed in a word document or textfile.

Fill in the following comment header for all your programs. Add additional comments in your program as you deem necessary.

////////////////////////////////////////////////////// // CS // // // Purpose: //////////////////////////////////////////////////////

4. (6 points) One way to measure the amount of energy that is expended during exercise is to use metabolic equivalents (MET). Here are some METS for various activities:

Running 6 MPH: 10 METS Basketball: 8 METS Sleeping: 1 MET

The number of calories burned per minute may be estimated using the formula:

Calories/Minute = 0.0175 × MET × Weight(Kg)

Write a program that inputs a person’s:

  • Weight in pounds
  • Minutes spent running 6 MPH
  • Minutes spent playing basketball
  • Minutes spent sleeping And outputs the total number of calories burned. One kilogram is equal to 2.2 pounds. 5. (10 points) Running Race Pace Calculator

Implement the running pace calculator described in problem 1. Here is a sample of the desired behavior:

Example (user input in bold): Input distance in miles: 26. Input hours run: 3 Input minutes run: 16 Input seconds run: 30 Your race pace is 7:30 per mile