Private Proxies – Buy Cheap Private Elite USA Proxy + 50% Discount!Private Proxies – Buy Cheap Private Elite USA Proxy + 50% Discount!Private Proxies – Buy Cheap Private Elite USA Proxy + 50% Discount!Private Proxies – Buy Cheap Private Elite USA Proxy + 50% Discount!
    0
  •   was successfully added to your cart.
  • Home
  • Buy proxies
  • Extra features
  • Help
  • Contact
  • Login
  • 50% OFF
    BUY NOW!
    50
    PROXIES
    $19
    --------------------
    BUY NOW!
    BUY NOW!
    BUY NOW!
    BUY NOW!
    BUY NOW!
    $29
    $49
    $109
    $179
    $299
    --------------------
    --------------------
    --------------------
    --------------------
    --------------------
    PROXIES
    PROXIES
    PROXIES
    PROXIES
    PROXIES
    100
    200
    500
    1,000
    2,000
    TOP SELLER
    BEST VALUE
    For All Private Proxies!

Project description

The program can be tested here

This project is an exercise designed to check if I understand the MVC pattern correctly and apply it correctly.

A quiz is to be designed in which the user should select the correct answer to a question from a given set of answers. If he answers the question correctly, the user receives a point. If he answers incorrectly, the program outputs the points achieved so far and aborts the program execution.

Many tutorials explain the MVC pattern on condition that there is only one class that belongs to the model, and mostly they name it just “Model”. So it is interesting for me to know if I have applied the design pattern correctly with several model classes.

I also tried to comment every field and function of a class as it should be except functions that are self-explanatory.

I’ve also found that to display the data of a class outside of itself requires a lot of data that requires getters and setters that violate the principle of data encapsulation. Is that a weakness of my implementation, or is this a general weakness of the MVC pattern?

Can the controller be equated with something like a main class of a project? Can it include the actual program logic?

The algorithm:

  1. Display a question and its possible answers.
  2. Ask the user for his suggestion.
  3. If he was right: Give the user a point. Go to step 1.
  4. If he was wrong: Exit the program.

Source Files

Main.java

