|
Lecture Notes Two: Classes and Objects
|
The fundamental programming unit of the Java programming language is the class.
The lecture notes for today (on Classes and Objects) can be found here:
They belong to a larger set of documents some of which are summarized below (with URLs).http://www.cs.indiana.edu/classes/a201-dger/spr2002/lectures/Eleven.html
Lecture Notes One http://www.cs.indiana.edu/classes/a201-dger/spr2002/lectures/One.html)
Lecture Notes Two
http://www.cs.indiana.edu/classes/a201-dger/spr2002/lectures/Two.html)
Lab One:
Getting Started http://www.cs.indiana.edu/classes/a201-dger/spr2002/labs/One.html)
Lecture Notes Three
http://www.cs.indiana.edu/classes/a201-dger/spr2002/lectures/Three.html)
Lecture Notes Four
http://www.cs.indiana.edu/classes/a201-dger/spr2002/lectures/Four.html)
Lab Two:
Some simple programs, some sample problems
http://www.cs.indiana.edu/classes/a201-dger/spr2002/labs/Two.html)
Homework Assignment One
http://www.cs.indiana.edu/classes/a201-dger/spr2002/assignments/A1.html)
Lecture Notes Five
main http://www.cs.indiana.edu/classes/a201-dger/spr2002/lectures/Five.html)
Lecture Notes Six
http://www.cs.indiana.edu/classes/a201-dger/spr2002/lectures/Six.html)
Lab Three:
Basic programs. Simulating decisions. Working with objects
http://www.cs.indiana.edu/classes/a201-dger/spr2002/labs/Three.html)
Lecture Notes Seven
http://www.cs.indiana.edu/classes/a201-dger/spr2002/lectures/Seven.html)
Lecture Notes Eight
http://www.cs.indiana.edu/classes/a201-dger/spr2002/lectures/Eight.html)
Lab Four:
Classes and objects
http://www.cs.indiana.edu/classes/a201-dger/spr2002/labs/Four.html)
Homework Assignment Two
http://www.cs.indiana.edu/classes/a201-dger/spr2002/assignments/A2.html)
Lecture Notes Nine
http://www.cs.indiana.edu/classes/a201-dger/spr2002/lectures/Nine.html)
Lecture Notes Ten
http://www.cs.indiana.edu/classes/a201-dger/spr2002/lectures/Ten.html)
Lab Five:
Wrap-up of Classes and Objects material
http://www.cs.indiana.edu/classes/a201-dger/spr2002/labs/Five.html)
Lecture Notes Eleven
http://www.cs.indiana.edu/classes/a201-dger/spr2002/lectures/Eleven.html)
Lecture Notes Twelve
http://www.cs.indiana.edu/classes/a201-dger/spr2002/lectures/Twelve.html)
Lab Six:
Nested loops, other loops, loops and a half, scalable letters
http://www.cs.indiana.edu/classes/a201-dger/spr2002/labs/Six.html)
Homework Assignment Three
http://www.cs.indiana.edu/classes/a201-dger/spr2002/assignments/A3.html)
Lecture Notes Thirteen
http://www.cs.indiana.edu/classes/a201-dger/spr2002/lectures/Thirteen.html)
Lecture Notes Fourteen
http://www.cs.indiana.edu/classes/a201-dger/spr2002/lectures/Fourteen.html)
Lab Seven:
Loops, Strings, StringTokenizers.
http://www.cs.indiana.edu/classes/a201-dger/spr2002/labs/Seven.html)
Lecture Notes Fifteen
http://www.cs.indiana.edu/classes/a201-dger/spr2002/lectures/Fifteen.html)
Lecture Notes Sixteen
http://www.cs.indiana.edu/classes/a201-dger/spr2002/lectures/Sixteen.html)
Homework Assignment Four
http://www.cs.indiana.edu/classes/a201-dger/spr2002/assignments/A4.html)
Lecture Notes Seventeen
http://www.cs.indiana.edu/classes/a201-dger/spr2002/lectures/Seventeen.html)
Lecture Notes Eighteen
http://www.cs.indiana.edu/classes/a201-dger/spr2002/lectures/Eighteen.html)
Lab Eight:
Procedures (Methods)
http://www.cs.indiana.edu/classes/a201-dger/spr2002/labs/eEight.html)
Lecture Notes Nineteen
http://www.cs.indiana.edu/classes/a201-dger/spr2002/lectures/Nineteen.html)
Lecture Notes Twenty
http://www.cs.indiana.edu/classes/a201-dger/spr2002/lectures/Twenty.html)
Lab Nine:
Working with Methods and Arrays
http://www.cs.indiana.edu/classes/a201-dger/spr2002/labs/Nine.html)
Lecture Notes Twenty-One
http://www.cs.indiana.edu/classes/a201-dger/spr2002/lectures/TwentyOne.html)
Lab Ten:
http://www.cs.indiana.edu/classes/a201-dger/spr2002/labs/Ten.html)
(http://www.cs.indiana.edu/classes/a201-dger/)
Here's the problem for today. This problem has several parts:
Vehicle class that has fields for
(at least) current speed, current direction in degrees, and owner
name.
Vehicle class for the
highest Vehicle Identification Number issued, and a non-static
field that holds each vehicle's ID number.
main method for your Vehicle class that
creates a few vehicles and prints out their field values. Note that
you can also write a separate tester program as well.
Vehicle. A no-arg constructor
and one that takes an initial owner's name. Modify the tester program from
the previous step and test your design.
Vehicle class private,
and add accessor methods for the fields. Which fields should have methods to
change them and which should not?
changeSpeed method that changes the current speed
of the vehicle to a passed-in value, and a stop method that
sets the speed to zero.
turn methods to Vehicle. One that
takes a number of degrees to turn, and one that takes simply either a
Vehicle.TURN_LEFT or a Vehicle.TURN_RIGHT
constant. Define the two constants accordingly.
Vehicle that returns the highest
identification number used so far.
toString method to Vehicle.
main method.
Here's a collection of problems of increasing difficulty, to be used as a starting point:
http://www.cs.indiana.edu/classes/a201-dger/spr2002/labs/warmups.html)
http://www.cs.indiana.edu/classes/a201-dger/spr2002/labs/warmsols.html)
http://www.cs.indiana.edu/classes/a201-dger/spr2002/labs/problems.html)
http://www.cs.indiana.edu/classes/a201-dger/spr2002/labs/probsol.html)
http://www.cs.indiana.edu/classes/a201-dger/sum2000/quizzes/Three2001.html)
http://www.cs.indiana.edu/classes/a201-dger/sum2000/quizzes/Three2001S.html)
http://www.cs.indiana.edu/classes/a201-dger/spr2001/assignments/SetTwo2001.html)http://www.cs.indiana.edu/classes/a201-dger/spr2001/assignments/setTwoSolutions2001.html)
http://www.cs.indiana.edu/classes/a201-dger/sum2001/labs/RodS.html)
http://www.cs.indiana.edu/classes/a201-dger/sum2001/lectures/ifs.html)
http://www.cs.indiana.edu/classes/a201-dger/sum2001/lectures/ifsSol.html)
http://www.cs.indiana.edu/classes/a201-dger/sum2001/lectures/pIfs.html)
http://www.cs.indiana.edu/classes/a201-dger/sum2001/lectures/pIfsSol.html)
http://www.cs.indiana.edu/classes/a201-dger/spr2002/labs/Eight.html)
http://www.cs.indiana.edu/classes/a201-dger/spr2001/lectures/practical.html)
http://www.cs.indiana.edu/classes/a201-dger/spr2001/practical.html)
The URL for this module:
(http://www.cs.indiana.edu/classes/a348/CTED/moduleFour/)
A348/A548/T540/NC010