Question: task 1 Objects and Classes 3 Consider the following code: public class Bicycle { private String owner; public String getOwner() { return this.owner; } }

task 1

Objects and Classes 3

Consider the following code:

public class Bicycle { private String owner; public String getOwner() { return this.owner; } } 

Complete the Bicycle class to allow Bicycle objects to be instantiated with or without specifiying the owner. If the owner is not specified, the owner should be set to "Anonymous". Hint: You need to define two constructors for this class.

public class Bicycle { private String owner; // TODO: add your code here public String getOwner() { return this.owner; } }

task 2

Objects and Classes 4

Assume that we have a class called Box that contains instance data that represents the height, width, and depth of the box. The Box constructor accepts and initializes the height, width, and depth of the box. Complete the following Box class by writing a toString method that returns a one-line description of the box. E.g. 1: if the height is 1, width is 3, and depth is 5, the toString method returns "[1.0,3.0,5.0]". E.g. 2: if the height is 4.4, width is 5.4, and depth is 1.2, the toString method returns "[4.4,5.4,1.2]".

public class Box { private double height; private double width; private double depth; public Box(double height, double width, double depth) { this.height = height; this.width = width; this.depth = depth; } // TODO: add the toString method here }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!