Professional Documents
Culture Documents
HSYD100 1 Jan Jun2024 FA2 OD V.2 08112023
HSYD100 1 Jan Jun2024 FA2 OD V.2 08112023
Weighting: 25%
Examiner: O.Dyantyi
Total: 50 marks
Instructions:
NB All your answers must be both in a PDF (theory and source code)
and NetBeans project folder (source code for live testing).
1 HSYD100-1-Jan-Jun2024-FA2-OD-V.2-08112023
• A Copyleaks Report will be issued via ColCampus once the assignment is
submitted. Please ensure that you follow the correct steps when uploading your
assignment, to ensure that the Copyleaks Report is correctly issued. You
should be working towards a similarity rating of 30% or less. Where a Copyleaks
Cheat Detection Report is issued, your submission will automatically be treated
as if you received a similarity rating in excess of 30%. Currently, no marks will
be deducted for a similarity rating that exceeds 30%.
1.1 Differentiate between the if statement and the if...else statement in Java. (2 marks)
2 HSYD100-1-Jan-Jun2024-FA2-OD-V.2-08112023
Question 2 [10 marks]
2.1 You're working on a user registration system. Users are required to provide a
password that contains at least one special character. Write a Java program that
inputs a user's password and checks whether it contains at least one special character.
Use the Character class methods to determine if a character is a special character. If
the password is valid, display the message "Password accepted," otherwise, display
"Password must contain at least one special character."
(10 marks)
Paste/write source code
3.1 The following is a Book class and an incomplete program that declares an array
of Book objects to store information about five different books. Provide the missing
code that displays the book list. (4 marks)
3 HSYD100-1-Jan-Jun2024-FA2-OD-V.2-08112023
4. public String getTitle() {
5. return title;
6. }
7. public void setTitle(String title) {
8. this.title = title;
9. }
10. public String getAuthor() {
11. return author;
12. }
13. public void setAuthor(String author) {
14. this.author = author;
15. }
16. public Book(String title, String author) {
17. this.title = title;
4 HSYD100-1-Jan-Jun2024-FA2-OD-V.2-08112023
13. }//end class LibrarySystem
3.2 In your library management system, a user wants to search for a specific book by
its title. Implement a method searchBook that takes the array of Book objects and a
target title as parameters and returns the index of the book if found, or -1 if not found.
(9 marks)
1. public class LibrarySystem {
2. public static void main(String[] args) {
3.3 You want to display the list of books in your library management system
alphabetically by title. Implement the insertion sort algorithm to sort the array of Book
objects based on their titles. (16 marks)
5 HSYD100-1-Jan-Jun2024-FA2-OD-V.2-08112023
1. public class LibrarySystem {
2. public static void main(String[] args) {
3. Book[] books = new Book[5];
4. books[0] = new Book("Java Programming", "John Smith");
5. books[1] = new Book("Data Structures", "Alice Johnson");
6. books[2] = new Book("Machine Learning", "David Williams");
7. books[3] = new Book("Algorithms", "Emily Davis");
8. books[4] = new Book("Web Development", "Michael Brown");
9. MISSING statement? (1 mark)
10. MISSING statement?
11. MISSING statement?
12. MISSING statement?
13. }//end main method
14. MISSING statement? (2 marks)
15. MISSING statement? (2 marks)
16. MISSING statement? (1 mark)
17. MISSING statement? (2 marks)
18. MISSING statement? (2 marks)
6 HSYD100-1-Jan-Jun2024-FA2-OD-V.2-08112023