Java程序辅导

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

客服在线QQ:2653320439 微信:ittutor Email:itutor@qq.com
wx: cjtutor
QQ: 2653320439
Introduction
Implementation Issues
Some interesting Websites
Writing a Simple Class
CS401 Lab 5: Object-Oriented Programming
Huichao Xue
Department of Computer Science
University of Pittsburgh
Oct 6, 2008
Huichao Xue CS401 Lab4
Introduction
Implementation Issues
Some interesting Websites
Background
What we have learned:
1 Writing simple classes.
2 Instance variables
3 Constructors
4 Accessor methods
5 Mutator methods
Huichao Xue CS401 Lab4
Introduction
Implementation Issues
Some interesting Websites
Write a Rectangle class
1 Write a MyRectangle class by modifying the skeleton of
that file at http://www.cs.pitt.edu/~ramirez/
cs401/labs/MyRectangle.java.
2 Run the “main program” which can be downloaded from
http://www.cs.pitt.edu/~ramirez/cs401/labs/
Lab5.java.
3 Compile “Lab5.java” and run it.
4 Compare your output to http://www.cs.pitt.edu/
~ramirez/cs401/labs/lab5out.txt. Hopefully the
output should be the same as “lab5out.txt”.
Huichao Xue CS401 Lab4
Introduction
Implementation Issues
Some interesting Websites
Instance Variables
There are four instance variables needed:
startX
startY
width
height
Huichao Xue CS401 Lab4
Introduction
Implementation Issues
Some interesting Websites
Constructors
Two should be implemented:
Default Constructor
MyRectangle();
Default Constructor
MyRectangle(int x, int y, int w , int h);
Huichao Xue CS401 Lab4
Introduction
Implementation Issues
Some interesting Websites
Accessors
Three should be implemented:
To calculate the area of the given MyRectangle object.
int area();
Fetch MyRectangle’s information as a string
String toString();
Judge whether a point is in the MyRectangle object or not.
boolean isInside(int X, int Y);
Huichao Xue CS401 Lab4
Introduction
Implementation Issues
Some interesting Websites
Mutators
Two should be implemented:
To alter the size of MyRectangle
void setSize(int newWidth, int newHeight);
Change the position
void setPosition(int newX, int newY);
Huichao Xue CS401 Lab4
Introduction
Implementation Issues
Some interesting Websites
Websites to train yourselves
Project Euler: http://projecteuler.net/index.
php?section=problems
SGU: http://acm.sgu.ru
Huichao Xue CS401 Lab4