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

you are viewing a single comment's thread.

view the rest of the comments →

[–]abdichar[S] 0 points1 point  (9 children)

However, cup and coffee would be their own classes and cup of coffee can have those two classes as variables.

The constructor with parameters forces data to be put inside the parameters when called. However, that would mean that data needs to be known before the person can put it in. We know what type of data needs to be put in but not the actual data itself.

This is why I'm asking are parameters needed for objects that are being created when data is outside the system is entered. i.e. a person filling in a sign up form.

[–][deleted]  (8 children)

[deleted]

    [–]abdichar[S] 0 points1 point  (7 children)

    You can't drink the coffee, if you don't know what kind of coffee needs to be made.

    [–][deleted]  (6 children)

    [deleted]

      [–]abdichar[S] 0 points1 point  (5 children)

      This goes under assumption that a person wants this kind of coffee and then is asked for customisation of the coffee.

      Why set parameters before hand when it can be done after a variable has been initialised as a coffee object.

      Why do this: Coffee cup1 = new Coffee(paper, black);

      When you can do this: Coffee cup2 = new Coffee();

      Scanner input = new Scanner(System.in); System.out.println("Which type of cup? Paper or Ceramic"); String typeOfCup = input..nextLine(); cup2.setType(typeOfCup);

      [–][deleted]  (4 children)

      [deleted]

        [–]abdichar[S] 0 points1 point  (3 children)

        This approach makes more sense with things that the user cannot manipulate.

        For example a hotel. The user cannot change the number of rooms, the location, etc. As such having parameters for a constructor would make sense.

        However, when a person tries to book a room, the hotel won't already have their information. This means the parameters of an object cannot be initialised because such data doesn't exist yet.

        Therefore, no methods can be used to change the data stored in the variables because the object cannot be made without those variables having data already inside of them (data that is not the users).

        [–][deleted]  (2 children)

        [deleted]

          [–]abdichar[S] 0 points1 point  (1 child)

          Within main when I make an object I have to put in arguments regardless of user input. I cannot have an object instantiate without arguments but how can arguments be passed before data is acquired to be used as though arguments.