mercredi 19 septembre 2018

Basic JAVA app with setters and setters and increment an integer by 1

I'm just blanking on what to do next.

What I need to do:

The class should have the variables name, breed, age, and color

A constructor that sets all the variables

Getters and Setters for all the variables

A main method that creates an instance of the Dog and utilizes the constructor

You can pick values you feel appropriate for the variables

Increase the dog's age by 1

Print all the values to the screen

Heres what I've done.

public class DOG {
    String DogName;
    String DogBreed;
    int DogAge;
    String DogColor;

public DOG(String name, String color, String breed, int age) {
    this.DogName=name;
    this.DogColor=color;
    this.DogBreed= breed;
    this.DogAge=age;

}

public static void main(String[] args) {
    DOG myDog = new DOG("Ares","Red","Rott",5);

    System.out.println(myDog.DogName+" " + myDog.DogColor+ " " + myDog.DogAge+ " " + myDog.DogBreed);

}

public void addOnetoAge() {
    if(DogAge >=6 DogAge++);
}

public String getDogName() {
    return DogName;
}

public void setDogName(String dogName) {
    DogName = dogName;
}

public String getDogBreed() {
    return DogBreed;
}

public void setDogBreed(String dogBreed) {
    DogBreed = dogBreed;
}

public int getDogAge() {
    return DogAge;
}

public void setDogAge(int dogAge) {
    DogAge = dogAge;
}

public String getDogColor() {
    return DogColor;
}

public void setDogColor(String dogColor) {
    DogColor = dogColor;
}
if(int i=1; i <= myDog.DogAge: i++) {
        System.out.println(myDog.DogAge);
    };

}

}

I'm just getting back into java and have forgotten what goes where. I would be grateful for a bit of direction

Aucun commentaire:

Enregistrer un commentaire