80.9k views
2 votes
Create a class called teachers, for which assign the ID to be 400 and the consecutive numbers to be displayed for each teachers and the three instances name, program, and courses, using the proper methods, constructors, and variables, display the names of the three students and the instances on the screen. Execute and show the result

1 Answer

2 votes

Final answer:

To create a class called 'teachers', use variables, constructors, and methods. Declare instance variables for ID, name, program, and courses. Create a constructor and display method, and execute the code to show the result.

Step-by-step explanation:

To create a class called 'teachers', you can use variables, constructors, and methods in Java. Begin by declaring an instance variable 'ID' and assigning it the value 400. Then, create 'name', 'program', and 'courses' as instance variables. Write a constructor that takes in the name, program, and courses as parameters and assigns them to the respective instance variables. Next, create a method called 'displayInfo' that displays the names of the three teachers and their respective instances on the screen.

Here's an example of how the code could look like:

public class Teachers {
private int ID = 400;
private String name;
private String program;
private String courses;

public Teachers(String name, String program, String courses) {
this.name = name;
this.program = program;
this.courses = courses;
}

public void displayInfo() {
System.out.println("Name: " + name);
System.out.println("Program: " + program);
System.out.println("Courses: " + courses);
System.out.println("ID: " + ID);
}

public static void main(String[] args) {
Teachers teacher1 = new Teachers("John", "Math", "Algebra");
Teachers teacher2 = new Teachers("Emily", "Science", "Biology");
Teachers teacher3 = new Teachers("David", "English", "Literature");

teacher1.displayInfo();
teacher2.displayInfo();
teacher3.displayInfo();
}
}

User Hans Passant
by
8.9k points