My Code
package com.company;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Tutor tutorOne = new Tutor("Anthony Joshua", "Mathematics", "31", "London, England"); //creating tutor objects until "till here" comment
Tutor tutorTwo = new Tutor("Andy Ruiz", "Physics", "31", "Mexico City, Mexico");
Tutor tutorThree = new Tutor("Vitali Klitschko", "Computer Science", "49", "Saint Petersberg, Russia");
Tutor tutorFour = new Tutor("Ray Leonard", "Mathematics", "64", "North Carolina, USA"); // till here
Tutor[] allTutors = {tutorOne, tutorTwo, tutorThree, tutorFour}; // defining an Array containing all the tutors.
Scanner userInput = new Scanner(System.in); // user input
System.out.println("Enter the subject: "); // the message user sees when program is run
String tutorNeeded = userInput.toLowerCase().nextLine(); // reads input including the space between words
for (int i = 0; i < allTutors.length; i++) { // for loop that iterates over allTutors
Tutor t = allTutors[i];
if (t.subject.contains(tutorNeeded)) {
System.out.println(t.name + "\n" + t.subject + "\n" + t.age + "\n" + t.location); // prints all tutor attributes
}
}
if (tutorNeeded.contains("math")) { // tutorNeeded.contains checks if these letters in this order is present in the user input
System.out.println(tutorOne.name+"\n"+tutorOne.subject+"\n"+tutorOne.age+"\n"+tutorOne.location); // prints attributes for tutor one.
}else if (tutorNeeded.contains("physics")) {
System.out.println(tutorTwo.name+"\n"+tutorTwo.subject+"\n"+tutorTwo.age+"\n"+tutorTwo.location);
} else if (tutorNeeded.contains(("computer"))) {
System.out.println(tutorThree.name + "\n" + tutorThree.subject + "\n" + tutorThree.age + "\n" + tutorThree.location);
} else if (tutorNeeded.contains("accounts")){
System.out.println(tutorFour.name + "\n" + tutorFour.subject + "\n" + tutorFour.age + "\n" + tutorFour.location);
} else {
System.out.println("Sorry, we don't have any tutors for that subject available at this time.");
}
}
static class Tutor { // defining second class
String name; // defining properties of object tutors
String subject;
String age;
String location;
Tutor(String name, String subject, String age, String location) { // Tutor constructor to define objects used above
// "this" refers to current instance of the current class
this.name = name;
this.subject = subject;
this.age = age;
this.location = location;
}
}
}
My University Professor says that this code has only one class. I understand that all the code is in one Main class, but wouldn't the Tutor Class also be counted as another class? Making it 2 classes in this code?