Question

In: Computer Science

THE QUESTION IS OF JAVA LANGUAGE. ANSWER IS REQUIRED IN THREE PARTS (THREE JAVA FILES). PLEASE...

THE QUESTION IS OF JAVA LANGUAGE.

ANSWER IS REQUIRED IN THREE PARTS (THREE JAVA FILES). PLEASE DIFFERENTIATE FILES SO I CAN UNDERSTAND BETTER.

NOTE - Submission in parts. Parts required - Dog Class Code, Dog Manager Class Code and the main code. Please differentiate all three in the answer.

This Assignment is designed to take you through the process of creating basic classes, aggregation and manipulating arrays of objects.

Scenario:

A dog shelter would like a simple system to keep track of all the dogs that pass through the facility.

The system must record for each dog:

dogId (int) - must be unique

name (string)

age (double) - cannot be less than 0 or more than 25

breed (string)

sex (char) – m for male, f for female

foundHome (bool)    - true means the dogs has been places in a home false otherwise.

You must create an object oriented solution with a text based menu as summarized on the next page. The system must check that valid data is entered. For example, the menu has four items so only 1 to 5 must be allowed as input from the menu.

Summary of Operations

System Menu:

  1. Add dog
  2. View all dogs
  3. View all available dogs
  4. View dog
  5. Update dog home status
  6. exit

Overview:

Add Dog:

When a dog is added to the system, you must check that the dogId is not already used in the system. All new dogs have no home as yet (foundHome = false).

View all Dogs:

This menu option shows all dogs in the system. This includes dogs that have a home and those that do not.

View all available dogs:

Shows all dogs in the system, that have no homes as yet.

View dog:

Asks the user for a dogId and then displays the dog information if found and “There is no dog with that id..” if it is not found.

Update dog home status:

Asks the user for a dogId. If a dog with that id is found, the “foundHome” status is changed to true and the dog information is to be displayed. If the dog is not found the message “There is no dog with that id..” should be displayed.

Solutions

Expert Solution

Solution of the above problem is provided below.

three separate .java files are provided

Dog.java


public class Dog {
        private int dogId;
        private String name;
        private double age;
        private String breed;
        private char sex;
        private boolean foundHome;
        /**
         * @param dogId
         * @param name
         * @param age
         * @param breed
         * @param sex
         * @param foundHome
         */
        public Dog(int dogId, String name, double age, String breed, char sex) {
                super();
                this.dogId = dogId;
                this.name = name;
                this.age = age;
                this.breed = breed;
                this.sex = sex;
                this.foundHome = false;
        }
        /**
         * @return the dogId
         */
        public int getDogId() {
                return dogId;
        }
        /**
         * @param dogId the dogId to set
         */
        public void setDogId(int dogId) {
                this.dogId = dogId;
        }
        /**
         * @return the name
         */
        public String getName() {
                return name;
        }
        /**
         * @param name the name to set
         */
        public void setName(String name) {
                this.name = name;
        }
        /**
         * @return the age
         */
        public double getAge() {
                return age;
        }
        /**
         * @param age the age to set
         */
        public void setAge(double age) {
                this.age = age;
        }
        /**
         * @return the breed
         */
        public String getBreed() {
                return breed;
        }
        /**
         * @param breed the breed to set
         */
        public void setBreed(String breed) {
                this.breed = breed;
        }
        /**
         * @return the sex
         */
        public char getSex() {
                return sex;
        }
        /**
         * @param sex the sex to set
         */
        public void setSex(char sex) {
                this.sex = sex;
        }
        /**
         * @return the foundHome
         */
        public boolean isFoundHome() {
                return foundHome;
        }
        /**
         * @param foundHome the foundHome to set
         */
        public void setFoundHome(boolean foundHome) {
                this.foundHome = foundHome;
        }
        @Override
        public String toString() {
                return "Dog [dogId=" + dogId + ", name=" + name + ", age=" + age + ", breed=" + breed + ", sex=" + sex
                                + ", foundHome=" + foundHome + "]";
        }
        
        

}

