Question

In: Computer Science

Part 1 Understand the Problem and Class Design with UML The client needs a program to...

Part 1 Understand the Problem and Class Design with UML

  • The client needs a program to calculate the age of a tuna fish. The program must store the length of the fish in cm, and the weight of the fish in pounds. To calculate the estimated age of the fish in years multiply the length times the weight then divide by 10000. Design a class based on this word problem.
  • Testing values are 300 cm length, and 1111.12 pounds.

  • Using the word problem above, design a class with the needed fields, one default (no parameter) constructor, and needed methods. Document your design using a detailed UML Class diagram.
  • Note: The calculations used in this word problem are fictional.

Part 2 Write the Java code for the class

  • Follow your UML class diagram and code the class you designed.
  • Use Java coding conventions for identifiers: class, constructor, field, variable, and method names
  • Mark fields private, constructor and methods public.
  • Select and use appropriate data types for the fields as well as method parameters as needed.
  • Comment your code as requested and demonstrated in the course.

Solutions

Expert Solution

Part 1 : UML Class Diagram

Part 2 : Java Code

class Fish
{
    private double length; //in case the length is in decimals
    private double weight; //in case the weight is in decimals
    
    public Fish() //default constructor
    {
        length = 0;
        weight = 0;
    }
    
    public void setLength(double l) // method to set value of private variable length
    {
        length = l;
    }
    
    public void setWeight(double w) // method to set value of private variable weight
    {
        weight = w;
    }
    
    public double getLength() // method to get value of private variable length
    {
        return length;
    }
    
    public double getWeight() // method to get value of private variable weight
    {
        return weight;
    }
    
    public double calcAge()
    {
        double age = length * weight / 10000;
        return age;
    }
    
        public static void main(String[] args) 
        {
                Fish tuna = new Fish(); // initializing and calling constructor
                tuna.setWeight(1111.12);
                tuna.setLength(300);
                System.out.println(tuna.calcAge());
        }
}

Related Solutions

LAB2 PART 1 FOR THE DATA TYPE CLASS: If you do not have UML of class...
LAB2 PART 1 FOR THE DATA TYPE CLASS: If you do not have UML of class Account_yourLastName, you should do that first Basesd on the UML, provide the code of data type class Account_yourLastName to hold the information of an account with account number (String), name (String), balance (double), with no-argument constructor, parameter constructor Also, define some methods to handle the tasks: open account, check current balance, deposit, withdraw, and print monthly statement. At the end of each task we...
C++ 1. Start with a UML diagram of the class definition for the following problem defining...
C++ 1. Start with a UML diagram of the class definition for the following problem defining a utility class named Month. 2. Write a class named Month. The class should have an integer field named monthNumber that holds the number of the month (January is 1, February is 2, etc.). Also provide the following functions: • A default constructor that sets the monthNumber field to 1. • A constructor that accepts the number of month as an argument and sets...
Complete the following class UML design class diagram by filling in all the sections based on...
Complete the following class UML design class diagram by filling in all the sections based on the information given below.         The class name is Boat, and it is a concrete entity class. All three attributes are private strings with initial null values. The attribute boat identifier has the property of “key.” The other attributes are the manufacturer of the boat and the model of the boat. Provide at least two methods for this class. Class Name: Attribute Names: Method...
In java program format Submit your completed UML class diagram and Java file. Part I: Create...
In java program format Submit your completed UML class diagram and Java file. Part I: Create a UML diagram for this assignment PartII: Create a program that implements a class called  Dog that contains instance data that represent the dog's name and age.   define the Dog constructor to accept and initialize instance data.   create a method to compute and return the age of the dog in "person-years" (note: dog age in person-years is seven times a dog's age).   Include a toString...
In java program format Submit your completed UML class diagram and Java file. Part I: Create...
In java program format Submit your completed UML class diagram and Java file. Part I: Create a UML diagram for this assignment PartII: Create a program that implements a class called Dog that contains instance data that represent the dog's name and age. define the Dog constructor to accept and initialize instance data. create a method to compute and return the age of the dog in "person-years" (note: dog age in person-years is seven times a dog's age). Include a...
HW 8-1a   1.)   Referring to the UML class diagram, create a program that utilizes the Student...
HW 8-1a   1.)   Referring to the UML class diagram, create a program that utilizes the Student class. - id : Integer - units : Integer - name : String + Student ( ) : + Student (id : Int, name : String, units : Int) : + ~Student( ) : + setID(id : Integer) : void + setName(name: String) : void + setUnits(units : Integer ) : void + displayRecord() : void 2.)   Include 3 files: -   Source.cpp -   Student.h...
I need a pseudocode and UML for this program. import java.util.Random; public class SortandSwapCount {   ...
I need a pseudocode and UML for this program. import java.util.Random; public class SortandSwapCount {    public static void main(String[] args) {        //Generate random array for test and copy that into 3 arrays        int[] arr1=new int[20];        int[] arr2=new int[20];        int[] arr3=new int[20];        int[] arr4=new int[20];        Random rand = new Random();        for (int i = 0; i < arr1.length; i++) {            //Generate random array...
Training Program: Design a full 12-week periodized training program for the client described in the Client...
Training Program: Design a full 12-week periodized training program for the client described in the Client Profile. Be very specific as you design the training program. This is an opportunity for you to demonstrate your full comprehension of the information and concepts discussed throughout the course. List the types of exercise, duration, sets, reps, rest intervals, and so on. Include the following in your case study submission: A description of your professional responsibilities as discussed in the stages of the...
For this assignment, create a complete UML class diagram of this program. You can use Lucidchart...
For this assignment, create a complete UML class diagram of this program. You can use Lucidchart or another diagramming tool. If you can’t find a diagramming tool, you can hand draw the diagram but make sure it is legible. Points to remember: • Include all classes on your diagram. There are nine of them. • Include all the properties and methods on your diagram. • Include the access modifiers on the diagram. + for public, - for private, ~ for...
Using UML, design a class that allows you to store and print employee information: name, id,...
Using UML, design a class that allows you to store and print employee information: name, id, and hourly_salary. Include the appropriate mutator and accessor methods. Write the code to create the class. Write a test program that instantiates an employee object. After the object is created write the code to give the employee a 3% raise. (IN PYTHON)
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT