Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

le ToolsView Lab3- 2017 (Protected View) - Word PROTECTED... e viruses. Unless y

ID: 3745710 • Letter: L

Question

le ToolsView Lab3- 2017 (Protected View) - Word PROTECTED... e viruses. Unless you need to edit, it's safer to stay in P Enable Editing Lab3- CSC121 B Object Interaction Goals: To understand the difference between classes and objects; To practice object creation and manipulation and external method calling. Getting started: 1. Start up BlueJ 2. Create a class called Dog. This class has three instance fields: breed (of type String), color (of type string) and weight (of type integer). 3. Write two constructors for the class, one without parameters and one with three parameters 4. Write accessor methods for the class 5. Write mutator methods for the class 6. Create a class called Cat. This class has three instance fields: breed (of type String), color (of type string) and weight (of type integer). 7. Write two constructors for the class, one without parameters and one with three parameters 8. Write accessor methods for the class 9. Write mutator methods for the class 10. Create a class called Animal. This class has four instance fields: a. Two Dog objects 946 AM 9/11/2018

Explanation / Answer

Program :-

class Dog{

  

String breed;

String color;

int weight;

  

Dog(){

this.breed = "ROAD";

this.color = "BLACK";

this.weight = 40;

}

  

Dog(String breed,String color,int weight){

this.breed = breed;

this.color = color;

this.weight = weight;

}

  

public String get_breed(){

return breed;

}

public String get_color(){

return color;

}

  

public int get_weight(){

return weight;

}

  

public void set_breed(String breed){

this.breed = breed;   

}

  

public void set_color(String color){

this.color = color;   

}

  

public void set_weight(int weight){

this.weight = weight;   

}

  

}

class Cat{

  

String breed;

String color;

int weight;

  

Cat(){

this.breed = "PERSIAN";

this.color = "WHITE";

this.weight = 20;

}

  

Cat(String breed,String color,int weight){

this.breed = breed;

this.color = color;

this.weight = weight;

}

  

public String get_breed(){

return breed;

}

public String get_color(){

return color;

}

  

public int get_weight(){

return weight;

}

  

public void set_breed(String breed){

this.breed = breed;   

}

  

public void set_color(String color){

this.color = color;   

}

  

public void set_weight(int weight){

this.weight = weight;   

}

  

}

public class Main

{

public static void main(String[] args) {

System.out.println("Classes and Objects");

Dog obj1 = new Dog();

Dog obj2 = new Dog();

}

}