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

example programs of getter and setter in java
getter and setter method in java example
getter and setter for array in java
getter and setter in java - geeksforgeeks
getter and setter in java javatpoint
getter and setter methods for arraylist in java
alternative to getters and setters java
constructor getter and setter in java example

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

Java Getter and Setter: Basics, Common Mistakes, and Best , In this post, we take a closer look at getter and setter methods in Java, and setter is one of the ways to enforce encapsulation in the program's code. Mistake #1: You have setter and getter, but the variable is declared in a  The naming of setter and getter can be done by using the Java bean naming convention. They are as follows: getXxx() and setXxx() where Xxx is the name of the variable.

Edit your method for adding 1 to DogAge instead of

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

use

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

also, don't forget to call your addOnetoAge() method when it's time to add 1 to DogAge

Setter and Getter Methods in Java, Published in the Java Developer group Getters and setters - 1 public class Cat { public String name; public int age; public int weight; As a result, the program has objects with an invalid state (such as this cat that is -1000 years old)​. As you can see, they look pretty simple :) Their names often consist  Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information. Learn more Accessing variables from another classes with setter and getter JAVA

You need to place your main method outside of the Dog class. This should work.

public class MainApplication
{
    public static void main(String[] args)
    {
       Dog goodBoy = new Dog("Milou", "Wire Fox Terrier", 6, "White");
       System.out.println(goodBoy.getDogName() + " " + goodBoy.getDogBreed() + " " + goodBoy.getDogAge() + goodBoy.getDogColor());
    }

}

class Dog
{
    private String dogName;
    private String dogBreed;
    private int dogAge;
    private String dogColor;

    public Dog(String dogName, String dogBreed, int dogAge, String dogColor)
    {
        this.dogName = dogName;
        this.dogBreed = dogBreed;
        this.dogAge = dogAge;
        this.dogColor = dogColor;
    }

    public String getDogName()
    {
        return dogName;
    }

    public void setDogName(String dogName)
    {
        this.dogName = dogName;
    }

    public String getDogBreed()
    {
        return dogBreed;
    }

    public void setDogBreed(String dogBreed)
    {
        this.dogBreed = dogBreed;
    }

    public int getDogAge()
    {
       return dogAge;
    }

    public void setDogAge(int dogAge)
    {
        this.dogAge = dogAge;
    }

    public String getDogColor()
    {
        return dogColor;
    }

    public void setDogColor(String dogColor)
    {
        this.dogColor = dogColor;
    }

    public void increaseAge()
    {
        this.dogAge++;
    }
}

Better, Faster, Lighter Java, Example 1-1. public void increment( ) { int i=getCount(); i++; setCount(i); } public void clear() It accesses two member variables through getters and setters, the counter value called clear and increment, that reset and increment the counter, respectively. For such a simple class, we've got an amazing amount of clutter. JavaScript Accessors (Getters and Setters) ECMAScript 5 (2009) introduced Getter and Setters. Getters and setters allow you to define Object Accessors (Computed Properties). JavaScript Getter (The get Keyword) This example uses a lang property to get the value of the language property. // Create an object: firstName: "John", lastName : "Doe",

Agile Business Rule Development: Process, Architecture, and JRules , Process, Architecture, and JRules Examples Jérôme Boyer, Hafedh Mili. class Policy extends . getters and setters // getters and setters public int getPolicyNumber() {} public Date Roughly speaking, to apply rules to Java application objects using a JRules rule engine, we need to do the following: 1. Create the rule  The meaning of Encapsulation, is to make sure that "sensitive" data is hidden from users. To achieve this, you must: provide public get and set methods to access and update the value of a private variable. You learned from the previous chapter that private variables can only be accessed within the same class (an outside class has no access to it).

Spring Persistence with Hibernate: Build Robust and Reliable , and Reliable Persistence Solutions for Your Enterprise Java Application Ahmad Reza Seddighi. Using identical primary keys The first strategy for mapping a one-to-one class Student { private int id; private Phone phone; //​other fields and getter/setter <id nameI"id" typeI"int" columnI"ID"> <generator classI"increment"/>  In Java getters and setters are completely ordinary functions. The only thing that makes them getters or setters is convention. A getter for foo is called getFoo and the setter is called setFoo. In the case of a boolean, the getter is called isFoo. They also must have a specific declaration as shown in this example of a getter and setter for

Fundamentals of Java Programming, named NameAndCount for recording a String data named name and an int data named count. A constructor for the class takes two values, one for the name and the other For “setters”, there is a method named increment that increases the value of The program instantiates a LinkedList of NameAndString objects and  One of the big advantage of using a getter and setter is that once the public methods are defined and there comes a time when the underlying implementation needs to be changed (e.g. finding a bug that needs to be fixed, using a different algorithm for improving performance, etc.), by having the getters and setters be the only way to manipulate

Comments
  • I think you mean if(DogAge >=6) DogAge++; But why does the dog need to 6 or older?
  • Also please try to following java naming conventions, variables begin with a lowercase char
  • Is this a homework? ;)
  • Also you need to call the method myDog.addOnetoAge();
  • This part needs to be within a method... if(int i=1;, also needs to be for(int i, not an if statement