Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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 < to) {
- while ((to-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);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement