Java程序辅导

C C++ Java Python Processing编程在线培训 程序编写 软件开发 视频讲解

客服在线QQ:2653320439 微信:ittutor Email:itutor@qq.com
wx: cjtutor
QQ: 2653320439
Lab 2 Multi-dimensional Array and Writing Class
Student Name: ______________________________________________________
TA Initial and Checkout time: ___________________________________________
TA Comments: ______________________________________________________
Prelab: Answer the following questions before working on the lab computers.
CSci112 Fall 2011 Closed Lab Handout! Lab 2, Friday, September 2, 2011
http://www.cs.olemiss.edu/~jxue/teaching/csci112_F11/notes/lab2
Prepared by Jianxia Xue, Last Update Tuesday, August 30, 2011! 1 of 2
1. Write the corresponding statements:
a) Declare a 1D array that can hold 
100 strings
!
    _________________________
b) Set the last element from the 
above array to hold a reference to 
the string “cool”.
!
    _________________________
c) Declare a 2D array that can hold a 
25 by 18 table of float numbers
!
    _________________________
d) Initialize the above declared array 
to be holding the value of 99.9f in 
each and every element.
!
    _________________________
    _________________________
!   _________________________
2. Given a class definition:
class Tiny {
  private int corners;
  public Tiny(){
   corners = 3;
  }
  public String toString(){
   return corners+” corners.”;
  }
}
! How to instantiate a Tiny object?
  ___________________________
 !Can you add a method in the Tiny 
class so that each Tiny object can 
hold different values of corners?
  ___________________________
  ___________________________
  ___________________________
  ___________________________
Coding Tasks
1. Debug BuggyPascalTriangle.java
      The given code of BuggyPascalTriangle.java generates a set of Pascalʼs triangle 
numbers given user specified size . Pascalʼs triangle However, there are 1 syntax and 2 
logical errors that stops the program from compiling and running correctly. Fix the 3 
errors. Try to read the inline comments to learn the intention of the code.
      Make sure that you are in your H: drive course workspace in eclipse, and remember 
to set up a new project of the lab2 before the importing of the source code.
2. Develop MyBuddy.java
      In this task, we will create a class that can be used to simulate BuddyFinder 
application. We will start with a simple abstraction of buddy object by encapsulating two 
instance member fields recording the nick name and subject of interest of a buddy, 
along with a set of methods to allow client instantiation and manipulations of a buddy 
object.
       A template code TemplateOfMyBuddy.java is provided for your reference. You can 
imported it to your “lab2” project in eclipse, then copy and paste the class, rename it to 
“MyBuddy” during the paste operation, and start developing the code. Please read 
through the header and inline comments from the code template to see all the detailed 
requirement.
       A driver main method is provided in the template to utilize the class of MyBuddy. 
Please complete the driver method development to test your MyBuddy class.
3. Optional task (Extra credit) 
      Design and implement a class called Book that contains instance data for the title, 
author, publisher, and copyright date. Define the Book constructor to accept and 
initialize this data. Include setter and getter methods for all instance data. Include a 
toString method that returns a nicely formatted, multiline description of the book. Create 
a driver class called Bookshelf, whose main method instantiates and updates several 
Book objects. (From text PP 5.7)
CSci112 Fall 2011 Closed Lab Handout! Lab 2, Friday, September 2, 2011
http://www.cs.olemiss.edu/~jxue/teaching/csci112_F11/notes/lab2
Prepared by Jianxia Xue, Last Update Tuesday, August 30, 2011! 2 of 2