Person.java 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import java.util.Calendar;
  2. import java.util.GregorianCalendar;
  3. /*
  4. * To change this template, choose Tools | Templates
  5. * and open the template in the editor.
  6. */
  7. /**
  8. *
  9. * @author LH
  10. */
  11. public class Person
  12. {
  13. private String name,beruf,lieblingsfarbe,lieblingstier;
  14. private int geburtsjahr;
  15. private float koerpergröße;
  16. public Person() throws Exception
  17. {
  18. this.name = InteractiveIO.promptAndRead("Name:");
  19. this.beruf = InteractiveIO.promptAndRead("Beruf:");
  20. this.lieblingsfarbe = InteractiveIO.promptAndRead("Lieblingsfarbe:");
  21. this.lieblingstier = InteractiveIO.promptAndRead("Lieblingstier:");
  22. this.geburtsjahr=InteractiveIO.promptForInt("Geburtsjahr:");
  23. this.koerpergröße = InteractiveIO.promptForFloat("Körpergröße:");
  24. }
  25. public String toString()
  26. { //FICK DICH JAVA
  27. String alter = (((Calendar)new GregorianCalendar()).get(Calendar.YEAR)-geburtsjahr)+"";
  28. return "Name: "+name+"\n"+
  29. "Beruf: "+beruf+"\n"+
  30. "Lieblingsfarbe: "+lieblingsfarbe+"\n"+
  31. "Lieblingstier: "+lieblingstier+"n"+
  32. "Alter: "+alter+"n"+
  33. "Größe: "+koerpergröße;
  34. }
  35. public static void main(String[] args) throws Exception
  36. {
  37. Person p1=new Person(),p2=new Person();
  38. InteractiveIO.write(p1+"");
  39. InteractiveIO.write(p2+"");
  40. }
  41. }