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

Write a class named Animal that has the following attributes and methods. Save t

ID: 3778206 • Letter: W

Question

Write a class named Animal that has the following attributes and methods. Save this class as Animal.py

Attributes __animal_type: a hidden attribute used to indicate the animal’s type. For example: gecko, walrus, tiger, etc.

__name: a hidden attribute used to indicate the animal’s name.

__mood: a hidden attribute used to indicate the animal’s mood. For example: happy, hungry, or sleepy.

__animal_available: a hidden attribute used to indicate if the animal is available for adoption.

Methods __init__: this method should create the three attributes above and assign their default values.

The value of __mood should be set randomly. Generate a random number between 1 and 3. Then:

If the number is 1, the __mood field should be set to a value of “happy”.

If the number is 2, the __mood field should be set to a value of “hungry”.

If the number is 3, the __mood field should be set to a value of “sleepy”.

get_animal_type: this method should return the value of the __animal_type field.

get_name: this method should return the value of the __name field.

check_mood: this method should return the value of the __mood field

get_available: this method should return the value of the __animal_available field

Explanation / Answer

import java.awt.BorderLayout;

    import java.awt.Color;

    import java.awt.GridLayout;

    import java.awt.event.ActionEvent;

    import java.awt.event.ActionListener;

    import java.util.Timer;

    import javax.swing.BorderFactory;

    import javax.swing.BoxLayout;

    import javax.swing.ImageIcon;

    import javax.swing.JFrame;

    import javax.swing.JLabel;

    import javax.swing.JPanel;

    import javax.swing.JButton;

    import javax.swing.JProgressBar;

    import javax.swing.JTextArea;

    public class inter {

private JFrame tigerWindow;

private JPanel topPanel, leftPanel, rightPanel, bottomPanel, middlePanel, allPanels;

private JLabel tigerLabel, happyLabel, hungryLabel, energyLabel, hygieneLabel, picLabel;

private JButton play, sleep, feed, hunt, swim, walk, shop, home;

private JProgressBar happyBar, hungryBar, energyBar, hygieneBar;

private JTextArea tigerText;

private JProgressBar happy, hungry, energy, hygiene;

private int interval;

private Timer timer;

private int tigerHungerCount = 5;

private int tigerHygieneCount = 5;

private int tigerHappyCount = 5;

private int tigerEnergyCount = 5;

        Pet tiger = new Pet ("Meat", "Roll", "Roar", "Yellow", "zzzZZZ", "Swim", "Walk",         "Claw", "Hunt", "Mark Territory", 22);

    public inter() {

        topPanel = new JPanel();

        topPanel.setBackground(Color.lightGray);

        leftPanel = new JPanel();

        leftPanel.setBackground(Color.gray);

        rightPanel = new JPanel();

        rightPanel.setBackground(Color.gray);

        bottomPanel = new JPanel();

       bottomPanel.setBackground(Color.darkGray);

        middlePanel = new JPanel();

        middlePanel.setBackground(Color.lightGray);

        allPanels = new JPanel();

        allPanels.setLayout(new BoxLayout(allPanels, BoxLayout.Y_AXIS));

        topPanel.setLayout(new GridLayout(2,0));

        play = new JButton("Play");

        sleep = new JButton("Sleep");

        feed = new JButton("Feed");

        hunt = new JButton("Hunt");

        swim = new JButton("Swim");

        walk = new JButton("Roam");

        shop = new JButton("Shop");

        home = new JButton("Home");

        tigerText = new JTextArea();

        bottomPanel.setBorder(BorderFactory.createEmptyBorder(25,25,25, 25));

        bottomPanel.setLayout(new GridLayout(0, 4, 50, 10));

        bottomPanel.add(play);

        bottomPanel.add(sleep);

        bottomPanel.add(feed);

        bottomPanel.add(hunt);

        bottomPanel.add(swim);

        bottomPanel.add(walk);

        bottomPanel.add(shop);

        bottomPanel.add(home);

        middlePanel.add(tigerText);

        leftPanel.setBorder(BorderFactory.createEmptyBorder());    

            ImageIcon image = new ImageIcon("Images/Timmy the Tiger.jpg");

            leftPanel.add(new JLabel(image));

            leftPanel.setVisible(true);

      rightPanel.setBorder(BorderFactory.createEmptyBorder(30, 30, 30, 30));

        rightPanel.setLayout(new GridLayout(0, 1));

        tigerText = new JTextArea();

        tigerLabel = new JLabel();

        middlePanel.setLayout(new GridLayout(2,0));

        middlePanel.add(tigerLabel);

        middlePanel.add(tigerText);

        happyBar = new JProgressBar();

        happyBar.setMinimum(0);

        happyBar.setMaximum(500);

        happyBar.repaint();

        happyLabel = new JLabel("Happy");

        happyLabel.setForeground(Color.white);

        hungryBar = new JProgressBar(0,500);

        hungryLabel = new JLabel("Hungry");

        hungryBar.repaint();

        hungryLabel.setForeground(Color.white);

        energyBar = new JProgressBar(0,500);

        energyLabel = new JLabel("Energy");

        energyBar.repaint();

        energyLabel.setForeground(Color.white);

        hygieneBar = new JProgressBar(0,500);

        hygieneBar.setIndeterminate(true);

        hygieneLabel = new JLabel("Hygiene");

        hygieneBar.repaint();

        hygieneLabel.setForeground(Color.white);

        rightPanel.add(happyBar);

        rightPanel.add(happyLabel);

        happyLabel.setBounds(5, 5, 5, 5);

        happyBar.setBounds(15, 5, 5, 5);

        rightPanel.add(hungryBar);

        rightPanel.add(hungryLabel);

        hungryLabel.setBounds(5, 5, 5, 5);

        hungryBar.setBounds(15, 5, 5, 5);

        rightPanel.add(energyBar);

        rightPanel.add(energyLabel);

        energyLabel.setBounds(5, 5, 5, 5);

        energyBar.setBounds(15, 5, 5,5);

        rightPanel.add(hygieneBar);

        rightPanel.add(hygieneLabel);

        hygieneLabel.setBounds(5, 5, 5, 5);

        hygieneBar.setBounds(15, 5, 5, 5);

        hygieneBar.setValue(tigerHygieneCount);

        hungryBar.setValue(tigerHungerCount);

        energyBar.setValue(tigerEnergyCount);

        happyBar.setValue(tigerHappyCount);

        allPanels.add(topPanel);

        allPanels.add(leftPanel);

        allPanels.add(middlePanel);

        allPanels.add(bottomPanel);

        allPanels.add(rightPanel);

        tigerWindow = new JFrame();

        tigerWindow.setTitle("Pet Game: Tiger");

        tigerWindow.setSize(800,300);

        tigerWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        tigerWindow.setVisible(true);

        tigerWindow.add(allPanels);

        tigerWindow.getContentPane().add(leftPanel,BorderLayout.WEST);

        tigerWindow.getContentPane().add(rightPanel,BorderLayout.EAST);

        tigerWindow.getContentPane().add(bottomPanel,BorderLayout.SOUTH);

        tigerWindow.getContentPane().add(topPanel,BorderLayout.NORTH);

    }

        public JButton getPlayButton() {

            return play;

       }

        public JButton getSleepButton() {

            return sleep;

        }

        public JButton getFeedButton() {

            return feed;

        }

        public JButton getHuntButton() {

            return hunt;

        }

        public JButton getWalkButton() {

            return walk;

        }

        public JButton getSwimButton() {

            return swim;

        }

        public JButton getShopButton() {

            return shop;

        }

        public JButton getHomeButton() {

            return home;

        }

        public JPanel getPanels() {

            return allPanels;

        }

        play.addActionListener(new ActionListener(){

    public void actionPerformed(ActionEvent e){

        tiger.getPlay();

        updateProgressBars();

        tigerText.append("You have played with your pet ");

        tiger.death();

    }

        });

        sleep.addActionListener(new ActionListener(){

            public void actionPerformed(ActionEvent e){

                tiger.getSleep();

                updateProgressBars();

                tigerText.append("Your dog is asleep: Z Z Z ");

                tiger.death();

            }

        });

        feed.addActionListener(new ActionListener(){

            public void actionPerformed(ActionEvent e){

                tiger.getFeed();

                updateProgressBars();

                tigerText.append("You have fed your pet ");

                tiger.death();

            }

        });

        hunt.addActionListener(new ActionListener(){

            public void actionPerformed(ActionEvent e){

                tiger.getHunt();

                updateProgressBars();

                tigerText.append("Your Tiger has gone to hunt");

                tiger.death();

            }

        });

        walk.addActionListener(new ActionListener(){

            public void actionPerformed(ActionEvent e){

                tiger.getRoam();

                updateProgressBars();

                tigerText.append("Your Tiger has begun to roam");

                tiger.death();

            }

        });

        swim.addActionListener(new ActionListener(){

            public void actionPerformed(ActionEvent e){

                tiger.getSwim();

                updateProgressBars();

                tigerText.append("You have washed your dog ");

                tiger.death();

            }

        });

            }

        {

            home.addActionListener(new ActionListener(){

                public void actionPerformed(ActionEvent e){

                }

            });

            shop.addActionListener(new ActionListener(){

                public void actionPerformed(ActionEvent e){

                }

            });

        }

    public void updateProgressBars()

    {

        hungryBar.setValue(tiger.getHungry());

        energyBar.setValue(tiger.getEnergy());

        hygieneBar.setValue(tiger.getHygiene());

        happyBar.setValue(tiger.getHappy());

    }

    public void death()

    {

        tiger.death();

        tigerText.append("Dog has died ");

    }

    public void play() {

        hungryBar.setValue(tigerHungerCount--);

        energyBar.setValue(tigerEnergyCount--);

        hygieneBar.setValue(tigerHygieneCount--);

        happyBar.setValue(tigerHappyCount++);

        tigerText.append("You have played with your tiger");

        tigerText.append(" ");

    }

    public void sleep() {

        hungryBar.setValue(tigerHungerCount--);

        energyBar.setValue(tigerEnergyCount ++);

        hygieneBar.setValue(tigerHygieneCount --);

        happyBar.setValue(tigerHappyCount ++);

        tigerText.append("You let your tiger sleep");

        tigerText.append(" ");

    }

    public void feed() {

        hungryBar.setValue(tigerHungerCount++);

        energyBar.setValue(tigerEnergyCount --);

        hygieneBar.setValue(tigerHygieneCount --);

        happyBar.setValue(tigerHappyCount ++);

        tigerText.append("You have fed your tiger");

        tigerText.append(" ");

    }

    public void hunt() {

        hungryBar.setValue(tigerHungerCount++);

        energyBar.setValue(tigerEnergyCount --);

        hygieneBar.setValue(tigerHygieneCount --);

        happyBar.setValue(tigerHappyCount ++);

        tigerText.append("You let your tiger hunt");

        tigerText.append(" ");

    }

    public void walk() {

        hungryBar.setValue(tigerHungerCount++);

        energyBar.setValue(tigerEnergyCount --);

        hygieneBar.setValue(tigerHygieneCount --);

        happyBar.setValue(tigerHappyCount ++);

        tigerText.append("You made your tiger roam");

        tigerText.append(" ");

    }

    public void swim() {

        hungryBar.setValue(tigerHungerCount--);

        energyBar.setValue(tigerEnergyCount --);

        hygieneBar.setValue(tigerHygieneCount ++);

        happyBar.setValue(tigerHappyCount ++);

        tigerText.append("You made your tiger go for a swim");

        tigerText.append(" ");

    }

        }

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