0% found this document useful (0 votes)
274 views9 pages

Student's Name: - Bogun Pathmaraj - ID: - 300829172

The document provides instructions for a final lab test in a Java programming course. Students are asked to create a GUI application that allows users to search for student information by city from an Oracle database table. The application should display the results in a scrollable text area. Screenshots and code for the completed application need to be pasted into a Word document along with start and end timestamps. The zipped Java project also needs to be submitted.

Uploaded by

Bogun Pathmaraj
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
274 views9 pages

Student's Name: - Bogun Pathmaraj - ID: - 300829172

The document provides instructions for a final lab test in a Java programming course. Students are asked to create a GUI application that allows users to search for student information by city from an Oracle database table. The application should display the results in a scrollable text area. Screenshots and code for the completed application need to be pasted into a Word document along with start and end timestamps. The zipped Java project also needs to be submitted.

Uploaded by

Bogun Pathmaraj
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

Java Programming COMP-228

CENTENNIAL COLLEGE
COMP 228: JAVA PROGRAMMING
FINAL LAB TEST (Version 3)
Full Marks: 100
Maximum Allowable Time: 4 hours

Student’s Name: __________Bogun Pathmaraj___________________________


ID:_______________300829172____________________________________

Please read the following instructions before you do anything:

You must submit 2 documents in the drop box titled FinalLabTest.

1. MS Word document:
[IN THE BEGINNING OF THIS DOCUMENT, YOU MUST PROVIDE A SCREEN
SHOT OF THE TIME YOU START TO WRITE CODE AND AT THE END, YOU MUST
PROVIDE A SCREEN SHOT OF THE TIME YOU ENDED AND SUBMITTED THE
WORD DOCUMENT.]

Use this document to provide screen shots and code. DO NOT DELETE the Question.

You should take screen shots of the application followed by the complete code that you would
use to develop this application. The screen shots should represent the full functionality of
your application.

Final Lab Test Page 1 of 9


Java Programming COMP-228
You must COPY the code used from the code window and paste the entire code into this
Word document AFTER the screen shots. Do not provide screen shots of your code since it
is hard to read screen shots of the code window.

DO NOT zip the Word document.

DO NOT submit in any file format other than MS Word document.

2. The Java zipped application:


Submit your complete zipped Java application folder in the same drop box.

Exercise 1

Start a new Eclipse Java project. Name the project: YourFullName_COMP228TestFall2016.


For example: JohnSmith_COMP228TestFall2016. DO NOT create a package in this project. Let
Eclipse create the default package.

Write a GUI application in Java that allows user to select students by their city.

The user should be able to enter the city. The application should retrieve the student information
from an Oracle table named Student. Here is the definition of the table:
CREATE TABLE Students (
studentID char(9) NOT NULL,
firstName varchar (20) NOT NULL,
lastName varchar (20) NOT NULL,
address varchar (30) NOT NULL,
city varchar(30) NOT NULL,
province char(2) NOT NULL,
postalCode char(6) NOT NULL,
PRIMARY KEY (studentID)
);
Populate the table with several rows as below:
insert into Students values('300111222','Sam', 'Malone', '10
Somewhere Road', 'Toronto','ON','M1Y2H2');
commit;

Final Lab Test Page 2 of 9


Java Programming COMP-228
The information should be displayed in a JTextArea component which has scrolling abilities.
Use “\t” and “\n” to format the display.

Use the most appropriate layout manager classes to implement the layout of this GUI.

Final Lab Test Page 3 of 9


Java Programming COMP-228

import java.awt.BorderLayout;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;

import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
Final Lab Test Page 4 of 9
Java Programming COMP-228
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.GridPane;
import javafx.stage.Stage;

public class StudentInfo extends Application


{

public static void main(String[] args)


{
Application.launch(args);
}

@Override
public void start(Stage mainStage) throws Exception
{

//Create GridPane
GridPane pane = new GridPane();
pane.setPadding(new Insets(5,5,5,5));
pane.setAlignment(Pos.CENTER_LEFT);
pane.setHgap(20);
pane.setVgap(10);
pane.setPadding(new Insets(25,15,15,15));

//Create TextFields

TextField cityName = new TextField();

//Button
Button update = new Button("Update");

//Create BorderPane
BorderPane border = new BorderPane();

//Set other Panes into designated spaces


border.setCenter(pane);
border.setPrefWidth(400);

//Create JTextArea
JTextArea ta = new JTextArea();
JFrame frame = new JFrame("JTextArea");
frame.getContentPane().setSize(800,400);

JPanel panel = new JPanel();


panel.setLayout(new BorderLayout());

JScrollPane tableContainer = new JScrollPane(ta);

Final Lab Test Page 5 of 9


Java Programming COMP-228
panel.add(tableContainer, BorderLayout.CENTER);

frame.getContentPane().add(panel);

frame.pack();
frame.setVisible(true);

//Add all nodes to panes

Label selectStudents = new Label("Select Students by City ");


pane.add(selectStudents,0,1);
pane.add(cityName,1,1);
pane.add(update, 2, 1);

//Put Pane into Scene

Scene scene = new Scene (border);

//Put Scene into Stage


mainStage.setScene(scene);

// Set the stage title


mainStage.setTitle("Student Information");

// Display the stage


mainStage.show();

//Register The JDBC Driver


System.out.println("Registering JDBC Driver");
DriverManager.registerDriver(new
oracle.jdbc.driver.OracleDriver());
System.out.println("JDBCDriver REGISTERED");

//Connect to the Database


System.out.println("Connect to Database");
Connection conn = DriverManager.getConnection
("jdbc:oracle:thin:@199.212.26.208:1521:SQLD", "COMP228_m22_sy_81", "password");

update.setOnAction((e)->
{

//Retrieve Info
String sql = "SELECT studentID, firstName,
lastName,address,city,province,postalCode FROM Students ORDER BY studentId";

try
{

Final Lab Test Page 6 of 9


Java Programming COMP-228

//create Statement
Statement sql_stmt =
conn.createStatement();

//Execute query

ResultSet result =
sql_stmt.executeQuery(sql);

//Display City Info

String[] array = new String[7];

while (result.next())
{
array[0]=result.getString(1);
ta.append(array[0] + "\t");

array[1]=result.getString(2);
ta.append(array[1] + "\t");

array[2]=result.getString(3);
ta.append(array[2] + "\t");

array[3]=result.getString(4);
ta.append(array[3] + "\t");

array[4]=result.getString(5);
ta.append(array[4] + "\t");

array[5]=result.getString(6);
ta.append(array[5] + "\t");

array[6]=result.getString(7);
ta.append(array[6] + "\n");

//Close the ResultSet

result.close();

//Close statements

sql_stmt.close();

System.out.print("Completed");

conn.close();

Final Lab Test Page 7 of 9


Java Programming COMP-228
} catch (NumberFormatException e1)
{
e1.printStackTrace();
}catch (SQLException e1)
{
e1.printStackTrace();

});

(100
marks)

Evaluation:
Functionality
Correct implementation of UI (using 35%
SWING or JavaFX components, event
handling)

Correct implementation of data access 50%


using JDBC (connecting with server,
executing a prepared statement,
displaying results)
Comments, correct naming of variables, 5%
Final Lab Test Page 8 of 9
Java Programming COMP-228
methods, classes, etc.
Friendly input/output 10%
Total 100%

Final Lab Test Page 9 of 9

You might also like