You should capitalize names of your classes. After doing that do this in your school class,
Classroom cls = new Classroom();
cls.setTeacherName(newTeacherName);
Also I'd recommend you use some kind of IDE such as eclipse, which can help you with your code for instance generate getters and setters for you. Ex: right click Source -> Generate getters and setters
Answer from ant on Stack OverflowI am new to Java, and am currently studying how to create packages with related classes in Eclipse.
If I create one class (example: Circle) defining the methods ( writing()) I want to use, and another class using those methods, do I have to include a reference to an instance of that class? Here is a code example of what I mean:
public class Circle{
double r;
void wirte() {
Syste.out.println("Hello");
} and in the other class:
public class Circle2{
public static void main(String[] args) {
write();
}} Would that work? Or do I always have to follow that format: classinstance.methodname()?
UPDATE
I did not know I can do something like this
public class GUI(){
//do something
}
public static void main(String[] args){
new GUI();
}This code block worked for me --- thank you for pointing it out.
---------
So my IDE flagged an error at this line in main (from my main class Tic_Tac_Toe)
public static void main(String[] args) {
ColRowLists ttt = new ColRowLists();
char[][] board = new char[3][3];
System.out.println("Welcome to Tic Tac Toe");
userInput(board);
System.out.println("show me your list" + ttt.winOrLose()); //"'winOrLose(java.util.List, java.util.List, java.util.List, java.util.List, java.util.List, java.util.List, java.util.List, ...)' in 'ThirtyMinutes.ColRowLists' cannot be applied to '()'"
}The winOrLose method in question lies in another class ColRowList: https://github.com/morry239/TTT_experiements/blob/master/src/ThirtyMinutes/Tic_Tac_Toe.java
I tried to do something like this, but it did not work obviously:
System.out.println("show me your list" + ttt.winOrLose(List topRow, List midRow, List botRow, List leftCol, List midCol, List rightCol, List diagonal1, List diagonal2);Could anyone kindly point me in the right direction? My main class is here FYI.
You should capitalize names of your classes. After doing that do this in your school class,
Classroom cls = new Classroom();
cls.setTeacherName(newTeacherName);
Also I'd recommend you use some kind of IDE such as eclipse, which can help you with your code for instance generate getters and setters for you. Ex: right click Source -> Generate getters and setters
Try this :
public void addTeacherToClassRoom(classroom myClassRoom, String TeacherName)
{
myClassRoom.setTeacherName(TeacherName);
}