public class Main {     public static void main(String[] args) {         Question[] questionList = {             new Question("In which country Kaiser Wilhelm II was born?",             new String[] {                 "America",                 "Germany",                 "North Korea",                 "England"             }, "B"),              new Question("Which flowers are the most beautiful?",             new String[] {                 "Tulips",                 "Roses",                 "Lilies",                 "Weeping willows"             }, "C"),              new Question("Where does England live?",             new String[] {                 "On an island",                 "Near poland",                 "In the white house",                 "In he yellow house"             }, "A"),              new Question("Who's a free software activist?",             new String[] {                 "Bill Gates",                 "Donald Trump",                 "Richard Stallman",                 "The GNU operating system"             }, "C"),               new Question("Which MMORPG has the most players?",             new String[] {                 "Arthoria.de",                 "Nostale",                 "GTA 5",                 "World of Warcraft"             }, "D")         };          // problem: the players name can not be initialized with functions from controller          // before the controller is initialized         Player player = new Player("");         Questions questions = new Questions(questionList);         View view = new View();          Controller controller = new Controller(player, questions, view);         controller.mainLoop();     }        } 

Player.java

// this class represents a player with a name and a score public class Player {     // represents his name     private String name;     // represents his score      private int score;      // generates a player with a given name and a score of 0     public Player(String name) {         this.name = name;         score = 0;     }      public String getName() {         return name;     }      public int getScore() {         return score;     }      public void setName(String name) {         this.name = name;     }      // increases score of player     public void scorePoint() {         score++;     } } 

Question.java

// this class represents a question with a set of answers public class Question {     // represents the question     private String question;     // represents four possible answers     private String[] answers;     // represents the correct answer with a letter from A to symbol D     private String correctAnswerLetter;      // generates a question and needs a string that contains the question, a string list     // with exactly four answers and a String that has a letter from A to D that points to the      // correct answer, throws IllegalArgumentException     public Question(String question, String[] answers, String correctAnswerLetter) {         if(answers.length > 4) {             throw new IllegalArgumentException("answers can only have four strings");         }         if(!correctAnswerLetter.equalsIgnoreCase("A") && !correctAnswerLetter.equalsIgnoreCase("B")         && !correctAnswerLetter.equalsIgnoreCase("C") && !correctAnswerLetter.equalsIgnoreCase("D")) {            throw new IllegalArgumentException("the letter representing the correct" +            " string can only have a value from A to D");         }          this.question = question;         this.answers = answers;         this.correctAnswerLetter = correctAnswerLetter;     }      public String getQuestion() {         return question;     }      public String[] getAnswers() {         return answers;     }      // checks if the given letter equalsIgnoreCase to the correct letter     public boolean check(String letter) {         return letter.equalsIgnoreCase(correctAnswerLetter);     } } 

Questions.java

import java.util.Random;  // this class manages a list of questions public class Questions {     // represents a collection of questions     Question[] questions;      // generates a set of questions and needs a list of questions     public Questions(Question[] questions) {         this.questions = questions;     }      // returns a random chosen question from the list     public Question getRandomQuestion() {         Random random = new Random();         int selection = random.nextInt(questions.length);         return questions[selection];     } } 

View.java

public class View {     /* methods for question */      public void printQuestion(Question question) {         String[] answers = question.getAnswers();          System.out.println(question.getQuestion() + "\n");         System.out.println("A: " + answers[0]);         System.out.println("B: " + answers[1]);         System.out.println("C: " + answers[2]);         System.out.println("D: " + answers[3]);     }      /* methods for player */       public void printScoreOfPlayer(Player player) {         System.out.println(player.getName() + " has reached " + player.getScore() + " points.");     }      /* methods for general game logic */      public void printNameRequest() {         System.out.print("Your name: ");     }      public void printInputRequest() {         System.out.print("Please chose a letter: ");     }      public void printSuccessMessage() {         System.out.println("That was right!\n");     }      public void printGameOverMessage() {         System.out.println("This was wrong. Game over.");     } } 

Controller.java

import java.util.Scanner;  public class Controller {     private Player player;     private Questions questions;     private Scanner input;      private View view;      public Controller(Player player, Questions questions, View view) {         this.player = player;         this.questions = questions;         input = new Scanner(System.in);          this.view = view;     }      public String getString() {         return input.next();     }      public String getGuessOfPlayer() {         String guess = input.next();         if(!guess.equalsIgnoreCase("A") && !guess.equalsIgnoreCase("B")          && !guess.equalsIgnoreCase("C") && !guess.equalsIgnoreCase("D")) {             throw new IllegalArgumentException("Enter A, B, C or D");         }         return guess;     }      public void mainLoop() {         view.printNameRequest();         player.setName(getString());          while(true) {             Question actualQuestion = questions.getRandomQuestion();              view.printQuestion(actualQuestion);             view.printInputRequest();             String input = getGuessOfPlayer();             if(actualQuestion.check(input)) {                 player.scorePoint();                 view.printSuccessMessage();             } else {                 view.printGameOverMessage();                 view.printScoreOfPlayer(player);                 break;             }         }     } } 

✓ Extra quality

ExtraProxies brings the best proxy quality for you with our private and reliable proxies

✓ Extra anonymity

Top level of anonymity and 100% safe proxies – this is what you get with every proxy package

✓ Extra speed

1,ooo mb/s proxy servers speed – we are way better than others – just enjoy our proxies!

50 proxies

$19/month

50% DISCOUNT!
$0.38 per proxy
✓ Private
✓ Elite
✓ Anonymous
Buy now

100 proxies

$29/month

50% DISCOUNT!
$0.29 per proxy
✓ Private
✓ Elite
✓ Anonymous
Buy now

200 proxies

$49/month

50% DISCOUNT!
$0.25 per proxy
✓ Private
✓ Elite
✓ Anonymous
Buy now

500 proxies

$109/month

50% DISCOUNT!
$0.22 per proxy
✓ Private
✓ Elite
✓ Anonymous
Buy now

1,000 proxies

$179/month

50% DISCOUNT!
$0.18 per proxy
✓ Private
✓ Elite
✓ Anonymous
Buy now

2,000 proxies

$299/month

50% DISCOUNT!
$0.15 per proxy
✓ Private
✓ Elite
✓ Anonymous
Buy now

USA proxy location

We offer premium quality USA private proxies – the most essential proxies you can ever want from USA

100% anonymous

Our proxies have TOP level of anonymity + Elite quality, so you are always safe and secure with your proxies

Unlimited bandwidth

Use your proxies as much as you want – we have no limits for data transfer and bandwidth, unlimited usage!

Superfast speed

Superb fast proxy servers with 1,000 mb/s speed – sit back and enjoy your lightning fast private proxies!

99,9% servers uptime

Alive and working proxies all the time – we are taking care of our servers so you can use them without any problems

No usage restrictions

You have freedom to use your proxies with every software, browser or website you want without restrictions

Perfect for SEO

We are 100% friendly with all SEO tasks as well as internet marketing – feel the power with our proxies

Big discounts

Buy more proxies and get better price – we offer various proxy packages with great deals and discounts

Premium support

We are working 24/7 to bring the best proxy experience for you – we are glad to help and assist you!

Satisfaction guarantee

24/7 premium support, free proxy activation and 100% safe payments! Best reliability private proxies for your needs!

Best Proxy Packs

  • 2,000 Private Proxies $600.00 $299.00 / month
  • 1,000 Private Proxies $360.00 $179.00 / month

Quick Links

  • More information
  • Contact us
  • Privacy Policy
  • Terms and Conditions

Like And Follow Us


Copyright ExtraProxies.com | All Rights Reserved.
  • Checkout
  • Contact
  • Help
  • Home
  • My Account
  • My Cart
  • News
  • Privacy Policy
  • Proxy features
  • Proxy packs
  • Terms and Conditions
Private Proxies – Buy Cheap Private Elite USA Proxy + 50% Discount!
    0 items