QuestionQuestion

Write a Java program containing two classes:
Dog and a driver class Kennel. A dog consists of the following information:
•An integer age.
•A string name. If the given name contains non-alphabetic characters, initialize to Wolfy.
•A string bark representing the vocalization the dog makes when they ‘speak’.
•A boolean representing hair length; true indicates short hair.
•A float weight representing the dog’s weight (in pounds).
•An enumeration representing the type of tail (LONG, SHORT, NONE).
A dog consists of the following methods.
•A default constructor.
•A constructor that takes a name as argument.
•A method private boolean validName(String) that returns true / false whether the given name contains non-alphabetic characters.
•humanAge that computes and returns the age of the dog in “human years.”
•speak returns the dog’s bark. Each constructor should initialize all attributes to reasonable initial values. The main method in the Kennel class should create several dogs with each constructor and output their instance data using toString.

Each of the following methods should be static and defined in a class called Utilities. Implement a second class called Tester that calls each of these methods.
1.Write a method that returns the absolute value of a given integer; your implementation may not use Math.abs .
2.Write a method that returns the ceiling of an input double. Note, this function always returns the next larger integer (even for negative numbers) except when an integer value is given. For example, ceiling(-1.2) = -1      ceiling(3) = 3    ceiling(1.2) = 2
3.Write a method that returns n! given an integer n. Your method must use and return a BigInteger object. Note, you may need code like
fact = fact.multiply(BigInteger.valueOf(i));
where i is an integer.
4.Write a method that returns a string consistent with the progression:
x xx xxx xxxx xxxxx
The method input should dictate the length of the pattern. For simplicity, interpret a negative value positively; that is, use absolute value (your absolute value method, not Math.abs).

In this lab you will write three classes:Die,PairOfDice,and Player. The Die class mimics the rolling of a die. Specifically, this class will implement the following methods:
A default constructor initializing the number of sides of a die to 6.
An overloaded constructor that takes an integer number of sides (assume greater than 1).
roll which generates and returns a random number between 1 and the number of sides (inclusive).
An accessor method to read the value of the face on the die.
A toString method returning the string representation of the face value.

The maximum number of sides should be stored as a private constant in the Die class. Also use the Random class for the random number generator. The PairOfDice class mimics the rolling of two dice. Specifically, this class will implement the following methods:
A default constructor that creates and initializes the number of sides of each die to 6.
An overloaded constructor that creates and takes two integer number of sides, one for each die.
roll rolls each die and returns the sum.
An accessor method to read the sum of the dice. The Player class implements the main method which creates the dice pair and rolls them several times reporting the results.

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

/*
* Dog class for Lab 10
*/
public class Dog {

int age;
String name;
String bark;
boolean hairLength;
float weight;
tailType tail;

// tail type enum
enum tailType {
    LONG, SHORT, NONE;
}

// Default constructor
public Dog() {
    this.age = 35;
    this.name = "Wolfy";
    this.bark = "woof";
    this.hairLength = true;
    this.weight = 75;
    this.tail = tailType.SHORT;
}

// Constructor with name
public Dog(String name) {
    this();
    if (validName(name))
      this.name = name;
}

// Method to check if name is valid
private boolean validName(String name) {
    for (char c: name.toCharArray()) {
      if (!Character.isLetter(c))
       return false;
    }
    return true;
}

// Method to get human age of dog
public int humanAge() {
    return this.age / 7;
}

// Method to speak dog's bark
public String speak() {



/*
* Kennel class for Lab 10
*/
public class Kennel {

/*
   * Main method for program execution
   */
public static void main(String[] args) {
   
    // Create dog with default constructor
    Dog dog1 = new Dog();
    System.out.println(dog1);
   
    // Create dog with name
    Dog dog2 = new Dog("Rufus");
    System.out.println(dog2);
   
    // Create dog with name and attributes
    Dog dog3 = new Dog("Spot");
    dog3.age = 27;
    dog3.bark = "bark";
    dog3.hairLength = false;
    dog3.weight = 80;
    dog3.tail = Dog.tailType.LONG;
    System.out.println(dog3);
   
    // Create dog with name and attributes
    Dog dog4 = new Dog("Butch");
    dog4.age = 10;
    dog4.bark = "ruff";
    dog4.hairLength = true;
    dog4.weight = 50;
    dog4.tail = Dog.tailType.NONE;
    System.out.println(dog4...

By purchasing this solution you'll be able to access the following files:
Solution.zip, Solution1.zip and Solution2.zip.

$42.00
for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Java Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats