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

How can I add an introduction() method to MyClone like the assignment requires a

ID: 3577180 • Letter: H

Question

How can I add an introduction() method to MyClone like the assignment requires and combine these classes/files to still make my code work? I'm really new at programming and am struggling to do things right!

Here is the assignment:

"You will create a Virtual World application as your final project. This Virtual World will have several objects including a MyClone object and another object of your choice. It would be an excellent idea to review the Final Project Guidelines at this time. For this Third Final Project Milestone, you will finish development of your MyClone class and create another class of your choice.

In Module Two, you started development of the MyClone class. You will continue to develop the MyClone class by adding accessor methods, mutator methoda, and an introduction() method. The introduction() method will introduce yourself to the virtual world by displaying a greeting, your first and last name, and anything else you would want to say.

You will also create another class of your choice. Your programmer-defined class should have at a minimum two instance variables and one method. The instance variables and method should be representative of the data and behavior that objects of this class will have. You will demonstrate your understanding of encapsulation by declaring the instance varibales as private and by creating accessors and mutatora for each instance variable. You should have at least one constructor created that initializes all instance variables. Document your code."

Here is what I have so far for my two classes (MyClone and Puppy):

MyClone.java:

package virtual.world;

public class MyClone {
private String firstName;
private String lastName;
  
public String getFirstName() {
return firstName;
}
  
public String getLastName() {
return lastName;
}
  
public void setFirstName(String newFirstName) {
firstName = newFirstName;
}
  
public void setLastName(String newLastName) {
lastName = newLastName;
}
}

VirtualWorld:

public class VirtualWorld {

public static void main(String[] args) {
MyClone clone = new MyClone();
clone.setFirstName("my name");
clone.setLastName("my name pt 2");
  
System.out.println("First Name: " + clone.getFirstName());
System.out.println("Last Name: " + clone.getLastName());
  
}

Puppy.java

package org.puppy;

public class Puppy
{
private int puppyTag;
private String puppyType;
private String puppyName;
  
public Puppy() {
this.puppyTag = 001;
this.puppyType= "Dachshund";
this.puppyName = "Slinky";
}

public Puppy(int puppyTag, String puppyName, String puppyType) {
super();
this.puppyTag = puppyTag;
this.puppyType = puppyType;
this.puppyName = puppyName;
}

public int getPuppyTag()
{
return puppyTag;
}
public void setPuppyTag(int puppyTag)
{
this.puppyTag = puppyTag;
}

public String getPuppyType()
{
return puppyType;
}
public void setPuppyType(String puppyType)
{
this.puppyType = puppyType;
}
public String getPuppyName()
{
return puppyName;
}
public void setPuppyName(String puppyName)
{
this.puppyName = puppyName;
}

public void displayPuppyInfo()
{
System.out.println("Puppy Tag#: " + puppyTag);
System.out.println("Puppy Name: " + puppyName);
System.out.println("Puppy Type: " + puppyType);
System.out.println(" ");
  
}
  
}

DogTypes.java:

package puppy;
import org.puppy.Puppy;

public class DogTypes {

public static void main(String[] args) {
Puppy a = new Puppy(); //allows us to differentiate different puppies
a.displayPuppyInfo();


Puppy b = new Puppy();
b.setPuppyTag(2);
b.setPuppyName("Johnny Danger");
b.setPuppyType("Poodle");
b.displayPuppyInfo();

Puppy c = new Puppy();
c.setPuppyTag(3);
c.setPuppyType("Pit Bull");
c.setPuppyName("Billy");
c.displayPuppyInfo();

Puppy d = new Puppy(4, "Kaiya", "Husky");
d.displayPuppyInfo();

}

}

Explanation / Answer

Creating a new method means simple add one more method to the class which does something like given below-


MyClone.java:
package virtual.world;
public class MyClone {
private String firstName;
private String lastName;
  
public String getFirstName() {
return firstName;
}
  
public String getLastName() {
return lastName;
}
  
public void setFirstName(String newFirstName) {
firstName = newFirstName;
}
  
public void setLastName(String newLastName) {
lastName = newLastName;
}
  
public void introduction() {
System.out.println("Hello there!! Greetings from "+firstName+" "+lastName+". Have a great time.");
}
}

VirtualWorld:
public class VirtualWorld {
public static void main(String[] args)
{
MyClone clone = new MyClone();
clone.setFirstName("my name");
clone.setLastName("my name pt 2");
clone.introduction();
}
}

Rest two classes are good.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote