Skip to content
Advertisement

Tag: setter

Do…while is not working in input verification

So I’m trying to do an input verification for my program in java, and I’m trying to do that in this setter: But when I call it and put a wrong name, the do…while does not work and the program just continue Here’s where I call it What am I doing wrong? Answer Maybe that’s because in your catch you

Using set and get methods in java

In my programming class, the teacher said we have to implement a class and use get methods but did not mention set methods in the description. Are they always used or should be used together? This is what I’ve written so far: Answer No, setters are not needed at all when implementing immutable classes/objects: Don’t provide “setter” methods — methods

how to compare 2 set values in the same arraylist in java

I have an arraylist of employees. Within this the id and name are non changeable, while the hours contracted and planned are changeable. I have managed the first 3 questions stated below, but stuck on the last one. Besides the 3 Classe below, i also have the Class Workspace. I have the Class Employee. This exends to Class Specialist And

Setting object attributes via a array list

Basically I am working on a project where certain class attributes and names of classes are stored in a text file. The goal here is to create a list of the objects of a certain data type (in this case Car) listed in the text file (of which I have already done), and then assign these to the data types

Setter methods or constructors

so far I have seen two approaches of setting a variable’s value in Java. Sometimes a constructor with arguments is used, others setter methods are used to set the value of each variable. I know that a constructor initialises an instance variable inside a class once a class is instantiated using the “new” Keyword. But when do we use constructors

Advertisement