Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java Main topics: Multiple Classes Declaring / Using Instance Variables Driver Classes SMouse Program: public class SMouse { private int age = 0; private double

Java

Main topics:

Multiple Classes

Declaring / Using Instance Variables

Driver Classes

SMouse Program:

public class SMouse

{ private int age = 0; private double weight = 1.0;

public void grow() { this.weight += 0.2 * this.age; ++this.age; }

public void display() {

} }

SMouseDriver Program:

import java.util.Scanner;

public class SMouseDriver

{

public static void main(String[] args)

{

Scanner stdIn = new Scanner(System.in);

SMouse mighty = new SMouse();

SMouse mickey = new SMouse();

System.out.println("");

System.out.println("");

System.out.println("");

stdIn.close();

}

}

Exercise We will be practicing with writing and managing multiple classes, including a designated driver class.

Getting Started To start this exercise, you should:

1. Open eclipse and start a new Java project named Lab01

2. Add a Class (named SMouse) to this project, and copy the contents of the SMouse file provided into it.

3. Add a Class (named SMouseDriver) to this project, and copy the contents of the SMouseDriver file provided into it

Requirements

SMouse: A simplified version of the books mouse class that is incomplete. You must do the following to finish the class:

1. Write the body of the display instance method, so that it displays both the age and weight (in some reasonable format) of the specific mouse whos display method is invoked.

2. Remember with in an instance method, this is an available instance variable that refers to the specific object whos method is being invoked.

3. Look for and fix any compilation errors.

4. Remember that you can not run this class, there is no main method.

SMouseDriver: A simple driver class to test your mouse class, that is also incomplete. You must do the following to finish the class:

1. Declare a variable that will hold the age of Mighty Mouse, prompt for this age and read it in to your variable.

2. grow Mighty Mouse this number of times.

3. display Mighty Mouses new age and weight.

4. Declare a variable that will hold the age of Mickey Mouse, prompt for this age and read it in to your variable.

5. grow Mickey Mouse this number of times.

6. display Mickey Mouses new age and weight.

7. Compile build the class and fix any errors.

8. Run your driver class and check the output and make sure it is correct.

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

Database And Expert Systems Applications 24th International Conference Dexa 2013 Prague Czech Republic August 2013 Proceedings Part 1 Lncs 8055

Authors: Hendrik Decker ,Lenka Lhotska ,Sebastian Link ,Josef Basl ,A Min Tjoa

2013 Edition

3642402844, 978-3642402845

More Books

Students also viewed these Databases questions