Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 2. 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: Carc1= new Car(); and
System.out.println(c1.tostring());
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 s 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 1, and explain why
the two addresses are the same. If you get stuck take a look at Case 1 in
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle 10g Database Administrator Implementation And Administration

Authors: Gavin Powell, Carol McCullough Dieter

2nd Edition

1418836656, 9781418836658

More Books

Students also viewed these Databases questions