I am working on implementing code using MVC for my class however I am running into an error I cant seem to figure out. The only parts of the assignment I am supposed to change are Model, View, and Controller so the rest of the classes were already completed for us.
When I run the code I get an error in the controller saying:
"error: incompatible types: Student cannot be converted to String view.DisplayOnButton(model.getInfoForStudent(0), 0);"
How do I fix this?
Here is what I have:
Controller -
public class Controller { Model model; View view; public Controller(Model model, View view) { this.model = model; this.view = view; SetViewFromModel(); } public void SetViewFromModel() { view.DisplayOnButton(model.getInfoForStudent(0), 0); view.DisplayOnButton(model.getInfoForStudent(1), 1); view.DisplayOnButton(model.getInfoForStudent(2), 2); } } Model -
public class Model { ArrayList<Student> sts = new ArrayList<>(); public Model() { //creates 3 students MailAddress addr1 = new MailAddress("107 W College Avenue", "State College", "PA", 16801); Student st1 = new Student("Emily", "Smith", 20, addr1); MailAddress addr2 = new MailAddress("200 W College Avenue", "State College", "PA", 16801); Student st2 = new Student("Mary", "Doe", 20, addr2); MailAddress addr3 = new MailAddress("300 W College Avenue", "State College", "PA", 16801); Student st3 = new Student("John", "Doe", 20, addr3); //add them to the array of students sts.add(st1); sts.add(st2); sts.add(st3); } public Student getInfoForStudent (int studentIndex) { return sts.get(studentIndex); } } View -
public void DisplayOnButton(String infoToDisplay, int onButton) { mf.getIp().DisplayOnButton(infoToDisplay, onButton); }
DisplayOnButtonhas a requirement that the parameter must be aString, either change the parameter type or pass in aString