S
S
Sergey Sergey2021-06-03 11:24:24
Java
Sergey Sergey, 2021-06-03 11:24:24

Where do you need to write the values, when encapsulating, that are in a commented out variable so that they can all be displayed?

public class DayTest {
    public static void main(String[] args) {
        Day d = new Day(days[i]);
System.out.println();
}
}

class Day{
    //int[] days = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
    private int[] days;
    
     public Day(int[]days){
     this.days = days;   
    }
    public void setDays(int[] days){
        this.days = days;
    }
    public int[] getDays(){
        return days;
        }
    public int[] Days(){
        int i = 0;
        for(; i < days.length; i++){
            
        }
        return days;
        }
}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
O
Orkhan, 2021-06-03
Hasanly @azerphoenix

Good afternoon!
Where do you think the value ishould come from here, which you pass to the constructor?

public static void main(String[] args) {
        Day d = new Day(days[i]);
        System.out.println();
}


Where do you need to enter the values, when encapsulating, that are in a commented out variable so that they can all be displayed?

Your question is not entirely clear.
You can initialize a variable when instantiating a class
private int[] days = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

Method names are capitalized. In this case, the method does nothing. The for loop simply iterates over the array and nothing happens inside the loop.
public int[] Days(){
        int i = 0;
        for(; i < days.length; i++){
            
        }
        return days;
        }

V
Vladimir Korotenko, 2021-06-03
@firedragon

After 2 lines. Insert what you have in the comments, well, pass days.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question