Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need a Model-View-Controller program that takes in two integers and counts fro

ID: 3630936 • Letter: I

Question

I need a Model-View-Controller program that takes in two integers and counts from one to the other, displaying each number. I can figure out the driver class, I just need the Model-View-Controller.

Explanation / Answer

import java.util.Scanner; class Model { public int takeInput(View view) { Scanner sc = new Scanner(System.in); view.printText("Enter input: "); int input = sc.nextInt(); return input; } } class Controller { public void count(int from, int to, View view) { String s = "Printing numbers from " + from + " to " + to + "."; view.printText(s); if (from = 0) { view.printText(new Integer(from).toString()); from++; } } else { while ((from-to) >= 0) { view.printText(new Integer(from).toString()); from--; } } } } class View { public void printText(String a) { System.out.println(a); } } public class MainClass { public static void main(String[] args) { /* Instantiate all the required classes */ Model model = new Model(); Controller controller = new Controller(); View view = new View(); /* Call model method to take input */ int a = model.takeInput(view); int b = model.takeInput(view); /* Call controller method to run the required process */ controller.count(a, b, view); } }
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote