Note that there are some explanatory texts on larger screens.

plurals
  1. POI want to edit the fourth variable of my class, but I seem to edit them all
    primarykey
    data
    text
    <p>What my program does now: </p> <ul> <li>I create a person object with the following information: <code>firstname</code>, <code>lastname</code>, <code>birthdate</code> (the data is different class). </li> <li>The date class, has four variables: day, month, year and 18+ (yes or no). </li> </ul> <p>What does work: I can create a person object with a <code>firstname</code>, <code>lastname</code> and <code>birthdate</code> succesfully. </p> <p>My person class (what looks like it works). </p> <pre><code>public class Person { public String firstName; public String lastName; public Date date; public String toString() { return (firstName + " " + lastName + " (" + date); } public Person(String firstName, String lastName, Date date) { this.firstName = firstName; this.lastName = lastName; this.date = date; } </code></pre> <p>}</p> <p>MY class including my main, where I also have a method where I create my person(s). </p> <pre><code>public static Person setName() { String name; String lastName String inputBirthdate; Date niceDate Date newDate; System.out.println("Firstname:"); firstName = userInput(); System.out.println("Lastname:"); lastName = userInput(); System.out.println("Birthday:"); inputBirthdate = userInput(); niceDate = new Date(inputBirthdate); newDate = new Date(niceDate); return new Gast(firstName, lastName, newDate); } </code></pre> <p>And then I have my Date class, where I check if the input of the date is correct. Please not that I can get my Date class to work correctly WITHOUT the 4th variable. </p> <pre><code>public class Date { public String day; public String month; public String year; public boolean child; public String toString() { return (day + "." + month + "." + year + "." + child); } /*Date(String day, String month, String year, boolean child) { this.day = dag; this.month = month; this.year = year; this.child = child; }*/ //don't need this one, output is the same public Date(Datum niceDate) { int bYear = Integer.parseInt(niceDate.year; int bMonth = Integer.parseInt(niceDate.day); int bDay = Integer.parseInt(niceDate.day); boolean child = false; if (bYear &gt; 1995) { this.child= true; } else if (bYear == 1995 &amp;&amp; bMonth &gt; 10) { this.child = true; } else if (bYear == 1995 &amp;&amp; bMonth == 10 &amp;&amp; bDay &gt; 1) { this.child = true; } else { this.child = false; } } public Date(String birthdate) { String patroon = "\\d{2}-\\d{2}-\\d{4}"; boolean b = birthdate.matches(patroon); if (b) { String[] str = birthdate.split("-"); for (String s: str) this.day = str[0]; this.month = str[1]; this.year = str[2]; } else { System.out.println("Birthday is formatted wrong"); } } </code></pre> <p>}</p> <p>If I run this (witch the check of adult or not (the check looks like it work!), However, my input of the <code>birthdate</code> returns null: </p> <pre><code> Room 1: Name name (null.null.null)false //boolean works, date not Room 2: available </code></pre> <p>I think the problem is that in my second method in my <code>Date</code> class, the <code>public Date(Date Nicedate)</code> deletes my date after parsing it to an int. </p> <p>So basically I only want to return the Boolean and keep my Strings exactly the same, and only editing them for using them as an Int for the calculations. </p> <p>Can someone point me in the right direction? Probably it's a very simple solution, but I've been working on it all day and don't see the solution.</p> <p>EDIT AS REQUESTED: (I've the this statements in the public Date(datum niceDate) but the date still won't show. Hmmmmm: </p> <pre><code>public Date(Datum niceDate) { this.year = year; this.day = day; this.month = month; int bYear = Integer.parseInt(niceDate.year; int bMonth = Integer.parseInt(niceDate.day); int bDay = Integer.parseInt(niceDate.day); boolean child = false; if (bYear &gt; 1995) { this.child= true; } else if (bYear == 1995 &amp;&amp; bMonth &gt; 10) { this.child = true; } else if (bYear == 1995 &amp;&amp; bMonth == 10 &amp;&amp; bDay &gt; 1) { this.child = true; } else { this.child = false; } } public Date(String birthdate) { String patroon = "\\d{2}-\\d{2}-\\d{4}"; boolean b = birthdate.matches(patroon); if (b) { String[] str = birthdate.split("-"); for (String s: str) this.day = str[0]; this.month = str[1]; this.year = str[2]; } else { System.out.println("Birthday is formatted wrong"); } } </code></pre> <p>}</p>
    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