Right click on each of these:
and choose Save Target As... (or Save Link As...) and save the files in the src folder of your project.
Student
objects to represent data describing 15 different students.
The output is printed in a JTextArea
GUI
component using several append method calls. MUPanel
class, change the first element in the array (element 0) so
that it represents you. Change "Samantha Student" to your
name, change the dorm to your residence hall (or use "off-campus" if
you don't live in a residence hall), specify a code number that
indicates your current class (1=Freshman, 2=Sophomore,
3=Junior, 4=Senior), specify a Boolean
value
indicating whether or not you are an intercollegiate athlete, and put in a
decimal number representing your GPA (you may use your
actual GPA or a made-up value, as you wish).Student
objects. Then add
instantiations for a sixteenth and a seventeenth student in
the fillArray()
method that represents either
friends of yours, or made-up people (could be your favorite
historical figures, athletes, movie stars, etc.). displayEntireArray()
method, then
paste a copy of this code immediately after the method, and then change the name of the
newly copied method to displaySophomores
.displaySophomores
method so that it only
processes students in the array that are Sophomores (have a
classCode
value of 2). To do this, place an if
statement immediately inside the for
loop, and
test to see if the result of the getClassCode()
method called for element number k
of the studentRoster
array is equal to 2. Only if this test evaluates as true
should the student in position k
of the array
be printed and her gpa added to the
total. Also, edit the text strings in this second block so
that the first line printed by the block is "Listing of
Sophomores".MUPanel
constructor method
to invoke this method; it should be invoked AFTER displayEntireArray
has
been invoked. Run the program now; you should see
two sets of output lines in the JTextArea: the original list of
all students, and a second list showing only those students
who are Sophomores.String
for equality, use .equals("McMaster Hall")
-- don't use
the ==
operator for the test).MUPanel
constructor method to invoke these methods.Right click on MUPanel.java and choose Save Target As... (or Save Link As...) to save the file in the src folder of your project.
MUPanel
,
displayEntireArray
and fillArray
try
to use an array of Book
objects, and the Book
class definition is not supplied. Your task for this step of
the lab is to provide a complete class definition for a Book
class, that allows the program to run correctly.Book
class must have three (3) private
data members: a String
for the book's title, a
String
for the book's author, and an Integer
for the number of pages in the book. You must write a
minimum of three methods for this class: a constructor
method (to see the order of the parameters for the
constructor, refer to the statements in fillArray
that call the constructor), a method named getNumPages()
that returns the number of pages in a Book
object, and a toString()
method that returns a
String
formatted in this format:
title_of_book, by author_of_book, has number_of_pages pages.When you have correctly written the
Book
class
definition, you should obtain output that looks like this screen shot image.
when you run the program.Book
class: an Integer
value representing the copyright
year for the book, and a Boolean
value
representing whether the book is a hardback book or not. If
we do this, we'll also need to modify the constructor method
of the class, so that it accepts two more parameters of the
appropriate type, and stores those parameter values in the
new private data members. MUPanel
class (as well as
displayArray
and fillEntireArray)
will
also need some modifications. For each book, you'll need to
specify two more pieces of information when the book is
instantiated. Use these values:Title | Copyright Year | Hardback? |
---|---|---|
War and Peace | 1864 | true |
Gone With The Wind | 1936 | true |
Using Java | 2011 | false |
Autobiography of a Yogi | 1953 | false |
Computing Unbound | 1992 | false |
Heaven Help Us | 1996 | false |
Computer Systems | 2010 | true |
toString()
method for the Book
class should be changed as follows: after forming the string
as you did above, concatenate
the string " (c) ", followed by the copyright year for the
book, followed by a semicolon and a space. Then, using an if/else
statement, concatenate the string "Hardback" to the answer String if the hardback
private data member is true, or the string "Paperback" if
the hardback
private data member is false.Book
class definition and MUPanel
, you should
obtain output that looks like this screen shot image
when you run the program. append()
method calls in displayEntireArray
and add if
statements to the for
loop so that the program calculates the totals and produces
the output shown in this final screen shot.