Question: Problem 1: Write a Java class to model a Ball. A ball has a color and radius (established initially when a ball object is created).
Problem 1:
Write a Java class to model a Ball. A ball has a color and radius (established initially when a ball object is created). Include getter and setter methods, a toString method, an equals method (balls are equal if they have the same radius and color) and a compareTo method (based on radius alone). The Ball class should include methods to compute (and return) the balls circumference, surface area and volume. It should also include a static variable to store a count of the number of Ball objects created. Write a test class to create a few balls and test their methods. Make sure you print a count of the number of balls created (using the static variable).
Problem 2:
Design a Message class to represent an e-mail message. A message has a recipient, a sender and message text. Your class should have the following methods:
A constructor that accepts the sender and recipient
An append method that appends a line of text to the message body
A toString method that turns the message into a long string such as From: Luke
Skywalker%nTo: Darth Vader%nText: Are you sure youre my father?
Then design a Mailbox class to store e-mail messages. This class should support the following methods:
public void addMessage(Message m)
public Message getMessage(int i)
public void removeMessage(int i)
Write a simple menu-driven application to test these classes. It should provide these menu options:
New message - prompts the user to enter all message information Delete message - prompts for the message index and deletes that message View message - prompts for the message index and then displays the message List messages - displays all messages Quit
Note: Each class should be in its own file. All classes should be contained in one BlueJ project.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
