Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package ui;
- import java.util.Scanner;
- /**
- *
- * @author llew870
- */
- public class Oefening5 {
- public static void main(String[] args) {
- Scanner input = new Scanner(System.in);
- System.out.print("Geef de schaal: Celcius of Fahrenheit (C=1 of F=2): ");
- int schaal = input.nextInt();
- System.out.print("Geef de temperatuur (9999 om te stoppen): ");
- int temp = input.nextInt();
- while (temp != 9999) {
- String resultaat = geefTemperatuurStatus(temp, schaal == 1 ? 'C' : 'F');
- System.out.printf("%d graden %s voelt aan als %s%n%n", temp, schaal == 1 ? "Celcius" : "Fahrenheit", resultaat);
- System.out.print("Geef de schaal: Celcius of Fahrenheit (C=1 of F=2): ");
- schaal = input.nextInt();
- System.out.print("Geef de temperatuur (9999 om te stoppen): ");
- temp = input.nextInt();
- }
- }
- // geefTemperatuurStatus - zie oef 2
- private static String geefTemperatuurStatus(int temperatuur) {
- if (temperatuur < 10) {
- return "koud";
- }
- if (temperatuur > 20) {
- return "warm";
- }
- return "lauw";
- }
- // geefTemperatuurStatus
- private static String geefTemperatuurStatus(int temperatuur, char cOfF) {
- if(cOfF == 'F') {
- temperatuur = (temperatuur - 32) * 5 / 9;
- }
- return geefTemperatuurStatus(temperatuur);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement