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
Step: 1
public class Cat private String name Use private for encapsulation private int age public CatString ...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started