Question

Project 1. Dog Door You are asked to create a dog door for a client. You are programming the remote that will do things such
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Executable Code

//DogBark.java

//Class name.

public class DogBark

{

//Declare the needed variable.

private String dSound;

//Constructor.

public DogBark(String dSound)

{

this.dSound = dSound;

}

//Method getDSound().

public String getDSound()

{

return this.dSound;

}

//Method equals().

public boolean equals(DogBark oBark)

{

//Condition check.

if (this.dSound.equalsIgnoreCase(oBark.getDSound()))

{

  

//Return value.

return true;

}

//Otherwise, return false.

return false;

}

}

//DogBarkRecognizer.java

//Include the needed packages.

import java.util.Iterator;

import java.util.List;

//Class name.

public class DogBarkRecognizer

{

  

//Declare the needed variable.

private MyDogDoor dDoor;

  

//Constructor.

public DogBarkRecognizer(MyDogDoor dDoor)

{

this.dDoor = dDoor;

}

//Method recognizer().

public void recognizer(DogBark dBark)

{

  

//Display message.

System.out.println("DogBarkRecognizer: Heard a '" + dBark.getDSound() + "'!");

//List of allowed barks.

List<DogBark> barksAllowed = dDoor.getBarksAllowed();

//For loop().

for (Iterator<DogBark> idx = barksAllowed.iterator(); idx.hasNext();)

{

DogBark allowedBark = idx.next();

  

//Condition check.

if (allowedBark.equals(dBark))

{

  

//Function call.

dDoor.dOpen();

//Return.

return;

}

}

//Display message.

System.out.println("This dog isn't allowed in!");

}

}

//MyDogDoor.java

//Include the needed packages.

import java.util.LinkedList;

import java.util.List;

import java.util.Timer;

import java.util.TimerTask;

//Class name.

public class MyDogDoor

{

//Declare the needed variables.

private boolean dOpen;

private List<DogBark> barksAllowed;

//Constructor.

public MyDogDoor()

{

this.dOpen = false;

this.barksAllowed = new LinkedList<DogBark>();

}

//Method dOpen().

public void dOpen()

{

//Display message.

System.out.println("The dog door opens.");

dOpen = true;

//For time delay.

final Timer dTimer = new Timer();

dTimer.schedule(new TimerTask()

{

//Overriden method run().

@Override

public void run()

{

dClose();

dTimer.cancel();

}

}, 5000);

}

//Method dClose().

public void dClose()

{

System.out.println("The dog door closes.");

dOpen = false;

}

//Method isOpen().

public boolean isOpen()

{

return dOpen;

}

//Method getBarksAllowed().

public List<DogBark> getBarksAllowed()

{

return this.barksAllowed;

}

//Method addBarksAllowed().

public void addBarksAllowed(DogBark allowedBark)

{

barksAllowed.add(allowedBark);

}

}

//MyRemote.java

//Class name.

public class MyRemote

{

//Declare the needed variable.

private MyDogDoor dDoor;

//Constructor.

public MyRemote(MyDogDoor dDoor)

{

this.dDoor = dDoor;

}

//Method buttonPress().

public void buttonPress()

{

//Display message.

System.out.println("Pressing remote button!");

//Condition check.

if (dDoor.isOpen())

{

//Function call.

dDoor.dClose();

}

//Otherwise.

else

{

//Function call.

dDoor.dOpen();

}

}

}

//MyDogDoorSimulator.java

//Class name.

public class MyDogDoorSimulator

{

//Main().

public static void main(String[] args)

{

//Create instance for MyDogDoor class.

MyDogDoor dDoor = new MyDogDoor();

//Add barks allowed.

dDoor.addBarksAllowed(new DogBark("woowo"));

dDoor.addBarksAllowed(new DogBark("roww"));

dDoor.addBarksAllowed(new DogBark("raww"));

dDoor.addBarksAllowed(new DogBark("rawl"));

dDoor.addBarksAllowed(new DogBark("warl"));

//Create instance for DogBarkRecognizer class.

DogBarkRecognizer recogn = new DogBarkRecognizer(dDoor);

//Create instance for MyRemote class.

MyRemote myremote = new MyRemote(dDoor);

//Display message.

System.out.println("My dog starts barking...");

//Function call.

recogn.recognizer(new DogBark("woowo"));

//Display message.

System.out.println("\nMy dog has gone outside...");

try

{

//Delay.

Thread.sleep(10000);

}

catch (InterruptedException e)

{

//Display message.

System.out.println("Something went wrong :)");

}

//Display message.

System.out.println("\nMy dog is all done...");

System.out.println("\n...but he is stuck outside!");

//Create a instance for for another dog.

DogBark otherDog = new DogBark("Other Dog");

//Display message.

System.out.println("\nAnother dog starts barking.");

//Function call.

recogn.recognizer(otherDog);

try

{

//Delay.

Thread.sleep(5000);

}

catch (InterruptedException e)

{

//Display message.

System.out.println("Something went wrong :)");

}

//Display message.

System.out.println("\nMy dog starts barking...");

//Function call.

recogn.recognizer(new DogBark("warl"));

//Display message.

System.out.println("\nMy dog came back inside...");

}

}

