Part A Question 1
Write a program to generate a rippled version of an image as it would look in a pond of water with ripples. For example, the sunflower image on the left, when rippled, would look like the image on the right.
Write a method:
private Picture ripple ( Picture oPic, double k ) {
which produces the ripple effect by, for each pixel in the column (c), selecting the pixel in the same
column but in row: 𝑟𝑟 + 𝑘𝑘 𝑠𝑠𝑠𝑠𝑠𝑠 �𝜋𝜋 𝑐𝑐 � where r is the row index, k is a ripple factor (the larger the 20
more rippling) and c is the column index. If the resulting row index is less than zero use 0, and if it is greater than the height-1, use height-1.
Load an image and display it. When the user presses OK, create the ripple image and present it. When the user presses Close, save the ripple image.
For submission, use the image file sunflowers.jpg in the folder Files on the desktop with a ripple factor (k) of 10.0. When the final image is displayed, select File/Print Image of Window… as output for your submission. When prompted, save the image as sunflowers_ripple.jpg in the folder Lab_Exam_A.
revised: 2019-04-01
Part A Question 2
Write a Java program to produce an accent effect on a picture. The effect is to accent one particular color by changing all other colors to monochrome (grayscale). For example, the image on the right is the accented version of the image on the left with BLUE accented.
The program should load a picture and then present it. When the user presses OK, it will generate the accented image with accent color BLUE and present the result. When the user presses Close, it should save the accented image.
Write a method:
private Picture accent ( Picture pic, Color c, double tol ) {
which produces a new picture in which each pixel whose color distance from the Color c is smaller than tolerance tol is the original color in pic and each pixel whose color distance from c is greater than or equal to tol is set to monochrome (i.e. grayscale—each color channel is the average of the three color channels of the pixel in pic).
For submission, run the program using the file bird.jpg in the Files folder on the desktop as input. When the final image is displayed, select File/Print Image of Window… as output for your submission. When prompted, save the image as bird_accent.jpg in the folder Lab_Exam_A.
revised: 2019-04-01
Part A Question 3
Write a Java program that creates a pop art (think Andy Warhol) version of an image such as the following:
Original Pop Art
The pop art version is twice the width and height of the original and consists of four copies of the original each in a different random color.
The process to create a version of the original in a random color is as follows. Choose a random color (remember there are 16,777,216 different colors) as the “new” color. For each pixel in the original image, determine its luminance (average of the color components). Express this as a proportion of maximum luminance (i.e. 255). Set the pixel in the new image to the equivalent luminance in the “new” color (i.e. each channel to the same proportion of luminance of the new color).
Write a method:
private void fill ( Picture nPic, int x, int y, Picture oPic ) { that fills in the Picture new, starting at top left corner position (x,y), with a copy of the
Picture orig in a randomly chosen color.
The program should display the original picture in a PictureDisplayer that sizes to the picture loaded. When the user presses Close, it creates the pop art image and displays it in PictureDisplayer that sizes to the picture.
For submission, run your program using the file jenny-red.jpg in the folder Files on the desktop as input. When the final image is displayed, select File/Print Image of Window… as output for your submission. When prompted, save the image as jenny-red_pop.jpg in the folder Lab_Exam_A.
revised: 2019-04-01
Part B Question 1
To keep track of student performance, a text file (ASCIIDataFile) is maintained containing the marks obtained by the students on the pieces of work submitted (two assignments, a test and an exam). The first line in the file has the course name (String). Then there is one line (record) for each student containing: student number (String), student name (String), assignment 1 mark (double), assignment 2 mark (double), test mark (double), exam mark (double). Initially a zero is entered for each mark for each student. As each piece of work is marked, a program is run that reads the current file, allows the instructor to enter the mark for the piece of work (say test) and writes a new updated file (i.e. with the test mark filled in) For example, with
assignment 2 the file might look like:
Then, after the program to enter the mark in the test is run, the updated file might look like:
The program uses an ASCIIPrompter with the label set to the student id to input the mark for the student in the piece of work (say test), such as:
It then updates the mark for the piece of work and writes out the updated student record. Write a method:
private void writeRecord ( String stNum, String name, double a1,
double a2, double test, double exam ) {
to write the student record (line) to the new student data file.
For submission, run your program using the file stdData.txt in the Files folder on the desktop as input. When prompted tor marks, enter the test marks (column 5 in the figure above). When prompted, save the resulting file as newStdData.txt in the folder Lab_Exam_B. Open the output file in Notebook by double-clicking the file. Print the file as output for your submission,
revised: 2019-04-01
Part B Question 2
Write a java program to summarize weather measurements on a daily basis. A file contains measurements for a number of days. For each day it contains the following: date (String), day (String) followed by 24 hourly temperature measurements (int).
The program should produce a report (ReportPrinter) summarizing the temperature data as follows:
Write a method:
private void doDay ( String date, String day ) {
that reads the temperature data for one day, computes the high, low and average for the day and prints the information to the report.
For submission, run the program using the file weather.txt in the folder Files on the desktop. Print the generated report as output from your program.
revised: 2019-04-01
Part B Question 3
Pizza Express is a pizza restaurant. It sells pizzas in three sizes with a selection of 3 toppings. They need an application to allow customers to place orders for pizza on-line.
The application should present a form such as follows:
The user selects the size and toppings by clicking the radio buttons and checkboxes and then presses Order. The information about the pizza is written to the Order text area and the total price so far is displayed in the Total text field. Ordering continues, adding entries (pizzas) to the Order text area and displaying the updated total in the Total text field, until the user presses Done at which point the application terminates.
Write a method:
private double compute ( ) {
that computes the cost of the pizza as selected by reading the radio buttons and checkboxes. The base price for a small pizza is $5.00, a medium is $10.00 and a large is $15.00. The toppings cost: pepperoni: $0.25, mushrooms: $0.50 and bacon: $0.75.
For submission, run your program to order a medium with pepperoni and bacon, a small with bacon and a large with pepperoni, mushrooms and bacon. When you have ordered the three pizzas, select File/Print Image of Window… as output for your submission. Press Done to terminate the program.
revised: 2019-04-01