Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Just started making classes in java and i have been set this task - non graded Just need some help as i am a little

Just started making classes in java and i have been set this task - non graded

Just need some help as i am a little confused on the overall concept - in java on intellij - Thanks

Aims and Objectives

This laboratory has been designed to help you

learn how to define classes which are instantiated in the main method of an application;

gain further practice with defining methods which are only used within a class (object) and those which are intended to be invoked using an object reference.

Task 1

On completion of this task you will have demonstrated the ability to construct

a simple class definition containing instance variables and methods, and

a class containing only a main method which creates an instance of a class (an object) and accesses instance variables, and invokes methods, through a reference to the object. In IntelliJ add the following to the files BoatMaker.java (the Java main class) and Boat.java (the Java class file):

Boat this class contains:

an instance variable, regNum, of type int initialised to -1

an instance variable, bClass, of type String initialised to "unknown"

an instance variable name of type String which is initialised to "unknown"

a method print which does not return a value (i.e. the return type is void), has no formal parameters and prints the boats name, class and registration number. in the following format:

Boat name, Class = bClass, Registration # = KA regNum where the words in italics should be replaced with the values of the corresponding instance variables.

BoatMaker this class contains a main method which performs the following actions:

Prints the message Starting boat application

Defines a variable called myBoat of type Boat and which is initialised to a new Boat object.

Invokes (calls) the print method from myBoat

Compile and run the application from IntelliJ . The following output should be produced: Starting boat application Boat unknown, Class = unknown, Registration # = KA -1

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

Students also viewed these Databases questions