Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Spatio Temporal Database Management International Workshop Stdbm 99 Edinburgh Scotland September 10 11 1999 Proceedings Lncs 1678

Authors: Michael H. Bohlen ,Christian S. Jensen ,Michel O. Scholl

1999th Edition

3540664017, 978-3540664017

More Books

Students also viewed these Databases questions