Due by the end of Tuesday, September 19
Today's lab has a pretty long description. It's telling you lots of stuff that you need to know, and that you'll use on every lab and assignment hereafter. Please read it carefully. We won't be going into so much detail on later labs and assignments, but you'll still be expected to do all the same sorts of things.
If you are using a lab computer you need to start up AppsAnywhere and open up Netbeans. You will also need to have a thumb drive to save your files on.
Students may also use AppsAnywhere on their home computers to run Netbeans.
For those of you going on in CS, we recommend you actually install Netbeans on your computer. Other students might like to do so as well. For those students, start by downloading JDK 17 (see the link in the Reference section of the navigation bar). After it is downloaded and installed, you can download download any version of Netbeans after v8.0.Refer to the Lecture Slides for weeks 1 and 2, and to the "How to Use NetBeans" link in the "Reference" section of the navigation pane, for information on using Netbeans.
You might want to open it in a new window so you can switch back-and-forth between it and this lab description.Pay particular attention to the sections "Creating a Program", "Downloading Code for a Lab" and "Running a Program".
You must use the following names:
You should put your project in the CSCI1226 folder you created.
The program I have provided for you has mistakes in it. Most of those mistakes are syntax errors -- you can see them because NetBeans draws squiggly red lines under them. Before you can run this program, you need to fix them.
Note that some bits of code have squiggly grey lines under them. Those are not errors; they are just warnings. NetBeans is telling you that you haven't used those variables yet But that's OK; we'll get around to using those variables by the end of the lab.Sometimes you might see code with squiggly yellow lines under it. That's also not an error, but it is a sign that you're doing some unusual thing. We'll talk more about that later in the term.
Once you have all the syntax errors fixed, you should look for some style mistakes. That is, there are places in the code where I've done something contrary to the style rules of the course. For example, a couple of the variables have names that don't look like variable names should. Some of the lines are not indented like they should be. And some commands' line breaks are in the wrong place.
Some of the mistakes can be fixed easily by using NetBeans' Format command (right-click in a blank area of the code pane). The variable names can be fixed easily by double-clicking the name in one place, then right-clicking it and using the Refactor > Rename... command from the pop-up menu. Of course, if you want to make those fixes by hand, you can do that, too. Just be aware that the variable names have to be changed the same way in every place they appear.
One last thing. You have now made changes to this program, so you and I are now joint authors of the version you're working on. Find where it says that "Mark Young" is an author, and add a line immediately below that says that you're an author, too. It should be just like Mark's line, but with your name and A-number.
After running the program, you should see the output in
the output window (typically at the bottom of the
program).
Click your mouse once, to position your cursor at the end of the last line outputted. Then type a 5, a space, and a 7, then press the enter key.
I've written those characters in blue followed by a grey arrow in the diagram below. Do not try to make blue or grey output!When the program asks you to press enter, press the enter key.
Shown by the grey arrow. Don't try to print a grey arrow!You should see:
Also notice that there are logic errors in your program. The output for your height and weight don't look right at all. Fix them so that the program prints out the feet and inches that the user typed in, and the number of pounds that the user is going to type in (after you fix that part of the program.)
Run the program again, using 6 and 2 as the input. Your output should look like this:
Now re-run the program and enter five foot seven (in numerals) at the first prompt, and 150 at the second prompt, where your newly created input statement will receive the value. It is because of your input statement the program suspends its execution, and waits for your input. You should see:
And if you did the input properly, it would have paused at the "Press enter..." prompt, and you should not see this bit (until you press the enter key again):
Don't worry if your numbers are a little bit different -- 1.70179999997 say, instead of 1.7018. That's called round-off error, and it's normal.
Note that we didn't print out the BMI. Add commands to print out the BMI. Put it on a line of its own at the bottom, separated from the one above it by a blank line:
Try your program with some different heights and weights. Some examples:
That's called a crash. The user has done something the program was not expecting at all, and couldn't cope with. And yet, it's something that a reasonable user might expect it to be able to do. Similarly, giving a weight of 87.5 lbs would also be reasonable. (Try it.)
The two crashes are pretty much the same. The error message is Exception in thread "main" java.util.InputMismatchException. It means that the input the user typed didn't match the kind of input the program asked for. The last line of the message has a link back to the program line where the crash occurred. For example, it might say: at l02.BMICalculator.main(BMICalculator.java:27). That says that the crash happened on line 27 of my program file (BMICalculator.java).
Don't worry if your line number is different! Your message is talking about your version of the program, which could be a bit different from mine.
Change your program so that the number of inches and the weight in pounds that the user enters can be double values instead of just int values. (The number of feet should still be an int value! It doesn't make sense to say you're "five and a half feet four inches" tall.)
Now take a moment and go over the code you've written. Make sure the indentation is consistent, and blank lines are used to highlight the pieces that make up the program. Be sure the variable names are fitting, and that the data types are appropriate.
Once all the activities are completed you can submit your Java program by one of the SUBMIT links above/below.
Make sure you pass in the correct file and that it has the correct name:
In particular, make sure you submit your modified copy of the .java file. You should find it in your L02/src/l02 folder.
The pass in page will print a little "receipt" for your records. Make sure you read it carefully. Make sure it doesn't have any red text on it at all. Make sure the submitted size is larger than the original size (you should have added quite a bit of code).
Submit this/these files:
You will be graded on the following: