Question: Part 2 . Data and Methods in Classes Purpose This lab reviews old material and introduces new material. Before you continue with the following problems,
Part Data and Methods in Classes
Purpose
This lab reviews old material and introduces new material. Before you continue with the following problems,
create a new Java project and add the following files: Rectangle.java darr and its driver
NewAndReviewExamples.java darr. Review and run the NewAndReviewExamples.java driver for each case of the
switch statement and observe what happens. After you run each case, take a look at the code used to produce
that result. Use these two files as examples while working on the remaining sections.
Data in Java: Primitives and Objects
Build a small class used to represent a single concept such as a Car or Vehicle.
Make a new Java project and create a new class called
Consider what primitive values a Car should have declared: an int for odometer reading, and Strings for
make and model. Inside your Car class right after the class declaration, define three instance variables for
the odometer, make, and model.
Write a main that instantiates two Cars and prints them out. Hint: Carc new Car; and
System.out.printlnctostring;
Constructors
First, check out the set of constructors provided for you in the
class. Notice how they are overloaded
there are multiple constructors with different parameters to provide flexibility for users of this class. Add to
your class three constructors one default constructor, one to take a
'make', the other to take two
;: a 'make' and a 'model'. Test these constructors by building multiple car in your
driver, calling
each constructor in turn.
This the Implicit Parameter
In the previous section, you created two car objects and observed the addresses of the objects in main by using
with
Next, create a method inside the
class, which prints out the address of the
object using
Call that method on the Car object you built earlier in problem and explain why
the two addresses are the same. If you get stuck take a look at Case in
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
