Project 3 Solution

$30.00

Category: Tag:

Description

This programming project involves writing a program to calculate the terms of the following sequence of numbers: 0 1 2 5 12 29 … where each term of the sequence is twice the previous term plus the second previous term. The 0th term of the sequence is 0 and the 1st term of the sequence is 1.

For example:

012->(0+1+2)+2=5

0125->(0+1+2+5)+5=12

012512->(0+1+2+5+12)+12=29

The interface to the program should be a GUI that looks similar to the following:

The pair of radio buttons allows the user to choose whether an iterative or recursive method is used to compute the term of the sequence. When the user enters a value for n and then clicks the Compute button, the nth term of the sequence should be displayed in the Result field. The Efficiency field should contain the number of calls to the recursive method when the recursive option is chosen and the number of iterations of the loop when the iterative option is selected.

The Iterative radio button should be initially set to selected.

When the window is closed, the efficiency values should be computed with values of n from 0 to 10 and written to a file. Each line of the file should contain the value of n, the efficiency of the iterative method for that value of n and the efficiency of the recursive method. The values should be separated by commas so the file can be opened with Excel and used to graph the value of the efficiencies for both the iterative and recursive options along the y axis with the value of n along the x-axis. The graph should be included in the Word document that accompanies this project and should also contain a brief explanation of the observed results.

The program should consist of two classes.

  1. The first class should define the GUI. In addition to the main method and a constructor to build the GUI, an event handler will be needed to handle the Compute button click and another handler will be needed to produce the file described above when the window is closed. The latter handler should be an object of an inner class that extends the WindowAdapter class.

1

  1. The other class should be named Sequence. It should be a utility class meaning that all its methods must be class (static) methods and no objects should be able to be generated for that class. It should contain three public methods:

    1. The first method computeIterative should accept a value of n and return the corresponding element in the sequence using iteration.

    1. The second method computeRecursive should accept a value of n and return the corresponding element in the sequence using recursion. This method will be a helper method because it will need to initialize the efficiency counter before calling the private recursive method that will actually perform the recursive computation.

    1. The third method getEfficiency will return the efficiency counter left behind by the previous call to either of the above two methods.

The google recommended Java style guide, provided as link in the week 2 content, should be used to format and document your code. Specifically, the following style guide attributes should be addressed:

Header comments include filename, author, date and brief purpose of the program. In-line comments used to describe major functionality of the code.

Meaningful variable names and prompts applied. Class names are written in UpperCamelCase.

Variable names are written in lowerCamelCase. Constant names are in written in All Capitals.

Braces use K&R style.

In addition the following design constraints should be followed:

Declare all instance variables private Avoid the duplication of code

Test cases should be supplied in the form of table with columns indicating the input values, expected output, actual output and if the test case passed or failed. This table should contain 4 columns with appropriate labels and a row for each test case. Note that the actual output should be the actual results you receive when running your program and applying the input for the test record. Be sure to select enough different scenarios to completely test the program.

Note: All code should compile and run without issue.

Submission requirements

Deliverables include all Java files (.java) and a single word (or PDF) document. The Java files should be named appropriately for your applications. The word (or PDF) document should include screen captures showing the successful compiling and running of each of the test cases. Each screen capture should be properly labeled clearly indicated what the screen capture represents. The test cases table should be included in your word or PDF document and properly labeled as well.

Submit your files to the Project 3 assignment area no later than the due date listed in your LEO classroom.

You should include your name and P3 in your word (or PDF) file submitted (e.g.

firstnamelastnameP3.docx or firstnamelastnameP3.pdf).

2

Grading Rubric:

The following grading rubric will be used to determine your grade:

Attribute

Meets

Does not meet

GUI Class

40 points

0 points

Defines the GUI

Does not defines the GUI

Contains a pair of radio buttons

Does not contain a pair of radio

allowing the user to choose

buttons allowing the user to

whether an iterative or

choose whether an iterative or

recursive method is used to

recursive method is used to

compute the term of the

compute the term of the

sequence.

sequence.

Allows the user to enter a value

Does not allows the user to

for n and click the Compute

enter a value for n and click the

button, to display the nth term

Compute button, to display the

of the sequence in the Result

nth term of the sequence in the

field.

Result field.

Allows the Efficiency field to

Does not allow the Efficiency

contain the number of calls to

field to contain the number of

the recursive method when the

calls to the recursive method

recursive option is chosen and

when the recursive option is

the number of iterations of the

chosen and the number of

loop when the iterative option

iterations of the loop when the

is selected.

iterative option is selected.

The Iterative radio button is

The Iterative radio button is not

initially set to selected.

initially set to selected.

When the window is closed, the

When the window is closed, the

efficiency values computes with

efficiency values does not

values of n from 0 to 10 and

compute with values of n from

writes them to a file.

0 to 10 and writes them to a

file.

Each line of the output file

contains the value of n, the

Each line of the output file does

efficiency of the iterative

not contain the value of n, the

method for that value of n and

efficiency of the iterative

the efficiency of the recursive

method for that value of n and

method.

the efficiency of the recursive

method.

3

The values of the output file are

The values of the output file are

separated by commas so the file

not separated by commas so

can be opened with Excel.

the file can be opened with

Excel.

Provides an event handler to

handle the Compute button

Does not provides an event

click and another handler will

handler to handle the Compute

be needed to produce the file

button click and another

described above when the

handler will be needed to

window is closed. The latter

produce the file described

handler is an object of an inner

above when the window is

class that extends the

closed. The latter handler is an

WindowAdapter class.

object of an inner class that

extends the WindowAdapter

class.

Code does not Compile.

Sequence class

30 points

0 points

All methods are class (static)

All methods are not class

methods.

(static) methods.

Contains three public methods.

Does not contain three public

methods.

Contains computeIterative

method that accepts a value of

Does not contain the

n and returns the corresponding

computeIterative method that

element in the sequence using

accepts a value of n and returns

iteration.

the corresponding element in

the sequence using iteration.

Contains method

computeRecursive that accepts

Does not contain the

a value of n and returns the

computeRecursive method that

corresponding element in the

accepts a value of n and returns

sequence using recursion.

the corresponding element in

the sequence using recursion.

The computeRecurvise method

will initialize the efficiency

The computeRecurvise method

counter before calling the

does not initialize the efficiency

private recursive method that

counter before calling the

will actually perform the

private recursive method that

recursive computation.

will actually perform the

recursive computation.

The getEfficiency method

returns the efficiency counter

The getEfficiency method does

left behind by the previous call

not return the efficiency

counter left behind by the

4

to either of the above two

previous call to either of the

methods.

above two methods.

Code does not Compile.

Test Cases

10 points

0 points

Test cases are supplied in the

No test cases were provided.

form of table with columns

indicating the input values,

expected output, actual output

and if the test case passed or

failed.

Enough scenarios selected to

completely test the program.

Test cases were included in the

supporting word or PDF

documentation.

Documentation and Style guide

20 points

0 points

Screen captures were provided

No documentation included.

and labeled for compiling your

code, and running each of your

Java style guide was not used to

test cases.

prepare the Java code.

Header comments include

All instance variables not

filename, author, date and brief

declared private.

purpose of the program.

Duplication of code was not

In-line comments used to

avoided.

describe major functionality of

the code.

Does not graph the value of the

efficiencies for both the

Meaningful variable names and

iterative and recursive options

prompts applied.

along the y axis with the value

of n along the x-axis. The graph

Class names are written in

is not included in the Word

UpperCamelCase.

document and does not contain

a brief explanation of the

Variable names are written in

observed results.

lowerCamelCase.

Constant names are in written

in All Capitals.

5

Braces use K&R style.

Declare all instance variables

private.

Avoids the duplication of code.

Graphs the value of the

efficiencies for both the

iterative and recursive options

along the y axis with the value

of n along the x-axis. The graph

is included in the Word

document and contains a brief

explanation of the observed

results.

6


error: Content is protected !!