I am struggling with this code I have been writing. I did some research but I could not find a solution.
Here is my full error:
No enclosing instance of type
Project2
is accessible. Must qualify the allocation with an enclosing instance of typeProject2
(e.g. x.new A()
wherex
is an instance ofProject2
).
Here is my full code:
import java.io.*;
import java.util.Scanner;
public class Project2 {
public static void main(String[] args) throws IOException {
SuperheroWithPowers aquaman = new SuperheroWithPowers();
Superhero2 catwoman = new Superhero2();
//Aquaman calls marine life
aquaman.setTelepathy(true);
if (aquaman.getTelepathy()) {
System.out.println("Aquaman calls all marine life around him to help defeat an evil villian!");
}
//Aquaman fights in the depths
aquaman.setAdaptability(true);
if (aquaman.getAdaptability()) {
System.out.println("Aquaman is able to hand very high depths of water due to his ability to adapt to the ocean!");
}
//Aquaman tries to use his super strength
aquaman.setStrength(true);
if (aquaman.getStrength()) {
System.out.println("Aquaman tries to use his super strength but the villian is stronger!");
}
//Aquaman uses the trident
aquaman.setTrident(true);
if (aquaman.getTrident()) {
System.out.println("Aquaman finally defeats his evil foe with his powerful trident!");
}
//Catwoman uses her equipment
catwoman.setEquipment(true);
if (catwoman.getEquipment()) {
System.out.println("Catwoman uses her bola to trip up evil");
}
//Catwoman uses her gymnastics
catwoman.setGymnast(true);
if (catwoman.getGymnast()) {
System.out.println("Catwoman escapes a near death by being very agile");
}
//Catwoman uses judo
catwoman.setJudo(true);
if (catwoman.getJudo()) {
System.out.println("Catwoman has incredible combat skills to take down any foe in her path");
}
//Catwoman uses thief
catwoman.setThief(true);
if (catwoman.getThief()) {
System.out.println("Catwoman is easily able to sneak at night due to her master theif skills");
}
}
class SuperheroWithPowers {
String name;
String alterEgo;
boolean telepathy;
boolean adaptability;
boolean strength;
boolean trident;
//Constructor
public SuperheroWithPowers() {
name = "Aquaman";
alterEgo = "Arthur Curry";
System.out.println("Aquaman created!");
}//End Constructor
//Start setters
public void setTelepathy(boolean x) {
telepathy = x;
}
public void setAdaptability(boolean x) {
adaptability = x;
}
public void setStrength(boolean x) {
strength = x;
}
public void setTrident(boolean x) {
trident = x;
}
//End Setters
//Start getters
public boolean getTelepathy() {
return telepathy;
}
public boolean getAdaptability() {
return adaptability;
}
public boolean getStrength() {
return strength;
}
public boolean getTrident() {
return trident;
}
//End Getters
}//end SuperheroWithPowers
class Superhero2 {
String name;
String alterEgo;
boolean equipment;
boolean gymnast;
boolean judo;
boolean thief;
//Constructor
public Superhero2() {
name = "Catwoman";
alterEgo = "Selina Kyle";
System.out.println("Catwoman created!");
}//end constructor
//Start setters
public void setEquipment(boolean x) {
equipment = x;
}
public void setGymnast(boolean x) {
gymnast = x;
}
public void setJudo(boolean x) {
judo = x;
}
public void setThief(boolean x) {
thief = x;
}
//End setters
//Start getters
public boolean getEquipment() {
return equipment;
}
public boolean getGymnast() {
return gymnast;
}
public boolean getJudo() {
return judo;
}
public boolean getThief() {
return thief;
}
}//End Getters
}//End Superhero2
The point of this assignment is to use constructors which is where I believe I went wrong, but I just can't put my finger on it.