1.4-Software-Development-Principles

Terminologie

In deze opdracht ga je een paar theorievragen beantwoorden voor een gegeven stuk code.

Gegegeven is de volgende klasse Terminology:

import java.util.Random;
import java.util.Scanner;

public class Terminology {

    String answer;
    int age;

    public static void main(String[] args) {
        Terminology terminology = new Terminology();
        terminology.start();
    }

    public void start() {
        Scanner scanner = new Scanner(System.in);
        System.out.println("Give your name");
        answer = scanner.nextLine();
        System.out.println("Answer");
        System.out.println("Give your age");
        age = scanner.nextInt();
        if (age >= 18) {
            System.out.println("You are allowed to vote");
        } else {
            int waitToVote = 18 - age;
            System.out.println("You will have to wait" + waitToVote + " years to vote");
            String country = getCountryByIp();
            if (age >= 16 && age < 18 && getCountryByIp().equals("USA")) { // <----------- This line!!!
                System.out.println("But you are allowed to drive a car");
            } else {
                System.out.println("Alas are not yet allowed o drive a car in " + country);
            }
        }
    }

    /**
     * Mock functions to get the country based on the IP address
     *
     * @return the country based on the current IP address
     */
    public String getCountryByIp() {
        String[] countries = {"USA", "NL", "DE", "Uk", "TR", "MA"};
        int selected = new Random().nextInt(6);
        return countries[selected];
    }

}

Vragen

  1. Hoeveel statements zijn er in de klasse Terminologie
  2. Welke expressies zijn er in de klasse Terminologie
  3. Hoeveel conditonal statments zijn er in de klasse Terminologie
  4. Welke declaraties zijn er in de klasse Terminologie
  5. Stel dat de naam “Anthony” en de leeftijd “17” wordt ingevoerd. Wat is dan de toestand van het programma bij de pijl (in de code)?