Applied
本页目录· 2 条
Rolling Project Part 3
4.1 Loops in Java
Task 2
Write a class called CheckPostCode. The class will ask the user to input a String value, via the keyboard. The class must have the required methods to check if the entered value meets the following criteria:
- Must be exactly 4 characters in length, anything greater than or less than is invalid
- Must be all numeric characters only
- Must classify them based on the first digit as follows:
- if first digit is 0, then NT
- if first digit is 2, then NSW
- if first digit is 3, then VIC
- if first digit is 4, then QLD
- if first digit is 5, then SA
- if first digit is 6, then WA
- if first digit is 7, then TAS
Your class must display the correct state classification based on the above rules. If anytime a rule is not met, it must display the message INVALID POSTCODE to the user.
You must also use a loop to do this, as the user may want to check multiple postcodes. You may decide the exit condition for the user to exit the program, such as 0000 or EXIT or anthing similar.
Last, remember to write your code as reusable methods. Have you seen or written some other methods before that might be reusable here?