Question: need help with constructors, accessors, and mutators. Firstly, do I need a void return type stated in the constructor method? Secondly, when I make a

need help with constructors, accessors, and mutators. Firstly, do I need a void return type stated in the constructor method? Secondly, when I make a new class called testGame, I am receiving an error after calling the setHomeScore and getHomeScore methods. Also, the I'm not sure if I did the toString method correctly. here is the code for the Game class.

public class Game {

private int homeScore; private int visScore; private String homeTeam; private String visTeam;

public void constructGame(int hScore, int vScore, String hTeam, String vTeam) { homeScore = hScore; visScore = vScore; homeTeam = hTeam; visTeam = vTeam; } public int getHomeScore() { return homeScore; } public int getVisScore() { return visScore; } public void setHomeScore(int point) { homeScore += point; } public void setVisScore(int point) { visScore += point; } public String toString() { if (homeScore > visScore) return homeTeam + " " + homeScore + " " + visTeam + " " + visScore;

return visTeam + " " + visScore + " " + homeTeam + " " + homeScore; } } Also, here (easier to read): https://pastebin.com/geFEdUGR Here is the code for the testGame class. public class testGame { public static void main(String[] args) { Game test = new Game(); test.setHomeScore(5); System.out.println(test.getHomeScore());

System.out.println(toString());

} } **** When I call toString in main I get the following error: java: non-static method toString() cannot be referenced from a static context

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!