Advertisement
Guest User

Untitled

a guest
Apr 19th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. public class HelloWorld
  2. {
  3. // arguments are passed using the text field below this editor
  4. public static void main(String[] args)
  5. {
  6. Konto klaus = new Konto("Peter Klaus", 1337);
  7.  
  8. System.out.println(klaus);
  9. klaus.einzahlen(20000);
  10. System.out.println(klaus);
  11. klaus.inhaber = "Petra Klaus";
  12. System.out.println(klaus);
  13. klaus.abheben(1500);
  14. System.out.println(klaus);
  15. /*
  16. Error:
  17. klaus.nr = 1;
  18. */
  19. try{
  20. klaus.kontoStand = (int) 1e6;
  21. }catch(Exception a){
  22. System.out.println("Can't change Money");
  23. }
  24.  
  25.  
  26. System.out.println(klaus);
  27.  
  28. }
  29.  
  30. public static class Konto {
  31. public String inhaber;
  32. protected int kontoStand;
  33. public final int nr;
  34.  
  35. public Konto(String inhaber, int nr)
  36. {
  37. this.kontoStand = 0;
  38. this.inhaber = inhaber;
  39. this.nr = nr;
  40. }
  41.  
  42. public void einzahlen(int a){
  43. kontoStand += a;
  44. }
  45.  
  46. public void abheben(int a){
  47. kontoStand -= a;
  48. }
  49.  
  50.  
  51. public String toString()
  52. {
  53. return inhaber+" hat "+ kontoStand+" euro. Nr.: "+ nr;
  54. }
  55. }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement