You are on page 1of 10

Technological Institute of the Philippines

938 Aurora Blvd. Cubao, Quezon City

College of Computer Studies

ITE 012 – Computer Programming 2

Midterm Period
Selection Control Structure

Name: SURNAME, FIRSTNAME MI Date:


Program / Section: Instructor: Ms. Arceli F. Salo
Assessment Task: Practice Exercise 3.4
Instructions:

Submission Requirement
1. Document the exercise by taking a screenshot of the program output.
2. Zip the following files. Name the folder LastnameFirstnameModule3Exercise3_4.
 Java Files (.java)
 Exercise Documentation
Directions:

Create a Java Project that exhibits the following properties.


1. Create a package in the LibraryManagementSystem project named
module3_exercise3_4.selectioncontrolstructure.
2. Create a class. Name the class Catalogue.
3. Include the following comments at the outset of your code using the java style comment.
 Lastname, Firstname
 Course and Section :
 Date :
 Topic :
4. Copy the following classes used in the previous exercises.
 Book
 Author
 Borrower
5. Overwrite the default constructors of the above-listed classes. Use all attributes of each
class as parameters of the new constructors.
6. Instantiate the classes in Catalogue class.
7. Use the switch selection control structure and JOptionPane class showInputDialog
method to enter the attribute values of a selected class(i.e. Book).
8. Use if-else if selection control structure and JOptionPane class showMessageDialog
method to display the attribute values of a selected class. (i.e. Book).
9. Save and compile your class.
10. Submit a softcopy of your output using the exercise template.
11. Submit your java files.
12. Include Honor Pledge.

Answer:
AUTHOR

package module3_exercise3_4.selectioncontrolstructure;

import java.io.*;

public class Author

public static int authorId;

public static String lastName;

public static String firstName;

public Author (int authId, String authLastName, String authFirstName) {

authorId = authId;

lastName = authLastName;

firstName = authFirstName;

}
BORROWER

package module3_exercise3_4.selectioncontrolstructure;

import javax.swing.JOptionPane;

public class Borrower {

private static int BorrowerId;

private static String LastName;

private static String FirstName;

public static int getBorrowerId() {

return BorrowerId;

public static String getLastName() {

return LastName;

public static String getFirstName() {

return FirstName;

public Borrower(int BorrowerId, String LastName, String FirstName) {

Borrower.BorrowerId = BorrowerId;

Borrower.LastName = LastName;

Borrower.FirstName = FirstName;

BOOK

package module3_exercise3_4.selectioncontrolstructure;
import java.io.*;
import java.util.Scanner;
import javax.swing.JOptionPane;

public class Book {

public static int bookId;


public static String title;
public static String ISBN;
public static String category;

public Book (int bookId, String title, String ISBN, String category){

Book.bookId = bookId;
Book.title = title;
Book.ISBN = ISBN;
Book.category = category;
}
}

CATALOGUE

package module3_exercise3_4.selectioncontrolstructure;

import javax.swing.JOptionPane;

public class Catalogue {

public static void main(String[] args) {

String anotherq = "";

int step = 1;

Boolean another = true;

Boolean invalid = false;

while (another) {

switch (step) {

case 1:

Author authorInfo = new Author(Integer.parseInt(JOptionPane.showInputDialog(null,


"Please enter author ID")),
JOptionPane.showInputDialog(null, "Please enter author's last name"),

JOptionPane.showInputDialog(null, "Please enter author's first name"));

step++;

case 2:

Book libro = new Book(Integer.parseInt(JOptionPane.showInputDialog(null,"Please Enter


Book ID: ")),

JOptionPane.showInputDialog(null,"Please Enter Book Title: "),

JOptionPane.showInputDialog(null, "Please Enter Book ISBN: "),

JOptionPane.showInputDialog(null, "Please Enter Book Category: "));

step++;

case 3:

Borrower borr = new Borrower(Integer.parseInt(JOptionPane.showInputDialog(null,


"Please enter the borrower's ID: ")),

JOptionPane.showInputDialog(null, "Please enter the borrower's last name: "),

JOptionPane.showInputDialog(null, "Please enter the borrower's first name: "));

step++;

if (step == 4) {

JOptionPane.showMessageDialog(null, "You have entered:\n" + "Book ID: " + Book.bookId


+ "\nBook Title: " +

Book.title + "\nISBN: " + Book.ISBN + "\nCategory: " + Book.category + "\n\n" +


"Author ID: " +

Author.authorId + "\nAuthor's Last Name: " + Author.lastName + "\nAuthor's First


Name: " +

Author.firstName + "\n\n" + "Borrower's ID: " + Borrower.getBorrowerId() +


"\nBorrower's Last Name: " +

Borrower.getLastName() + "\nBorrower's First Name: " + Borrower.getFirstName());

else if (step < 4) {


JOptionPane.showMessageDialog(null, "Error! Fill all fields first!");

anotherq = JOptionPane.showInputDialog(null, "Do you want to enter another book?


Please type y or n.");

do {

if (anotherq.equalsIgnoreCase("y")) {

step = 1;

else if (anotherq.equalsIgnoreCase("n")) {

another = false;

else {

invalid = true;

anotherq = JOptionPane.showInputDialog(null, "Invalid Input! Please enter y or n.");

while (invalid);

OOUTPUT

You might also like