TCSE1PE – Trimester 2 2018
La Trobe Melbourne
Foundation Studies and Diploma Programs
Course: Diploma of Information Technology
Subject Code: TCSE1PE
Subject Name: Programming Environment
Submission
Instructions: See page 4
I declare that the work I am submitting is my own work, and acknowledgement has been made
when citing the words or ideas of others. I have read the Academic Integrity policy and understand
that academic misconduct can incur disciplinary measures such as reduction of marks or zero marks
awarded. Producing assignments in collaboration when the assignment is an individual piece is also
subject to disciplinary action.
Name:
Student ID:
TCSE1PE – Trimester 2 2018
2
Guess the number
Design and implement a Java application to address the following problem description. Your
implementation should be strictly based on your own design and creativity will be
rewarded.
Problem Description
Learning about your outstanding programming skills, the principal of your local primary
school wants you to develop a fun number game for his students.
Student will first input their name and age. The program should then generate a random
number within the following range based on student’s age:
Age (years) Range (inclusive)
4-7 1-25
8-12 1-25
12+ 1-30
For example, if a student is aged 9, the program should generate a random number
between 1 and 15 (inclusive). Hint: You can use the inbuilt Math.random() method to generate a
random number in Java.
Students below 4 years of age are strictly not allowed to continue due to their notorious
history of smudging water colours on the school’s only laptop! The program should exit with
an appropriately stern warning.
Each student should get 10 attempts per game to guess the number. In case of a wrong
attempt, the program should display ‘GO HIGHER!’ if student’s guess is lower than the
number generated or ‘GO LOWER!’ if it is greater. If student makes a correct guess, the
program should score student for the game based on number of attempts required to make
the correct guess.
TCSE1PE – Trimester 2 2018
3
Number of attempts Score (out of 5)
1-3 5
4-6 3
7-10 1
No score is awarded if the student is unable to make a correct guess within the allowed 10
attempts.
After each game, student can either continue playing the game or choose to exit the
program. When the student finally chooses to exit, the program should display the following
overall statistics:
1. Total number of games played
2. Number of games where correct guess was made
3. Overall score of the user in following format -
“Hello Patrick, you scored 12 out of possible 15.”
Bonus Task (10 marks):
Modify your program so that the random number generated is always a prime number.
Hint: A prime number is a number that is divisible only by itself and 1 (e.g. 2, 3, 5, 7, 11).
版权所有:编程辅导网 2021 All Rights Reserved 联系方式:QQ:99515681 微信:codinghelp 电子信箱:99515681@qq.com
免责声明:本站部分内容从网络整理而来,只供参考!如有版权问题可联系本站删除。