Source: Mr. Sanford, BCC
cis73999.doc LAB 9:
Introduction to Arrays Due 11-16-09
Object Oriented Java Programming I
This week we are starting
our study of array
objects. We will be working with an array of integers and an array of Student
objects using the Student class that you created for Lab 8.
Note that the “Sorting and
Displaying Arrays”
sample on the course web page was written as a reference to
assist you in understanding and completing this assignment. Make sure you are
comfortable with the sample reference before you start to design and write the
application file.
This lab also attempts to
reinforce the difference between a member method and a static method. Make sure
that you understand the difference between the displayRectangle
member method in the Rectangle class
sample on the course web page and the displayCar private static method in the CarUser class sample
on the course web page. A member
method is similar to the other member methods (getLength,
setLength, and etc.) and exists in each object that
is instantiated. A member method
must be called via an object (for example r1.getlength(
) ). A private static method can be
created in any class and can be called from another static method in the class
such as the main method (see the CarUser class
sample). In this case the private static
method is being used to reduce the size of the main.
Write a Java application file that will:
1. Declare, instantiate, and
initialize an array of doubles with six elements.
2. Use a for loop to display the contents of each element.
3. Then allow the user to
ask for any element at random to be displayed.
4. Then allow the user to
change the value of any element of their choice.
5. Finally use an enhanced for loop to display the
contents of each element.
***************************************************************************************************************
6. Continue on and declare,
instantiate, and initialize an array of Student objects with four elements.
7. Use a for loop to
display the contents of each element object. Note that contents
includes the name, student number, and grade point average data field
attributes.
8. Then allow the user to
ask for any element at random to be displayed by calling a member method of the student class which
will display the contents of a single object.
9. Then allow the user to
change the grade point average field value for any element of their choice.
10. Assume there is no member method to display
objects. Use an enhanced for loop to
display the contents of each object by calling a private
static method in the same class that contains the main, which will display the contents of a single object.
Notes:
1. Label the end of all
classes, methods, and blocks with a comment.
2. Line up the beginning
brace { and ending brace } vertically for each block.
(i.e. for each class, method, and block)
3. Indent all code between
the beginning and ending braces so that the lineup of braces can be easily
observed.
4.
Include comments at the beginning of every .java source file with the assignment number,
author, date due, and an essay (with paragraphs) at the start of the file
describing the functionality of each class as well as how each class “works”.
User instructions should also be provided. Are there comments
reference important or complex syntax?
5. Insert dividers/separators (i.e. a line of dashes or a line of asterisks) between each method and class.
6. Capture your test results
and paste them into the end of your .java source class file as comments.
7. Submit an electronic copy
of all of your .java source class files for credit. Note that all submissions
should be made as attachments to an email, and sent to the instructor with the
following subject line:
CIS73 Lab x
where x = the lab assignment number. Note that the subject line is case sensitive. All assignments should be submitted on or before the due date for full credit per the course policies.
8. All data output should have data titles.
9. All primitive data should be formatted on output.
10. Prompts should be used for all data input from the keyboard and data should be entered on the same line as the prompt.
11. All code should be tested and included in the test results output.
12. All objects declared and used in the main( ) should be passed to other private static methods (example …a Scanner object) in lieu of recreating them in the private static methods.
13. No methods (including the main) should be more than one screen full long.
14. Note once again that all
duplicate .java files that are submitted for a grade will NOT be graded.
15. If you are having
problems that you and your classmates cannot resolve, you should review the
“Suggestions for Success” on my home page and attempt to resolve them in our 2
hours of lab sessions each week. Note that there are 3 class tutors that are
available in the lab for a total of 10 hours each week plus they are available
by appointment. If all else fails then get back to me via email or make an
appointment with me.....We care about the students that care!
Note there is no substitution for
adequate preparation.