Advertisement
Randomsurpriseguy

Übung 12-31

Jan 31st, 2018
381
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.54 KB | None | 0 0
  1. package Lösungen;
  2.  
  3. class Date{
  4.     private int Day;
  5.     private int Month;
  6.     private int Year;
  7.    
  8.     boolean C(int x,int a, int b) {
  9.         if (x>b) return false;
  10.         if (x<a) return false;
  11.         else return true;
  12.     }
  13.    
  14.     Date(){
  15.         Day=1;
  16.         Month=1;
  17.         Year=2001;
  18.     }
  19.    
  20.     Date(int D, int M, int Y){
  21.         if(!C(M,1,12)||((M==4||M==6||M==9||M==11)&&!C(D,1,30))||((Y%100==0||Y%4!=0)&&!C(D,1,28)&&(M==2)&&(Y%400!=0))||(Y%4==0)&&(M==2)&&!C(D,1,29)) {
  22.             Day=1;
  23.             Month=4;
  24.             Year=7353;
  25.             System.out.println("Haha, schönes Datum");
  26.             return;
  27.         }
  28.         Day=D;
  29.         Month=M;
  30.         Year=Y;
  31.        
  32.     }
  33.    
  34.     void print() {
  35.         System.out.println(Day+","+Month+","+Year);
  36.     }
  37.    
  38.     boolean equals(Date In) {
  39.         return (In.Day==Day&&In.Month==Month&&In.Year==Year);
  40.        
  41.     }
  42.     boolean yequals(Date In) {
  43.         return (In.Day==Day&&In.Month==Month);
  44.        
  45.     }
  46. }
  47.  
  48. class Person{
  49.     private String Name;
  50.     private Date Geburtstag;
  51.    
  52.     Person(){
  53.         Name="Chin. Fabrikkind";
  54.         Geburtstag=new Date(1,1,2012);
  55.     }
  56.    
  57.     Person(String Nin){
  58.         Name=Nin;
  59.         int a=(int)(Math.random()*10+2000);
  60.         int b=(int)(Math.random()*12+1);
  61.         int c=0;
  62.         if (b==2) {
  63.             c=(int)(Math.random()*28+1);
  64.         }
  65.         if (b==4||b==6||b==9||b==11) {
  66.             c=(int)(Math.random()*30+1);
  67.         }
  68.         if (b==1||b==3||b==5||b==7||b==8||b==10||b==12) {
  69.             c=(int)(Math.random()*30+1);
  70.         }
  71.        
  72.         Geburtstag=new Date(c,b,a);
  73.     }
  74.    
  75.     Person(String Nin,Date Din){
  76.         Name=Nin;
  77.         Geburtstag=Din;
  78.     }
  79.    
  80.     void print() {
  81.         System.out.println(Name);
  82.         Geburtstag.print();
  83.     }
  84.    
  85.     void Namevon() {
  86.         System.out.println(Name);
  87.     }
  88.     void setGbt(Date In) {
  89.         Geburtstag=In;
  90.     }
  91.    
  92.     Person copy() {
  93.         Person Out=new Person(this.Name,this.Geburtstag);
  94.         return Out;
  95.     }
  96.     void copyGeburtstag(Person In) {
  97.         Geburtstag=In.Geburtstag;
  98.        
  99.     }
  100.     void copyName(Person In) {
  101.         Name=In.Name;
  102.     }
  103.    
  104.    
  105. }
  106.  
  107.  
  108. class Kind extends Person{
  109.     private Toy Spielz;
  110.    
  111.    
  112.     Kind(String N){
  113.         super(N);
  114.         Spielz=new Toy("Braunkohle",this);
  115.        
  116.     }
  117.    
  118.     Kind(String N, String T){
  119.         super(N);
  120.         Spielz=new Toy(T,this);
  121.        
  122.     }
  123.    
  124.    
  125.     void print() {
  126.         super.print();
  127.         Spielz.print();
  128.        
  129.        
  130.     }
  131.    
  132.    
  133.     Kind copy(){
  134.         Kind Out=new Kind("Hallo");
  135.         Out.copyName(this);
  136.         Out.copyGeburtstag(this);
  137.         Out.Spielz=this.Spielz;
  138.         return Out;
  139.        
  140.        
  141.        
  142.        
  143.     }
  144.    
  145.     Kind ToyTausch(Kind K2) {//Verändert den wert des Kindes, auf den es angewandt wird und soll gleichgesetzt werden mit dem Kind innerhalb der Methode
  146.         Kind T=K2.copy();
  147.         T.Spielz=Spielz;
  148.         Spielz=K2.Spielz;
  149.         T.Spielz.Update(T);
  150.         Spielz.Update(this);
  151.        
  152.         return T;
  153.        
  154.        
  155.     }
  156.    
  157. }
  158.  
  159.  
  160.  
  161. class Toy{
  162.     private String Bez;
  163.     private Person Own;
  164.     private Person LOwn;
  165.    
  166.     Toy(String In){
  167.         Bez=In;
  168.         Own=new Person();
  169.         LOwn=new Person();
  170.     }
  171.    
  172.     Toy(String In, Person P){
  173.         Bez=In;
  174.         Own=P;
  175.         LOwn=new Person();
  176.     }
  177.    
  178.     void Update(Person New) {
  179.         LOwn=Own;
  180.         Own=New;
  181.     }
  182.    
  183.     void print() {
  184.         System.out.println(Bez);
  185.         System.out.print("Besitzer: ");Own.Namevon();
  186.         System.out.print("Ehemaliger Besitzer: ");LOwn.Namevon();
  187.        
  188.        
  189.     }
  190. }
  191.  
  192.  
  193. public class Übung12 {
  194.    
  195.     public static void main(String[] args) {
  196.        
  197.         /*Date Tag=new Date(29,2,100);
  198.         Tag.print();
  199.        
  200.         Person Kevin=new Person("Kevin");
  201.         Kevin.print();*/
  202.        
  203.         Kind Idiotengruppe[]=new Kind[7];
  204.         int c=0;
  205.         while(c<Idiotengruppe.length) {
  206.             Idiotengruppe[c]=new Kind("Kind"+c+1,"Spielzeug"+c+1);
  207.             c++;
  208.         }
  209.        
  210.        
  211.        
  212.         Kind Sven=new Kind("Sven");
  213.         Sven.print();
  214.        
  215.         Kind Bjoern=new Kind("Bjoern","Lokomotive");
  216.         Bjoern.print();
  217.        
  218.         Sven=Bjoern.ToyTausch(Sven);
  219.        
  220.         Sven.print();
  221.         Bjoern.print();
  222.     }
  223.  
  224. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement