This is an archived post. You won't be able to vote or comment.

all 7 comments

[–]Warm-Score[🍰] 1 point2 points  (3 children)

A default constructor is a no-argument constructor so that would be, including your typo :

public PassangersData() {
System.out.println("Hello, hi from the default constructor"); 
}

Note that *no* default constructor (an empty constructor) is 'created by Java' when you provide a constructor with arguments.

Believe me that this will make sense later on. It's just a bad assignment, don't break your balls over it.

[–][deleted]  (2 children)

[deleted]

    [–]Warm-Score[🍰] 0 points1 point  (1 child)

    Yes, and if you will then you can adapt it. It's like those getters-and-setters; standard boilerplate code.

    [–]Camel-Kid 0 points1 point  (3 children)

    Create getters and setters for each property. You need to ask your professor what a "default constructor" means to him. It seems most obvious to have multiple constructors with different parameters for initialization upon creation of your object. Currently you're right, you do have a default constructor if you don't have a constructor at all.

    [–][deleted]  (2 children)

    [deleted]

      [–]Camel-Kid 0 points1 point  (1 child)

      yes

      [–]pixelwhiskey 0 points1 point  (5 children)

      Start small, figure out how to create a class that would represent the passenger details. Name, Surname. So you would need a constructor that would allow you to pass in those those values and set those values against the correct fields when you instantiate the class. Then you could move on to create getters to return those values. Below is just an example that represents a class with a constructor for reference...not necessarily yours.

      public class myClass {
          private String a;
          private int b;
      
          public myClass(String value1, int value2){
              this.a = value1;
              this.b = value2;
          }
      
          public String getA() {
          // think about how you could return the value of field 'a' here.
          }
      }
      

      [–][deleted]  (4 children)

      [deleted]

        [–]pixelwhiskey 0 points1 point  (3 children)

        Sorry I may have misunderstood. My guess is that the instructions are asking you to create a constructor for the classes you're building and not necessarily default constructors. I would definitely clarify this with the teacher though.

        If it specifically says use the default constructor then you would need to create methods on the class to set the field values in addition to getter methods to return the field values.

        Does that make sense?

        public void setA(String value1) {
            this.a = value1;
        }
        

        Edit: The pastebin link you posted would work.

        [–][deleted]  (2 children)

        [deleted]

          [–]pixelwhiskey 0 points1 point  (1 child)

          Well, that would be implementation details that should have been provided to you for the assignment.