Question
Algorithm Workbench java proram 1. Design a class named Pet, which should have the following fields: name. The name field holds the name of a
Algorithm Workbench
java proram
1. Design a class named Pet, which should have the following fields: name. The name field holds the name of a pet. animal. The animal field holds the type of animal that a pet is. Example values are Dog, Cat, and Bird. age. The age field holds the pets age. The Pet class should also have the following methods: setName. The setName method stores a value in the name field. setAnimal. The setAnimal method stores a value in the animal field. setAge. The setAge method stores a value in the age field. getName. The getName method returns the value of the name field. getAnimal. The getAnimal method returns the value of the animal field. getAge. The getAge method returns the value of the age field. a. Draw a UML diagram of the class. Be sure to include notation showing each field and methods access specification and data type. Also include notation showing any method parameters and their data types. b. Write the Java code for the Pet class.
2. Look at the following partial class definition, and then respond to the questions that follow it: public class Book { private String title; private String author; private String publisher; private int copiesSold; } a. Write a constructor for this class. The constructor should accept an argument for each of the fields. b. Write accessor and mutator methods for each field. c. Draw a UML diagram for the class, including the methods you have written.
3. Consider the following class declaration: public class Square { private double sideLength; public double getArea() { return sideLength * sideLength; } public double getSideLength() { return sideLength; } } a. Write a no-arg constructor for this class. It should assign the sideLength field the value 0.0. b. Write an overloaded constructor for this class. It should accept an argument that is copied into the sideLength field.
4. Look at the following description of a problem domain: The bank offers the following types of accounts to its customers: savings accounts, checking accounts, and money market accounts. Customers are allowed to deposit money into an account (thereby increasing its balance), withdraw money from an account (thereby decreasing its balance), and earn interest on the account. Each account has an interest rate. Assume that you are writing an application that will calculate the amount of interest earned for a bank account. a. Identify the potential classes in this problem domain. b. Refine the list to include only the necessary class or classes for this problem. c. Identify the responsibilities of the class or classes.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started