CS代考 ICT167 Principles of Computer Science

ICT167 Principles of Computer Science
Lab Practice Week 8
You need to show working versions of your answers to all questions to your tutor. Your tutor will expect to see them by your next session.
What to submit: your answers to exercises 1, and 2.

Copyright By PowCoder代写 加微信 powcoder

Note: even though you only need to submit those exercises mentioned above, you should attempt all exercises in each lab practice to help broaden your understanding; this may also help with your assignment work.
Do all the programs in NetBeans IDE.
NOTE: Include internal documentation in your code.
Before starting the exercises, make sure you have read the relevant lecture material.
1. Create a MyTime class which is designed to contain objects representing times in 12-hour clock format. Eg: 7:53am, 10:20pm, 12:00am (= midnight), 12:00pm (= noon). You can assume the user will enter times in the format given by the previous examples.
Provide a default constructor, a set method which is given a String (eg: ¡°7:53am¡±), a getHours method, a getMinutes method and a boolean isAm method. Also provide a method for returning a string ¡°morning¡±, ¡°afternoon¡±, ¡°evening¡± or ¡°night¡± appropriate (in your opinion) to the time.
Please see the NOTE below concerning input validation and exception.
2. Write a client program for MyTime which loops around getting strings from the user representing times and responding with a greeting such as ¡°good morning¡± as appropriate. The user should enter the string ¡°quit¡± to exit the program.
EXAMPLE run of client:
USER: 2:07 pm
PROGRAM: good afternoon
USER: 10:71 am
PROGRAM: that¡¯s not a valid time, please re-enter
USER: 14:30am
PROGRAM: that¡¯s not a valid time, please re-enter
USER: 10:21am
PROGRAM: good morning
USER: 7:00 pm
PROGRAM: good evening

ICT167 Principles of Computer Science
NOTE for questions 1 and 2: the set method for MyTime should detect input strings which do not represent valid times. An exception should be thrown in such a case. Clients (such as the one you are writing for question 2) will have to handle (or catch) the exceptions. Thus you will have to also write your own exception class which can be used by MyTime and the client class.

程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com