Question: create a program using a real life object as a Java class. I am having trouble with some errors. I am trying to change the

create a program using a real life object as a Java class. I am having trouble with some errors. I am trying to change the name of a cat and its age. Here is the code, any help would be appreciated, I am just getting back into Java

 

CAT FILE
public class cat {

String name;
int age;

public cat (String name, int age) {
this.name = name;
this.age= age;

}


public void Set(String name, int age) {
this.name = name;
this.age = age;


}

}


 

RUN CHANGE CLASS //for some reason this class does not recognize cat, name, and age which i declared in the first class **ANY HELP WOULD BE APPRECIATED**
public class runchange {

public static void main(String[] args) {
cat i = new cat("Max");
cat i  = new age("6");
System.out.println("The name of the cat is: " + i.name);
System.out.println ("The current age of the cat is: " + i.age);
i.setname= ("Monk");
i.setage=("7");

System.out.println("The new name of your cat is:" + i.name);
System.out.println("The new age of your cat is: " i.age);



}

}

Step by Step Solution

3.53 Rating (160 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

public class Cat private String name Use private for encapsulation private int age public CatString ... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!