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...
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...
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...
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)
Part I – Understand a Given Class (die class) (40 pts) • Download the die class...
Part I – Understand a Given Class (die class) (40 pts) • Download the die class (attached as usingDieClass.cpp), save it as LabUseDieClassFirstName1_FirstName2.cpp • Add proper opening comments at the beginning of the program. The comments must include the description of all three parts of this lab. You may want to modify the comments after all parts are done to be sure that it is done properly. • Run the program and answer the following questions: o How many objects...
1) Design an implement a program that created and exception class called StringTooLongException, designed to be...
1) Design an implement a program that created and exception class called StringTooLongException, designed to be thrown when a string is discovered that has too many characters in it. Create a driver that reads in strings from the user until the user enters DONE. If a string that has more then 5 characters is entered, throw the exception. Allow the thrown exception to terminate the program 2) Create a class called TestScore that has a constructor that accepts an array...
1.) According to the UML Class Diagram, these are the mutator and accessor methods that you...
1.) According to the UML Class Diagram, these are the mutator and accessor methods that you need to define: 1a.) +setName(value:String):void 1b.) +setGPA(value:double):void 1c.) +setID(value: String):void 1d.) +getName(): String 1e.) +getLastName():String 2.) Working with constructors 2a.) +Student() : This is the default constuctor. For the Strings properties, initialize them to null. The order is String ID, String name, String lastName, and double GPA. 2b.) +Student(value:String) - This constructor receives just the ID. 2c.) +Student(value:String, var: String) - This constructor receives...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT