Download Lab7

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
CMPT 183 Lab # 7
Objective: At the end of this lab you will be able to




Read a project specification
Write an algorithm (sequential ‘to do’ list for your project)
Modify an existing project to suit your new project
Submit the results
Read a project Specification
In lab 5 you were asked to write a program to compute the square of a number,
which basically involved 1 or 2 variables, some mathematical calculation, and the
output. Some of you choose to include many bells and whistles on your project
including methods, separate classes, and complex calculations; which was very
creative but unnecessary at the time.
You are now faced with 2 programming problems that deal with the original; you
only have to do 1 for the lab. I highly recommend that you try both as
practice, because these two concepts are similar to your homework assignments.
Problem 1:
Suppose we wish to write a program that will let the user square any number
they want, this basically means you need to let the user enter the number from
the keyboard. After the number is squared, give the user the option to run the
program again and again if necessary until they decide to finish. This can be
accomplished using some sort of structure that constantly runs, like you
have learned in class. How can we modify our old program to do so?
Problem 2:
Suppose we wish to write a program that will let the user square or cube any
number they want, this basically means you need to let the user enter a
choice between squaring and cubing as well as the number from the keyboard.
This choice can be made using a decision structure like you learned in class.
How can we modify our old program to do so?
Write an algorithm
Something I have noticed while watching everyone program lab 5 is that almost
everyone jumps immediately into the programming before they understand what
the problem is, let alone how to solve it. Although this method may work and if
you try hard enough it will come to you, there is a far better way to go about
writing programs.
An algorithm is nothing more than a fancy way of saying ‘to do list’. It lets you
state the problem again so you may understand what you want to do. It lets you
identify what variables you will need as well as what type (int, float, string, etc.)
they are. It lets you write a step by step listing of what the program should and
will accomplish.
On the attached sheet there are instructions on how to write an algorithm for each
of these programs. Everyone will fill out this sheet before starting to program.
You will also hand it in, because you will be graded on it. Those who don’t hand it
in will receive an irreversible 0, this should let you know how important this part of
the assignment is to me.
Modify an existing project
Everyone should have done the previous project, and I am sure you have named it
something like Lab5.java or Square.java. Before you open it up and modify the
original, I would like you to make a copy, and they work with the copy. This can
be done by doing the following:
cp
filename.java
Lab7.java
NOTE: I am not sure what YOU have named the file, but
YOU will know what it is called. Replace filename with
what YOU have called the file!
Open the new file Lab7.java, and make the necessary changes for either one of
the two assignments. Test and debug the program until you are satisfied. GET
MY ATTENTION before going to the next part!
Submit the results
By now everyone should know how to create a script file, so from now on I will not
include that information in the lab. For those who still don’t know please practice
making them so you become proficient.
DO NOT overwrite your source file by typing
script Lab7.java
(like many of you have done in the past).
Make a script file like we have done for past labs. Make sure to include the source
file and the output of your program in the script.
Print the script file and hand it in.
Problem 1 Algorithm
Objective: Creating an algorithm for Problem 1





Read problem
Restate problem in simpler terms
Identify variables, their types, and where they come from
Write a sequential list of how to solve the problem
Write brief pieces of JAVA from previous list
Original Problem
Suppose we wish to write a program that will let the user square any number they want,
this basically means you need to let the user enter the number from the keyboard. After the
number is squared, give the user the option to run the program again and again if necessary
until they decide to finish. This can be accomplished using some sort of structure that
constantly runs, like you have learned in class. How can we modify our old program to do
so?
What does this really mean?
Variables we need, what kind are they, and where are they coming from?
1.)
2.)
3.)
4.)
Step by step instructions for the problem
1.)
2.)
3.)
4.)
5.)
6.)
Converting instructions into JAVA
1.)
2.)
3.)
4.)
5.)
6.)
Problem 2 Algorithm
Objective: Creating an algorithm for Problem 2





Read problem
Restate problem in simpler terms
Identify variables, their types, and where they come from
Write a sequential list of how to solve the problem
Write brief pieces of JAVA from previous list
Original Problem
Suppose we wish to write a program that will let the user square or cube any number
they want, this basically means you need to let the user enter a choice between squaring
and cubing as well as the number from the keyboard. This choice can be made using a
decision structure like you learned in class. How can we modify our old program to do so?
What does this really mean?
Variables we need, what kind are they, and where are they coming from?
1.)
2.)
3.)
4.)
Step by step instructions for the problem
1.)
2.)
3.)
4.)
5.)
6.)
Converting instructions into JAVA
1.)
2.)
3.)
4.)
5.)
6.)