Advertisement
Guest User

Untitled

a guest
Dec 17th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package ui;
  7.  
  8. import java.util.Scanner;
  9.  
  10. /**
  11. *
  12. * @author llew870
  13. */
  14. public class Oefening5 {
  15.  
  16. public static void main(String[] args) {
  17. Scanner input = new Scanner(System.in);
  18.  
  19. System.out.print("Geef de schaal: Celcius of Fahrenheit (C=1 of F=2): ");
  20. int schaal = input.nextInt();
  21. System.out.print("Geef de temperatuur (9999 om te stoppen): ");
  22. int temp = input.nextInt();
  23. while (temp != 9999) {
  24. String resultaat = geefTemperatuurStatus(temp, schaal == 1 ? 'C' : 'F');
  25. System.out.printf("%d graden %s voelt aan als %s%n%n", temp, schaal == 1 ? "Celcius" : "Fahrenheit", resultaat);
  26.  
  27. System.out.print("Geef de schaal: Celcius of Fahrenheit (C=1 of F=2): ");
  28. schaal = input.nextInt();
  29. System.out.print("Geef de temperatuur (9999 om te stoppen): ");
  30. temp = input.nextInt();
  31. }
  32. }
  33.  
  34. // geefTemperatuurStatus - zie oef 2
  35.  
  36. private static String geefTemperatuurStatus(int temperatuur) {
  37. if (temperatuur < 10) {
  38. return "koud";
  39. }
  40. if (temperatuur > 20) {
  41. return "warm";
  42. }
  43. return "lauw";
  44. }
  45.  
  46. // geefTemperatuurStatus
  47. private static String geefTemperatuurStatus(int temperatuur, char cOfF) {
  48. if(cOfF == 'F') {
  49. temperatuur = (temperatuur - 32) * 5 / 9;
  50. }
  51. return geefTemperatuurStatus(temperatuur);
  52. }
  53.  
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement