Question

Create a field with the boolean value of goodBoi. In the constructor, set your good boi...

  1. Create a field with the boolean value of goodBoi.
  2. In the constructor, set your good boi to being false, as all dogs has deserve being called a good boiii.
  3. Make a method makeGoodBoi, which sets the good boi value to being true.
  4. Make a method isGoodBoi which returns the value the good boi field (hint: it returns a boolean value).
  5. Now we need a method called whosAGoodBoi. If the doggo is indeed a good boi, then print: "[doggo] is such a goood boii". If they are not yet a good boi, then print: "[doggo] is not a good boi :(". Doggo is the name of the doggo (like in the last exercise).

    Hey I have this ^ assignment and I am stuck at 5. but I don't know if it is something I have done wrong earlier.
    I will just submit my code below and hopefully someone can tell me what I am doing wrong :

    public class Doggo {

    // field

    String name;

    Boolean goodBoi;

    //constructor

    public Doggo(String name) {

    this.name = name;

    this.goodBoi = false;

    }

    //getName method

    public String getName()

    {

    return name;

    }

    // makeBark method

    public void makeBark ()

    {

    System.out.println(this.name + " " + "said: Woof woof");

    }

    // makeGoodBoi method

    public void makeGoodboi()

    {

    this.goodBoi = true;

    }

    // is GoodBoi

    public static boolean isGoodBoi()

    {

    return false;

    }

    // whosAGoodBoi

    public void whosAGoodBoi(Doggo mira) {

    if (Doggo.isGoodBoi()); {

    System.out.println(mira.getName() + "" + "is such a good boii");

    }

    else {

    System.out.println(mira.getName()+ "" + "is not a good boi :(");

    }

    }

    }

    public class Main {

    public static void main(String[] args) {

    Doggo mira = new Doggo("mira");

    mira.makeBark();

    }

    }

Homework Answers

Answer #1

class Doggo {

// field
  
String name;
  
Boolean goodBoi;
  
//constructor
  
public Doggo(String name) {
  
this.name = name;
  
this.goodBoi = false;
  
}
  
//getName method
  
public String getName() {
  
return name;
  
}
  
// makeBark method
  
public void makeBark () {
  
System.out.println(this.name + " " + "said: Woof woof");
  
}
  
// makeGoodBoi method
  
public void makeGoodboi(){
this.goodBoi = true;
}
  
// is GoodBoi
  
public boolean isGoodBoi() {
return goodBoi;
}
  
// whosAGoodBoi
  
public void whosAGoodBoi(Doggo mira) {

if (mira.isGoodBoi()) {
  
System.out.println(mira.getName() + "" + "is such a good boii");
  
}
  
else {
  
System.out.println(mira.getName()+ "" + "is not a good boi :(");
  
}
  
}
  
}

public class Main {

public static void main(String[] args) {
  
Doggo mira = new Doggo("mira");
  
mira.makeGoodboi(); // here I am making good boi. so the status is true
mira.whosAGoodBoi(mira);
  
}

}

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Java Program Implement a class called AnimalTrainer. Include the following data types in your class with...
Java Program Implement a class called AnimalTrainer. Include the following data types in your class with the default values denoted by dataType name : defaultValue - String animal : empty string - int lapsRan : 0 - boolean resting : false - boolean eating : false - double energy : 100.00 For the animal property implement both getter/setter methods. For all other properties implement ONLY a getter method Now implement the following constructors: 1. Constructor 1 – accepts a String...
Java: ModifyStudentList.javato use anArrayListinstead of an array In StudentList.java, create two new public methods: The addStudent...
Java: ModifyStudentList.javato use anArrayListinstead of an array In StudentList.java, create two new public methods: The addStudent method should have one parameter of type Student and should add the given Student to the StudentList. The removeStudent method should have one parameter of type String. The String is the email of the student to be removed from the StudentList. In Assign5Test.java do the following: Create a new StudentList containing 3 students. Print the info of all the Students in the StudentList using...
Which method is correct to access the value of count? public class Person { private String...
Which method is correct to access the value of count? public class Person { private String name; private int age; private static int count = 0; } A. private int getCount() {return (static)count;} B. public static int getCount() {return count;} C. public int getCount() {return static count;} D. private static int getCount() {return count;} How can you print the value of count? public class Person { private String name; private int age; private static int count=0; public Person(String a, int...
Class VacationPackage java.lang.Object triptypes.VacationPackage Constructor Summary Constructors Constructor and Description VacationPackage(java.lang.String name, int numDays) Initializes a...
Class VacationPackage java.lang.Object triptypes.VacationPackage Constructor Summary Constructors Constructor and Description VacationPackage(java.lang.String name, int numDays) Initializes a VacationPackage with provided values. Method Summary All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method and Description boolean equals(java.lang.Object other) Provides a logical equality comparison for VacationPackages and any other object type. double getAmountDue() This method provides the remaining amount due to the travel agent for this trip less any deposit made upfront. abstract double getDepositAmount() This method provides the required...
I am a beginner when it comes to java codeing. Is there anyway this code can...
I am a beginner when it comes to java codeing. Is there anyway this code can be simplified for someone who isn't as advanced in coding? public class Stock { //fields private String name; private String symbol; private double price; //3 args constructor public Stock(String name, String symbol, double price) { this.name = name; this.symbol = symbol; setPrice(price); } //all getters and setters /** * * @return stock name */ public String getName() { return name; } /** * set...
Write the following problem in Java Create a class Dog, add name, breed, age, color as...
Write the following problem in Java Create a class Dog, add name, breed, age, color as the attributes. You need to choose the right types for those attributes. Create a constructor that requires no arguments. In this constructor, initialize name, breed, age, and color as you wish. Define a getter and a setter for each attribute. Define a method toString to return a String type, the returned string should have this information: “Hi, my name is Lucky. I am a...
[Java] I'm not sure how to implement the code. Please check my code at the bottom....
[Java] I'm not sure how to implement the code. Please check my code at the bottom. In this problem you will write several static methods to work with arrays and ArrayLists. Remember that a static method does not work on the instance variables of the class. All the data needed is provided in the parameters. Call the class Util. Notice how the methods are invoked in UtilTester. public static int min(int[] array) gets the minimum value in the array public...
Add a second data member (another int) to the class ObjX. Then in main assign a...
Add a second data member (another int) to the class ObjX. Then in main assign a value to the new variable and print it. class ObjX { // No "static" keyword for either member. int i; void print () { System.out.println ("i=" + i); } } public class DynamicExample { public static void main (String[] argv) { // First create an instance, which allocates space from the heap. ObjX x = new ObjX (); // Now access members via the...
This is Java programing.Modify this Java code,so that each franchise can assign and print their own...
This is Java programing.Modify this Java code,so that each franchise can assign and print their own burger price.The programing have at least three franchises. (Use abstract) class newBurger { public newBurger() { } public void salmonBurger(){    System.out.println("salmonBurger $5.99");    System.out.println("Kcal: 294"); } public void clamBurger(){    System.out.println("clamBurger $4.99");    System.out.println("Kcal: 200"); } public void oysterBurger(){    System.out.println("oysterBurger $3.50");    System.out.println("Kcal: 125"); } } class franchise1 extends newBurger { String name = "franchise #1"; public franchise1() { } } public...
I am writing code in java to make the design below. :-):-):-):-):-):-)  :-):-):-):-):-):-)  :-):-):-):-):-):-) :-):-):-):-):-):-)  :-):-):-):-):-):-)  :-):-):-):-):-):-) I already have...
I am writing code in java to make the design below. :-):-):-):-):-):-)  :-):-):-):-):-):-)  :-):-):-):-):-):-) :-):-):-):-):-):-)  :-):-):-):-):-):-)  :-):-):-):-):-):-) I already have this much public class Main { int WIDTH = 0; double HEIGHT = 0; public static void drawSmileyFaces() { System.out.println(" :-):-):-):-):-):-)"); } public static void main (String[] args) { for (int WIDTH = 0; WIDTH < 3; WIDTH++ ) { for(double HEIGHT = 0; HEIGHT < 2; HEIGHT++) { drawSmileyFaces(); } } } } I am pretty sure that alot of this is wrong...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT