Pledged Lab QuizThis lab quiz is pledged. You may use the course textbook, and NOTHING ELSE. This includes any files in your home directory, previous assignments, slides, etc. However, you should still save your file into your home directory. You will need to submit a single file called LabQuiz2.java. You may download the skeleton code here: LabQuiz2.java (right click on the link and select "save as" (or "save target as")). The TAs cannot help you with Java-related issues on this quiz. If you are having problems getting JCreator to work, can't log in to the machines, etc., then you are welcome to ask the TAs for assistance. If you do not understand what the lab is asking, the TAs may be able to help you (meaning if it's a problem with our explanation, then they can help you -- if you've been skipping the lectures so far and have no idea what any of this means, you are on your own). Advice
Lab Quiz Part 1: Triangle CountingThe code for this part should all be within the main() method. You will need to read in an int value from the keyboard (we'll call it n). Only read one int value for this whole program, or else it will not run correctly for the graders! You will then need to examine all triangles from (1,1,1) to (n,n,n). Thus, if n is 2, you need to consider 8 triangles: (1,1,1), (1,1,2), (1,2,1), (1,2,2), (2,1,1), (2,1,2), (2,2,1), (2,2,2). This will probably require nested loops. First, check if the triangle is not valid. There are two reasons to not consider a potential triangle
For each triangle, you will need to print out its properties.
If you get stuck on some of them, keep on going -- you can always come back and try to fix it later. Sample OutputThe text in red is what was input by the user. The format of your program does not have to look the same, but it should print out the same information. Note that for some triangles, such as (3,4,5) have multiple properties (right and scalene) -- they can be printed out on separate lines. Triangle manipulation Enter max n: 5 (1,1,1) is an equilateral triangle (1,2,2) is an isosceles triangle (1,3,3) is an isosceles triangle (1,4,4) is an isosceles triangle (1,5,5) is an isosceles triangle (2,2,2) is an equilateral triangle (2,2,3) is an isosceles triangle (2,3,3) is an isosceles triangle (2,3,4) is a scalene triangle (2,4,4) is an isosceles triangle (2,4,5) is a scalene triangle (2,5,5) is an isosceles triangle (3,3,3) is an equilateral triangle (3,3,4) is an isosceles triangle (3,3,5) is an isosceles triangle (3,4,4) is an isosceles triangle (3,4,5) is a right triangle (3,4,5) is a scalene triangle (3,5,5) is an isosceles triangle (4,4,4) is an equilateral triangle (4,4,5) is an isosceles triangle (4,5,5) is an isosceles triangle (5,5,5) is an equilateral triangle Lab Quiz Part 2: Method CreationFor this part, you should move the code that tests whether (a,b,c) is a triangle of various kinds into separate methods. For example, the isRightTriangle(a,b,c) method should return true if (a,b,c) is a right triangle, and false otherwise. The isTriangle() method does something similar. Thus, you should implement four methods: isRightTriangle(), isScaleneTriangle(), isIsoscelesTriangle(), and isEquilateralTriange(), each of which take in 3 int parameters. Your methods must be public and static, or else your code will not work properly for yourself or for the graders! These methods will be MUCH easier if you ensure that the values passed into the method are already in sorted order (i.e. prior to calling these methods, you ensure that the first parameter is less than or equal to the second parameter, and that the second parameter is less than or equal to the third parameter). Make sure the spelling of your methods is correct! Especially isosceles. And equilateral. If your methods are spelled incorrectly, the grading system will not realize they are there, and you will lose points. Your code in the main() method should then be modified to use your new methods. The program output will be the same. How to ProceedGet the steps working in order! Make sure part 1 works before you move onto part 2. If you don't follow this, you will end up with a mess of code that doesn't work, and you will not be able to fix it within the lab quiz time. There will be partial credit given for this lab quiz -- so if you are unable to handle one triangle type, you can still receive a lot of points for the quiz. Other RequirementsYou are only required to follow a few of the good programming practices discussed in HW J1 (yes, you may follow that link during the lab quiz). If you have time, feel free to do the others -- but due to the time constraints of the quiz, you don't have to do them all. The ones you must do are listed below.
SubmissionWhen you are finished, submit your LabQuiz2.java file. You will have to "sign" a pledge on the submission.
|