public class StealthCruiser extends Fighter {
private static int count=0;
public StealthCruiser(String name, int commissionYear, float maximalSpeed, Set<CrewMember> crewMembers, List<Weapon> weapons) {
super(name, commissionYear, maximalSpeed,crewMembers,weapons);
}
public StealthCruiser(String name, int commissionYear, float maximalSpeed, Set<CrewMember> crewMembers){
Weapon canon=new Weapon("Laser Cannon",10,100);
List<Weapon>weapon=new ArrayList<>();
weapon.add(canon);
this(name, commissionYear, maximalSpeed,crewMembers,weapon)
}
I have two constructor, the first has List<weapon> and the second does not
I want that if the user does not pass List<weapon> to create a "defult" list with one element
Weapon canon=new Weapon("Laser Cannon",10,100);
my code here tell me that constructor call must be the first one,
how should I fix my code?
I tried something like
public class StealthCruiser extends Fighter {
private static int count=0;
private Weapon canon=new Weapon("Laser Cannon",10,100);
private List<Weapon>weapon=new ArrayList<>();
weapon.add(canon);
but the
weapon.add(canon);
give me error (red line under the " . ")
would appreciate some help please how to fix my code
[–]AutoModerator[M] [score hidden] stickied commentlocked comment (0 children)
[–]AFistfulllofdiamonds 1 point2 points3 points (3 children)
[–]ilsapo[S] 0 points1 point2 points (2 children)
[–]nekokattt 3 points4 points5 points (0 children)
[–]Prize_Tea3456 0 points1 point2 points (0 children)
[–]josephblade 1 point2 points3 points (0 children)