In: Computer Science
Part 1 Understand the Problem and Class Design with UML
Part 2 Write the Java code for the class
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());
}
}