Add a comment
Know the answer?
Add Answer to:
Project 1. Dog Door You are asked to create a dog door for a client. You...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Exercise #3: Create a class to represent a dog. Name the class “Dog”. It will contain...

    Exercise #3: Create a class to represent a dog. Name the class “Dog”. It will contain three (3) class attributes, its bark, size, and cuteness. The bark will be the sound of the dog’s bark, as in “woof!”. Its size will be how tall the dog is from the ground, and that number should always be between 6 and 44 inches. The cuteness is a string describing how cute the dog is, based on this scale: “ugliest dog ever!” “pretty...

  • Exercise: (2) Create a class called Dog containing two Strings: name and says. In main(), create...

    Exercise: (2) Create a class called Dog containing two Strings: name and says. In main(), create two dog objects with names “spot” (who says, “Ruff!”) and “scruffy” (who says, “Wurf!”). Then display their names and what they say. Be sure to use setter and getter methods to assign(set) and retrieve(get) values for both Strings name and says. Your Task: Create the program using Netbeans and easyUML (i.e: Open a project in NetBeans then create the classes, attributes, and methods in...

  • In a project named 'DogApplication', create a class called 'Dog' 1. declare two instance variables in...

    In a project named 'DogApplication', create a class called 'Dog' 1. declare two instance variables in 'Dog' : name (String type) age (int type) 2. declare the constructor for the 'Dog' class that takes two input parameters and uses these input parameters to initialize the instance variables 3. create another class called 'Driver' and inside the main method, declare two variables of type 'Dog' and call them 'myDog' and 'yourDog', then assign two variables to two instance of 'Dog' with...

  • Using your Dog class from earlier this week, complete the following: Create a new class called...

    Using your Dog class from earlier this week, complete the following: Create a new class called DogKennel with the following: Instance field(s) - array of Dogs + any others you may want Contructor - default (no parameters) - will make a DogKennel with no dogs in it Methods: public void addDog(Dog d) - which adds a dog to the array public int currentNumDogs() - returns number of dogs currently in kennel public double averageAge() - which returns the average age...

  • Imagine that money is no object. You have been asked to design an environmentally friendly dog...

    Imagine that money is no object. You have been asked to design an environmentally friendly dog house for a client. Your structure should be Classical Style, Prairie Style, International (geometric) Style, or Organic Style. First describe the architectural style, architectural elements, materials, and methods you have chosen. Describe the location and features of the dog house. In order to design a "green" dog house you must do the following: 1. be sure your structure has a reduced impact (smaller "footprint",...

  • Project overview: Create a java graphics program that displays an order menu and bill from a...

    Project overview: Create a java graphics program that displays an order menu and bill from a Sandwich shop, or any other establishment you prefer. In this program the design is left up to the programmer however good object oriented design is required. Below are two images that should be used to assist in development of your program. Items are selected on the Order Calculator and the Message window that displays the Subtotal, Tax and Total is displayed when the Calculate...

  • *Use Java to create this program* For this assignment, you will be building a Favorite Songs...

    *Use Java to create this program* For this assignment, you will be building a Favorite Songs application. The application should have a list with the items displayed, a textbox for adding new items to the list, and four buttons: Add, Remove, Load, and Save. The Add button takes the contents of the text field (textbox) and adds the item in it to the list. Your code must trim the whitespace in front of or at the end of the input...

  • Java Project In Brief... For this Java project, you will create a Java program for a...

    Java Project In Brief... For this Java project, you will create a Java program for a school. The purpose is to create a report containing one or more classrooms. For each classroom, the report will contain: I need a code that works, runs and the packages are working as well The room number of the classroom. The teacher and the subject assigned to the classroom. A list of students assigned to the classroom including their student id and final grade....

  • We are going to create a few different classes in this project. I will supply one...

    We are going to create a few different classes in this project. I will supply one of the classes: Pound (as in a pound for animals). Your goal will be to create proper Dog and Cat classes that will work in conjunction with this Pound class. Before starting to the design process for the Dog/Cat classes, carefully inspect this code. Get an idea of the goal of the Cat/Dog classes. How many fields will they store? What will the constructors...

  • Project Description In this project, you will design and implement a database for keeping track of...

    Project Description In this project, you will design and implement a database for keeping track of information for an online “SOCIAL NETWORK” system (e.g. a simplified version of Facebook!). You will first design an EER schema diagram for this database application. Then, you will map the EER schema into a relational database schema and implement it on ORACLE or MySQL or some other relational DBMS. Finally, you will load some data into your database (via user Interface) and create some...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT