Use Java to Write two classes: Fish and FishTank ? You should be able to add up
ID: 3565791 • Letter: U
Question
Use Java to Write two classes: Fish and FishTank
? You should be able to add up to three fish to the tank.
? You can only have one aggressive fish in each tank.
? Allow a user to create and name a fish, specify if it is aggressive and add it
to the tank.
? Each time a user adds a fish, make sure it will fit and is the only aggressive
fish in the tank.
? Allow the user to see all the fish in the tank.
? Allow the user to remove fish from the tank.
? Allow the user to see how long each fish has been in the tank.
Explanation / Answer
import java.io.*;
import java.util.*;
public class Fish
{
String name;
int aggr;
Fish(String name,String aggr1)
{
}
public static void main()
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter a fish name");
Fish.name = sc. nextLine();
System.out.println("Press 1 if aggresive");
Fish.aggr = sc.nextInt();
System.out.println("Name a tank");
String tank= sc. nextLine();
Fishtank valueOf(tank)= new Fishtank(name,aggr);
}
}
public class Fishtank
{
int count =0;
int aggr_flg;
long start_time;
Fishtank (String nme, int flg )
{
int agg=0;
if (flg == 1)
{
agg=1;
}
else
{
System.out.println("can't adjust more than 1 aggresive fish");
break;
}
if (count> 3)
{
System.out.println("tank full");
break;
}
count ++;
start_time= System.currentTimeMills();
System.out.println("Fish name "+nme+" here since "+start_time);
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.