PurposeA computer program represents a useful computation (or, to be precise, a set of possible computations) in a human-readable form. The computer, so programmed, is valuable in its ability to automate useful computations at high speed. One important class of programs are those that accept input values from the person using the computer (colloquially “the user”), that compute a useful result, and that then present the result to the user. The steps in such a computation are thus (1) get input values, (2) compute result, (3) output result. In this homework assignment, you will write a computer program representing a simple but useful computation in this style. You can download the skeleton code here. The ProblemA bicyclist wants to bike a certain number of miles on each given day but has to figure out how many times to go around a given loop to reach that distance. In this assignment, you will write a program to answer how many times must the biker complete the loop to reach the goal. The biker also wants to know, given a time taken per loop, how long the entire ride will take. More specifically, you need to ask for three inputs (in the specified order): ride length, loop length, and loop time. All of these values should be of type double. Your program needs to provide a number of outputs:
Sample executionTo help you understand what is required for this homework, we have included an execution run of this program. Your program needs to print out similar information, but the format does not have to be the same. However, the values computed should be the same. Note that the text in red is what was input by the user. And don't worry about really long decimal numbers (such as 2.533333333333333 ) -- we'll see how to convert this into 2.53 (or similar) later in the semester. Welcome to the bike loop calculator! Please enter the number of miles to bike (in miles): 25 Please enter the length of the loop you'll be riding (in miles): 4 Please enter the average time per loop (in minutes): 15 The number of 4.0-mile loops required to bike for 25.0 miles is 6.25 It should take 93.75 minutes, or 1.5625 hours The average speed should be 16.0 mph, or 25.749504 kph Program DesignOne of the key problems that software developers face is to determine what sequences of operations are needed to solve a specified problem (such as the number-of-loops problem). In this case, we’re going to get you off to a good start by giving you a sequence of steps that work. Your primary task is to refine this program by converting each of these high-level steps into an appropriate statement or sequence of statements in the Java language. In the software development field, we call such a task step-wise refinement -- meaning that we take program steps expressed in a high-level, easy-to-understand form (such as the 6 steps below that are listed in English), and we refine them into one or more steps in a lower-level, more concrete language: in this case Java. This is an incredibly important skill for the software developer -- to be able to sketch programs at a high level before refining them into statements in a formal programming language, such as Java. The list below expresses the essence of the solution -- it's an abstract solution. Refining it into a language such as Java is relatively straightforward, once you know the language.
Remember that if you want to print out multiple things with a System.out.println() statement, you need to separate them with a + (a plus sign). You are welcome to print out the values as they are computed, if you would like. You should be able to determine the formulas needed to solve the problem -- see a TA for help if you are unsure. When asking for input, please only ask for the required 3 values in the specified order (ride length, loop length, loop time). We will test your program automatically, so if you ask for more input values, your program will not execute correctly for the graders. While we have provided most of the design for this program above, you need to supply some details -- the formula for computing the output values, the variables needed to store inputs and the result, and how to express all of these ideas in the Java programming language. How and where to startWe have provided a skeleton BikeLoops.java file for you to start with. Please don't change the class name -- doing so will cause it not to compile correctly and result in a loss of lots of points. The best way to proceed is to go through the seven steps described above, testing the program after each step or two. This process is called incremental development. If you take a small step and it doesn’t work, it’s easy to step back and do it again. If you take lots of steps and end up with something that doesn’t work, you can easily get completely lost. Take small steps then test before proceeding! For example, after you write the code to read in the input from the user, you should print those values out to the screen, so that you can test your input routines. And after you make some partial calculations, print those out to the screen to test the program. You are welcome to try to write the whole program and debug it all at once – however, this will very likely take you more time than developing and testing it incrementally. Of course, if you have lots of print statements in there, you should probably remove them when the program is working properly, so that the output looks similar to what is shown below. Lastly, be sure you fully understand how to do the conversions before you try to program that in Java. Lastly, you may want to look at the BMICalculator.java program (also on page 75 of the textbook and discussed in lecture). This program, while it computes something different, uses a lot of the same steps described above. Good programming practicesThe following are considered good programming practices. All homeworks must include these whenever possible. Not including them will receive points off from the grade. The BMICalculator.java program (on page 75 of the textbook) is an example of a program that follows most of these practices (all but the test code part).
GradingThe following lists the criteria that the graders will be look at when the homework is graded. Note that these criteria will not be repeated on the other homeworks, only on this first one. Also, the points for each of the following criteria have not yet been determined.
If your program does not compile, you will receive 25 points off, in addition to any other penalties. If you do not understand a compilation error, see a TA or professor (thus, you probably don't want to wait until the night before to start this homework). We have lots of office hours available, please make use of them! SubmissionWhen you are finished, submit the BikeLoops.java file. You will notice that we ask more survey questions for the homeworks.
|