0

I have a Class and then a made a sub class that would check if the letter "a" is in the string. i don't know how to call the subclass i made. i want to insert the subclass object into a StringDetail array but i keep getting an error. i don't know how i construct the subclass when i try to do it in the for loop i get an error. Thanks for any help.

import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.ArrayList;

public class StringDetail {
private String string;
private int number;
private boolean check;

	public StringDetail (String a) {

		this.string = a;
		number = 0;
		for (int i= 0;i < string.length();i++){
			if( Character.isLetter(string.charAt(i)) && string.charAt(i) > 96){
				number++;
				check = false;
			}			
		}
		
	}	
	
	public int getInt(){
		return number;
	}
	
	public void setBool(boolean set) {
		this.check = set;		
		
	}
	public boolean getBool(){
		return check;
	}
	@Override
	public String toString() {
	return number+"(" + check+"): "+ string;
	}
public class StringMoreDetail extends StringDetail{
	private int numVowels;

	public StringMoreDetail(String a) {
		super(a);
		numVowels = 0;
		for(int i = 0; i < string.length(); i++)
			if(Character.isLetter(string.charAt(i)) == string.equals("a"))
				numVowels ++;
		
			
		
		// TODO Auto-generated constructor stub
	}
	public int getNumVowels(){
		return numVowels;
	}
	
}

	public static void main(String[] args) throws FileNotFoundException {
		ArrayList<String> lines = new InputReader().fileReader();
		//StringMoreDetail []  details= new StringMoreDetail [lines.size()];
	
		StringDetail[] details = new StringDetail[lines.size()];
		for(int i = 0; i < lines.size(); i++) { 
			StringDetail sd = new StringDetail(lines.get(i));
			sd.setBool(sd.getInt() >= i);
			if(i + 1 %3 == 0)
				;//details[i]= StringMoreDetail(sd);
			else	
				details[i] = sd;
			System.out.println(details[i].toString());
			System.out.println();
			
		}
	
		
	}

	


}
1
Contributor
1
Reply
2
Views
7 Years
Discussion Span
Last Post by aodpreacher
0

I tried inserting this new way but i keep getting the same error
This is the error i get in the "StringDetail sdm = new StringMoreDetail(lines.get(i));" line : No enclosing instance of type StringDetail is accessible. Must qualify the allocation with an
enclosing instance of type StringDetail (e.g. x.new A() where x is an instance of StringDetail).

public static void main(String[] args) throws FileNotFoundException {
		ArrayList<String> lines = new InputReader().fileReader();
		
		StringDetail[] details = new StringDetail[lines.size()];
		
		for(int i = 0; i < lines.size(); i++) { 
			StringDetail sd = new StringDetail(lines.get(i));
			
			sd.setBool(sd.getInt() >= i);
			if(i + 1 %3 == 0){
				StringDetail sdm = new StringMoreDetail(lines.get(i));
				details[i]= sdm;}
			else	
				details[i] = sd;
			System.out.println(details[i].toString());
			System.out.println();
			
		}
	
		
	}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.