---+ Selection Lab Program: Fall 2026 ---++ Learning Objective(s) * Learn to use constants * Learn to use selection statements * Learn to use random numbers * Learn the syntax of compound statements * Learn to do statement coverage testing * Develop a complete program. ---++ Overview of the Program The program is to pick a random integer within a specified range. The user is allowed to get a number of hints, then must guess the number. Hints the program is to provide: * if it is a multiple of a number specified by the user * if it is higher than another number specified by the user * if it is lower than a third number specified by the user ---++ Specifics * The program is to be called <b>SimpleGuess</b> * Must have a constant <b>MAX</b> that specifies the largest number possible. * Use a <b>Random</b> object to have the computer pick a number * Use at least one compound statement. I suggest two output statements when the user guesses wrong. * One to tell the user that they were wrong. * One to tell the user what the number was. ---++ Sample dialogue Below are some sample dialogues. Your output can vary somewhat as long as the required data is nicely displayed.<br> Dialogue 1: <pre> I have a number between 0 and 50 You will receive 3 hints and then you must try to guess it. I will tell you if it is a multiple of a number. What number do you want me to use? <b><font color="blue"> 5</b><font color="black"> My number is not a multiple of 5 I will tell you if is higher than a number. What number do you want me to use? <b><font color="blue">15<font color="black"></b> My number is higher than 15 I will tell you if is lower than a number. What number do you want me to use? <b><font color="blue">40<font color="black"></b> My number is lower than 40 It is time to guess my number. What do you think it is? <b><font color="blue">34<font color="black"></b> You did not guess it. My number was 31 </pre> Dialogue 2 <pre> I have a number between 0 and 50 You will receive 3 hints and then you must try to guess it. I will tell you if it is a multiple of a number. What number do you want me to use? <b><font color="blue">4<font color="black"></b> My number is a multiple of 4 I will tell you if is higher than a number. What number do you want me to use? <b><font color="blue">37<font color="black"></b> My number is not higher than 37 I will tell you if is lower than a number. What number do you want me to use? <b><font color="blue">33<font color="black"></b> My number is not lower than 33 It is time to guess my number. What do you think it is? <b><font color="blue">36<font color="black"></b> You guessed it! </pre> You can also run a solution for this program if you want. See classroom instructions for more details. ---++Lab Hints * Hint 1: [[%ATTACHURL%/SimpleGuessSolnFlowChart.pdf][a flowchart that you can use]] * Hint 2: [[CSC121F2024Lab02Hint02][Dealing with syntax errors]] * Hint 3: [[CSC121F2024Lab02Hint03][Random numbers]] * Hint 4: Constants: See class examples and notes ---++ Submission * Create a software development report * For the system design, you may use my flowchart if it is the design of your program. Otherwise, you need to make your own. * For testing report, * make sure your tests ensure that each statement is executed at least one. Indicate which options of the select statements each test is covering. * your <b>expected output</b> <font color="red">CANNOT</font> be pasted from the dialogue of a running. Only the actual output may be pasted. * For the improvement section, specify how many points were lost from the last lab that you should not lose points for on this lab because you corrected the problem. * Create a pdf document from your software development report. * Create an empty zip folder * Place *only* !SimpleGuess.java and your pdf document into it * Submit the zip folder on canvas ---++ Optional improvements Optional improvements should ONLY be worked on once the program is completing working. In addition, the work is to be done on your own with little if any help for lab assistants or the instructor. 1. Compare your first lab to the solution. * Explain how they are different. Include * Do the differences matter in terms of producing the correct output? * Do the differences matter in terms of the style required? * Were the any problems with the solution (in terms of correctness, style, etc.) * What have your learned from this comparison about your own programming? * Create a pdf document with your answers and add it to your zip folder
This topic: CenterForComputing
>
WebHome
>
Syllabi
>
CSC121SylF2026
>
CSC121F2026Lab02
Topic revision: r1 - 2026-06-04 - CathyBareiss
Copyright © 2008-2026 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki?
Send feedback