DogManager.java


import java.util.*;

public class DogManager {
        
        ArrayList<Dog> dogList = new ArrayList<>();
        
        
        /* method to add dog to the list*/
        public void addDog(Dog dog) {
                if(!dogList.contains(dog)) {
                        dogList.add(dog);
                }
        }
        
        /* Method to view all dogs */
        public void viewAllDogs() {
                for(Dog d : dogList) {
                        System.out.println("\t"+d.toString());
                }
        }
        
        public void viewAllAvailableDogs() {
                for(Dog d : dogList) {
                        if(!d.isFoundHome()) {
                        System.out.println("\t"+d.toString());
                        }
                }
        }
        /* print dog information if the dogId matches */
        public void viewDog(int dogId) {
                for(Dog d : dogList) {
                        if(d.getDogId() == dogId) {
                        System.out.println("\t"+d.toString());
                        }
                }
        }
        
        public void updateDogHomeStatus(int dogID) {
                for(Dog d : dogList) {
                        if(d.getDogId() == dogID) {
                                d.setFoundHome(true);
                                System.out.println("\t"+d.toString());
                        }
                        System.out.println("There is no dog with that id..");
                }
        }

}

Main.java <Driver class of code>

import java.util.*;

public class Main {
        
        public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        // dog class objects
        Dog d1 = new Dog(1,"tony",5,"Jerman Shepard", 'm');
        Dog d2 = new Dog(2,"jessy",8,"Pamerian", 'm');
        
        // creating objects of dog manager class
        DogManager dm = new DogManager();
        
        /* manually adding dog objects to list to test the view dogs method */
        dm.addDog(d2);
        
        
        int choice;
        
        do {
                menu();
                choice = sc.nextInt();
                switch (choice) {
                
                
                case 1: {
                        System.out.println("Enter dogid");
                        int dogid = sc.nextInt();
                        
                        System.out.println("Enter dog name");
                        String dogName = sc.next();
                        
                        System.out.println("Enter age");
                        double age = sc.nextDouble();
                        
                        System.out.println("Enter breed");
                        String breed = sc.next();
                        
                        System.out.println("Enter sex of dog m/f");
                        char sex = sc.next().charAt(0);
                        
                        dm.addDog(new Dog(dogid, dogName, age, breed, sex));
                        
                        break;
                }

                case 2: {
                        dm.viewAllDogs();
                        break;
                }

                case 3: {
                        dm.viewAllAvailableDogs();
                        break;
                }

                case 4: {
                        System.out.println("Enter Dog id");
                        int dogID = sc.nextInt();
                        dm.viewDog(dogID);
                        break;
                }

                case 5: {
                        System.out.println("Enter Dog id");
                        int dogID = sc.nextInt();
                        dm.updateDogHomeStatus(dogID);
                        break;
                }

                case 6: {
                        System.exit(0);
                        break;
                }

                default:
                        System.out.println("\nInvalid choice!\n");
                }
        } while (choice != 0);
        
        }
        
        public static void menu() {
                System.out.print("1. Add dog\n" 
        + "2. View all dogs\n" 
                                + "3. View all available dogs   \n" 
        + "4. View dog \n"
                                + "5. Update dog home status\n" 
        + "6. exit\n");
        }
        
        

}

Output of the program:

End of Solution


Related Solutions

