Note that there are some explanatory texts on larger screens.

plurals
  1. POCompare two objects, and return string. But one object doesn't take parameters?
    primarykey
    data
    text
    <p>This is homework. </p> <p>GOAL: I want to compare the date of two objects to decide whether my person object is an adult or not and store this in a string. </p> <p>The strange thing is, all my values of date d1 are 0; </p> <pre><code>public class Date { public int day, month, year; public String child Date(date d1, date d2) { if ((d1.year - d2.year &gt; 18) || ((d1.year - d2.year == 18) &amp;&amp; (d2.year&gt; d1.year)) || ((d1.year - d2.year == 18) &amp;&amp; (d2.year == d1.maand) &amp;&amp; (d2.day &gt; d1.day))) { child = adult; } else { child = child; } Date(int a, int b, int c) { a = year; b = month; c = day; } Date (String birthdate) { String pattern = "\\d{2}-\\d{2}-\\d{4}"; boolean b = birthdate.matches(pattern); if (b) { String[] str = birthdate.split("-"); for (String s: str) this.day = Integer.parseInt(str[0]); this.month = Integer.parseInt(str[1]); this.year = Integer.parseInt(str[2]); this.child = false; } else { System.out.println("Wrong format"); } } </code></pre> <p>When I make a test, this happens: </p> <blockquote> <pre><code> System.out.println("D1 year = " + d1.year); System.out.println("D1 day = " + d1.day); System.out.println("D1 month = " + d1.month); </code></pre> </blockquote> <pre><code>Result: D1 year = 0 D1 day = 0 D1 month = 0 </code></pre> <p>Why does this happen? Lets look at my other class. </p> <p>My other class, where my method infoPerson is located is as following: </p> <pre><code> public static Person infoPerson() { String name, lastname, birthdate; Datum birthday, today; System.out.println("Firstname:"); name = userInput(); System.out.println("Lastname:"); lastname = userInput(); System.out.println("Birthdate?:"); birthdate = userInput(); //here I send the string birthdate to my Date class birthday = new Date(birthdate); today = new Date(3, 7, 2013); //Here I want to compare my two Date objects, today and birthday. This is were I got stuck, how do I do this correctly? dateChild = new Date(today, birthday); // here i send the new date to my Person class what consists of two strings and Data birthday return new Gast(name, lastname, dateChild); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload