# Practice Questions: Course: OOP cse142Spring 2012 Instructor

```Practice Questions:
Course: OOP cse142Spring 2012
Instructor: Asma Sanam Larik
Problem #1
a. Create a Time class to enter time in military time (24 hours) and then convert and
display the equivalent conventional time (12 hour with AM or PM) for each entry if
it is a valid military time. An error message will be printed to the console if the
entry is not a valid military time.
b. Create a constructor that takes a string military time as input and converts the
string to conventional time in hours and minutes
c. Create a method validMilitaryTime() to check if the time is valid or not
d. Create a method display() to print the hours and minutes on console
Note:
To be a valid time, it should have exactly 5 characters. Next,only digits are allowed in
the first two and last two positions, and that a colon is always used in the middle
position. Next, we need to ensure that we never have over 23 hours or 59 minutes. This
will require us to separate the substrings containing the hours and minutes. When
converting from military time to conventional time, we only have to worry about times
that have hours greater than 12, and we do not need to do anything with the minutes at
all. To convert, we will need to subtract 12, and put it back together with the colon and
the minutes, and indicate that it is PM. Keep in mind that 00:00 in military time is 12:00
AM (midnight) and 12:00 in military time is 12:00 PM (noon).
Problem #2
In this problem we implement a SerialNumber class, which is used by the Home Software
Company to validate software serial numbers. A valid software serial number is in the form
LLLLL-DDDD-LLLL, where L indicates an alphabetic letter and D indicates a numeric digit. For
example, WRXTQ-7786-PGVZ is a valid serial number. Notice that a serial number consists of
three groups of characters, delimited by hyphens.
The fields first, second, and third are used to hold the first, second, and third groups of
characters in a serial number. The valid field is set to true by the constructor to indicate a valid
serial number, or false to indicate an invalid serial number.
a. Create a constructor accepts a string argument that contains a serial number. The string
is split into first, second, and third fields. The validate method is called.
b. Create a isValid method that returns the value in the valid field.
c. Create a validate method that calls the isFirstGroupValid, isSecondGroupValid, and
isThirdGroupValid methods
d. Create isFirstGroupValid method that returns true if the value stored in the first field is
valid. Otherwise false.
e. Create isSecondGroupValid method that returns true if the value stored in the second
field is valid. Otherwise false.
f.
Create isThirdGroupValid method returns true if the value stored in the third field is
valid. Otherwise false.
Problem #3:
Create a class named Student. Students have a running point total, initialized to zero
and have a name.
a. Implement a constructor that creates a new student with the given name
Student(string name)
b. AddPoints(double newPoints): adds the given number of points to students total
c. GetPoints: returns the total points earned
Create a class Course that contains Students array
a. Implement constructor Course(Student[] students) that creates a new course that
the students are taking
b. double average()
Returns the current average total score over all the students enrolled in this course
c. boolean checkOff(Student student, double score)
This method takes a Student and a score as input. If the student is enrolled in the course (that
is, they were in the array passed to the constructor), then this method increments that
student's point total and returns true. Otherwise, if the student is not enrolled, we return false.
----------------------------------- The End ----------------------------
```