0

so i'm having issues making this work for me. what this code needs to do is have 3 different (string) fields that then sort them into alphabetical order i've had help before but it wont run on my netbeans. i am currently up to date with all updates as well.

heres the code i have so far

import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;
import java.util.Comparator;

public class test {
private Scanner scan = new Scanner(System.in);
private List<LayoutOfScientist> scientistsNames = new ArrayList<LayoutOfScientist>();
private String name, field, idea;
private boolean continueLoop = true;
private int countTo3 = 0;

private void run() {
    while(countTo3<3&&continueLoop) {
        if(countTo3>0) {
            System.out.println("Would you like to add another scientist? (Y/N)");
        }

        if(countTo3 == 0 || scan.nextLine().equalsIgnoreCase("y")) {
            System.out.println("Please enter the scientist's name:");
            name = scan.nextLine();
            System.out.println("Please enter the scientist's field:");
            field = scan.nextLine();
            System.out.println("Please enter the scientist's idea:");
            idea = scan.nextLine();
            scientistsNames.add(new LayoutOfScientist(name, field, idea));
        } else {
            continueLoop = false;
        }
        countTo3++;
    }

    scientistsNames.sort(Comparator.comparing(LayoutOfScientist::getScientistName));
    for(LayoutOfScientist lOS : scientistsNames) {
        System.out.println(lOS.getScientistName() + ", " + lOS.getScientistField() + ", " + lOS.getScientistIdea());
    }
}

private class LayoutOfScientist {
    private String scientistName, scientistField, scientistIdea;

    private LayoutOfScientist(String scientistName, String scientistField, String scientistIdea) {
        this.scientistName = scientistName;
        this.scientistField = scientistField;
        this.scientistIdea = scientistIdea;
    }

    public String getScientistName() {
        return scientistName;
    }

    public String getScientistField() {
        return scientistField;
    }

    public String getScientistIdea() {
        return scientistIdea;
    }
}

public static void main(String[] args) {
    new Test().run();
}
}
RaymondRay
  • 39
  • 1

1 Answers1

1

Your class name is test (lowercase t) and in your main method, you are calling Test().run(). You need to rename your class to be Test and that should work. Or if your file is test you need to change Test().run() to test().run() instead of public class test to public class test. However, it is good programming practice to name a ClassLikeThis.

If your error is something else entirely, tell us what the error is.

Dan
  • 7,286
  • 6
  • 49
  • 114
ANooBee
  • 165
  • 1
  • 7