Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java help! Write and test a Java project that satisfies the following requirements: Create a class definition file and a test file as follows: Create

Java help!

Write and test a Java project that satisfies the following requirements:

Create a class definition file and a test file as follows:

Create a class to hold and manipulate data for a Pet for a pet adoption service. The class will have these fields: pet type (a String), pet name (a String), cost to adopt(a double)

Write the following methods for the Pet class:

A default (no-args) constructor A constructor with parameter values for all the field A toString( ) method that uses all the fields. An equals( ) method that is based on pet type and pet name A compareTo( ) method that is based on the cost to adopt

Once the Pet class compiles write a Driver class with the main( ) method.

The main( ) method will declare three Pet reference variables. It will then create the Pet objects reading the data from the file named rescue.txt. The file is comma delimited. (use the StringTokenizer class

After the objects have been created print the state of the three Pet objects using the toString( ) method.

Test the equals( ) method using the first Pet object and the second Pet object. Test the compareTo( ) method by using the first Pet object and the third Pet object. Print the results of these two tests.

(The text file is saved as rescue.txt and the file reads as:

Lab dog,Charley,65.00 Tabby cat,Honey,45.00 Collie dog,Susie,65.00)

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