SOLUTION IN JAVA LANGUANGE NEEDED. JAVA LANGUAGE QUESTION. NOTE - Submission in parts. Parts required -...
SOLUTION IN JAVA LANGUANGE NEEDED. JAVA LANGUAGE QUESTION. NOTE - Submission in parts. Parts required - Dog Class Code, Dog Manager Class Code and the main code. Please differentiate all three in the answer. This Assignment is designed to take you through the process of creating basic classes, aggregation and manipulating arrays of objects. Scenario: A dog shelter would like a simple system to keep track of all the dogs that pass through the facility. The system must record for...
Please answer both parts of this question. Please answer both parts of this question. Question: a)...
Please answer both parts of this question. Please answer both parts of this question. Question: a) The channel in question 2 now has a 0.3m high smooth extended shelf built across its base to cover a submerged pipeline but still carries 50m3/s. Plot the specific energy diagram for 0 < y < 4m and calculate the critical depth and minimum specific energy. What are now the two possible flow depths for a specific energy of 4m upstream of the obstructions?...
Please answer all the parts of this question Please answer all the parts of this question...
Please answer all the parts of this question Please answer all the parts of this question Question: a) Where is the flow accelerating in the control volume? b) Will the pressure be greater or less than hydrostatic in a region of accelerating flow? c) Is the hydrostatic estimate of force on the gate; larger, smaller, or the same, as that obtained from the Momentum Equation? Explain. d) Where does the change in flow momentum go in this control volume? Explain.
***Please answer the question using the JAVA programming language. Write a program that calculates mileage reimbursement...
***Please answer the question using the JAVA programming language. Write a program that calculates mileage reimbursement for a salesperson at a rate of $0.35 per mile. Your program should interact (ask the user to enter the data) with the user in this manner: MILEAGE REIMBURSEMENT CALCULATOR Enter beginning odometer reading > 13505.2 Enter ending odometer reading > 13810.6 You traveled 305.4 miles. At $0.35 per mile, your reimbursement is $106.89. ** Extra credit 6 points: Format the answer (2 points),...
Programming Steps: (In Java) (Please screenshot your output) A. Files required or needed to be created:...
Programming Steps: (In Java) (Please screenshot your output) A. Files required or needed to be created:    1. Artist.java (Given Below)    2. p7artists.java (Input file to read from)    3. out1.txt (Output file to write to) B. Java programs needed to writeand create:    1. MyArtistList.java:    - Contains the following:        1. list - public, Arraylist of Artist.        This list will contain all entries from "p7artists.txt"        2. Constructor:        A constructor that accepts one...
Please answer the three parts of the question. 32. A. Why, according to Keynes, can a...
Please answer the three parts of the question. 32. A. Why, according to Keynes, can a recession be prolonged? Illustrate and discuss B. Discuss and illustrate the main policy recommendations to get out of a recession according to Keynes C. Can a reduction in the interest rate get an economy out of recession according to Keynes? Discuss.
Question 4. Please answer all three parts to this question. a. Write down the quantity equation,...
Question 4. Please answer all three parts to this question. a. Write down the quantity equation, in both the level and the rates of change form. What do each of the terms represent? b. If the Bank of Canada wishes to maintain inflation at 2% per year, how can the bank use the quantity equation to achieve this goal? What assumption is made about the velocity of money? c. Does the Bank of Canada target the rate of growth of...
PLEASE READ: This is one question with 3 parts to it, please answer the full question....
PLEASE READ: This is one question with 3 parts to it, please answer the full question. Mark M. Upp has just been fired as the university bookstore manager for setting prices too low (only 20 percent above suggest retail). He is considering opening a competing bookstore near the campus, and he has begun an analysis of the situation. There are two possible sites under consideration. One is relatively small, while the other is large. If he opens at Site 1...
In JAVA Language Please! Programming Exercise 3.20 required you to design a PID manager that allocated...
In JAVA Language Please! Programming Exercise 3.20 required you to design a PID manager that allocated a unique process identifier to each process. Exercise 4.20 required you to modify your solution to Exercise 3.20 by writing a program that created a number of threads that requested and released process identifiers. Now modify your solution to Exercise 4.20 by ensuring that the data structure used to represent the availability of process identifiers is safe from race conditions. Use Pthreads mutex locks....
Please answer all three parts to question 1. 1A. The income from operations and the amount...
Please answer all three parts to question 1. 1A. The income from operations and the amount of invested assets in each division of Beck Industries are as follows: Income from Operations Invested Assets Retail Division $167,200 $760,000 Commercial Division 74,000 370,000 Internet Division 69,700 410,000 a. Compute the return on investment for each division. (Round to the nearest whole number.) Division Percent Retail Division   % Commercial Division   % Internet Division   % b. Which division is the most profitable per dollar...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT