Questions Uploads

program’s output

For each of the following steps, end the program’s output with a newline.

(1) Write program that outputs the following. (Submit for 1 point).

Hello world!

(2) Update to output the following. (Submit again for 1 more point, so 2 points total).

Hello world!
How are you? 

(3) Finally, update to output the following. End with a newline. (Submit again for 1 more point, so 3 points total).

Hello world!
How are you?
   (I'm fine).
 
Looking for a Similar Assignment? Order now and Get 10% Discount! Use Coupon Code "Newclient"

JAVA code.

Hi- I need some help with JAVA code.

  • When I select 1 for animal, it’ll ask for which animal. If I select 1 to 3, it works but if I select animal #4 it throws my index error even though it’s within the limit
  • When I select 2 for habitat, it’ll ask for which habitat. Whatever number I select here, it’ll actually end up listing the animal for that index and not the habitat. If I select habitat #3, it’ll through my index error as well even though it’s within the limit

I also need to implement a pop up alert whenever the animal/habit with ***** are selected. The alert needs to display the message without the *****

Monitor.JAVA

import java.io.File;

import java.io.FileNotFoundException;

import java.util.ArrayList;

import java.util.Scanner;

import java.util.logging.Level;

import java.util.logging.Logger;

import javax.swing.JOptionPane;

/**

 * Monitor

 * @

 */

public class Monitor {

  static ArrayList<Animal> animals = new ArrayList<>();

  static ArrayList<Habitat> habitats = new ArrayList<>();

  public static void main(String[] args) {

    readAnimals(“animals.txt”);

    readHabitats(“habitats.txt”);

    Scanner input = new Scanner(System.in);

    int choice;

    while(true) {

      System.out.println(“Please select what you would like to view:nEnter 1 to monitor AnimalnEnter 2 to monitor HabitatnEnter 3 to Exit”);     

      choice = input.nextInt();

      if(choice == 1) {

        System.out.println(“Displaying animals…”);

        for(int i = 0; i < animals.size(); i++) {

          System.out.println((i+1) + “. ” + animals.get(i).getCategory());

        }

        System.out.print(“Choose animal index?n”);

        int index = input.nextInt();

        if(index >= animals.size()) {

          System.out.println(“error: invalid index!!”);

        } else {

          if(animals.get(index).getHealthConcerns().startsWith(“*****”)) {  //MODIFIED

            Animal anml = animals.get(index);  //MODIFIED

            String str = “Animal – ” + anml.getCategory() + “n”

                + “Name: ” + anml.getName() + “n”

                + “Age: ” + anml.getAge() + “n”

                + “Health concerns: ” + anml.getHealthConcerns().substring(anml.getHealthConcerns().indexOf(“: “) + 2) +

                “nFeeding schedule: ” + anml.getFeedingSchedule().substring(anml.getFeedingSchedule().indexOf(“: “) + 2);

            JOptionPane.showMessageDialog(null, str);

          } else {

            System.out.println(animals.get(index)); //MODIFIED

          }

        }

      } else if(choice == 2) {

        System.out.println(“Displaying habitats…”);

        for(int i = 0; i < habitats.size(); i++) {

          System.out.println((i+1) + “. ” + habitats.get(i).getCategory());           

        }

        System.out.print(“Choose habitat index?n”);

        int index = input.nextInt();

        if(index >= habitats.size()) {

          System.out.println(“error: invalid index!!”);

        } else {

          if(habitats.get(index).getFoodSource().startsWith(“*****”)) { //MODIFIED

            Habitat hab = habitats.get(index); //MODIFIED

            String str = “Habitat – ” + hab.getCategory() + 

                “n” + hab.getTemperature() + “n”

                + “Cleanliness: ” + hab.getCleanliness().substring(hab.getCleanliness().indexOf(“:”) + 2)

                + “nFood Source: ” + hab.getFoodSource().substring(hab.getFoodSource().indexOf(“:”) + 2);

            JOptionPane.showMessageDialog(null, str);

          } else {

            System.out.println(animals.get(index)); //MODIFIED

          }

        }

      } else if(choice == 3) {

        break;

      } else {

        System.out.println(“Invalid choice”);

      }

    }     

  }  

  public static void readAnimals(String filename) {

    try {

      Scanner fileIn = new Scanner(new File(filename));

      while(fileIn.hasNextLine()) {

        String line = fileIn.nextLine();

        if(line.startsWith(“Animal – “)) {

          String category = line.substring(line.indexOf(“-“)+2);      

          line = fileIn.nextLine();

          String name = line.substring(line.indexOf(“:”)+2);

          line = fileIn.nextLine();

          int age = Integer.parseInt(line.substring(line.indexOf(“:”)+2));

          line = fileIn.nextLine();

          String concerns = line;//.substring(line.indexOf(“:”)+2);

          line = fileIn.nextLine();

          String feedingScehdule = line;//.substring(line.indexOf(“:”)+2);

          Animal animal = new Animal(category, name, age, concerns, feedingScehdule);

          animals.add(animal);

          //System.out.println(“adding…n” + animal);

        }

      }

    } catch (FileNotFoundException ex) {

      Logger.getLogger(Monitor.class.getName()).log(Level.SEVERE, null, ex);

    }

  }

  public static void readHabitats(String filename) {

    try {

      Scanner fileIn = new Scanner(new File(filename));

      while(fileIn.hasNextLine()) {

        String line = fileIn.nextLine();

        if(line.startsWith(“Habitat – “)) {

          String category = line.substring(line.indexOf(“-“)+1);           

          line = fileIn.nextLine();

          String temp = line;

          line = fileIn.nextLine();

          String foodSource = line;

          line = fileIn.nextLine();

          String cleanliness = line;

          Habitat habitat = new Habitat(category, temp, foodSource, cleanliness);

          habitats.add(habitat);

          //System.out.println(“adding…n” + habitat);

        }

      }

    } catch (FileNotFoundException ex) {

      Logger.getLogger(Monitor.class.getName()).log(Level.SEVERE, null, ex);

    }

  }

}

Habitat.JAVA

public class Habitat {

  private String category;

  private String temperature;

  private String foodSource;

  private String cleanliness;

  public Habitat(String category, String temperature, String foodSource, String cleanliness) {

    this.category = category;

    this.temperature = temperature;

    this.foodSource = foodSource;

    this.cleanliness = cleanliness;

  }

  public String getCategory() {

    return category;

  }

  public void setCategory(String category) {

    this.category = category;

  }

  public String getTemperature() {

    return temperature;

  }

  public void setTemperature(String temperature) {

    this.temperature = temperature;

  }

  public String getFoodSource() {

    return foodSource;

  }

  public void setFoodSource(String foodSource) {

    this.foodSource = foodSource;

  }

  public String getCleanliness() {

    return cleanliness;

  }

  public void setCleanliness(String cleanliness) {

    this.cleanliness = cleanliness;

  }

  public String toString() {

    String str = “Habitat – ” + category + 

        “n” + temperature +

        “n” + foodSource +

        “n” + cleanliness;

    return str;

  }

}

Animal.JAVA

public class Animal {

  private String category;

  private String name;

  private int age;

  private String healthConcerns;

  private String feedingSchedule;

  public Animal(String category, String name, int age, String healthConcerns, String feedingSchedule) {

    this.category = category;

    this.name = name;

    this.age = age;

    this.healthConcerns = healthConcerns;

    this.feedingSchedule = feedingSchedule;

  }

  public String getCategory() {

    return category;

  }

  public void setCategory(String category) {

    this.category = category;

  }

  public String getName() {

    return name;

  }

  public void setName(String name) {

    this.name = name;

  }

  public int getAge() {

    return age;

  }

  public void setAge(int age) {

    this.age = age;

  }

  public String getHealthConcerns() {

    return healthConcerns;

  }

  public void setHealthConcerns(String healthConcerns) {

    this.healthConcerns = healthConcerns;

  }

  public String getFeedingSchedule() {

    return feedingSchedule;

  }

  public void setFeedingSchedule(String feedingSchedule) {

    this.feedingSchedule = feedingSchedule;

  }

  @Override

  public String toString() {

    String str = “Animal – ” + category + 

        “n” + “Name: ” + name +

        “n” + “Age: ” + age +

        “n” + healthConcerns +

        “n” + feedingSchedule;

    return str;

  }

}

habitats.TXT

Details on penguin habitat

Details on bird house

Details on aquarium

Habitat – Penguin

Temperature: Freezing

*****Food source: Fish in water running low

Cleanliness: Passed

Habitat – Bird

Temperature: Moderate

Food source: Natural from environment

Cleanliness: Passed

Habitat – Aquarium

Temperature: Varies with output temperature

Food source: Added daily

*****Cleanliness: Needs cleaning from algae

animals.TXT

Details on lions

Details on tigers

Details on bears

Details on giraffes

Animal – Lion

Name: Leo

Age: 5

*****Health concerns: Cut on left front paw

Feeding schedule: Twice daily

Animal – Tiger

Name: Maj

Age: 15

Health concerns: None

Feeding schedule: 3x daily

Animal – Bear

Name: Baloo

Age: 1

Health concerns: None

*****Feeding schedule: None on record

Animal – Giraffe

Name: Spots

Age: 12

Health concerns: None

Feeding schedule: Grazing

 
Looking for a Similar Assignment? Order now and Get 10% Discount! Use Coupon Code "Newclient"

PYTHON 3

USING PYTHON 3

I need help incorporating this feedback into my code. The script I have written DOES work, but it is not what my teacher is asking. I am unable to go back and reread the book due to once completing it you are no longer able to view those chapters. Thanks!

FROM INSTRUCTOR:

“Input (Parameters) Function(s): Your functions did not utilize input parameters. For example, the deposit() function should be deposit(amount) and when you call it, you pass in the amount you want to deposit. Also, you should separate your print statements from the functions. Functions should do one thing and one thing only (return account balance for example) and then the calling code handles output to the user.

Script Comments: Your comments should explain what the code is doing. A number of your comments do not help understand what the code is doing, they merely point out that there is a function.  

#add another custom function here

#another example of a function…

Input (Parameters) Function(s): Your functions did not utilize input parameters. For example, the deposit() function should be deposit(amount) and when you call it, you pass in the amount you want to deposit. Also, you should separate your print statements from the functions. Functions should do one thing and one thing only (return account balance for example) and then the calling code handles output to the user.”

MY CODE IS:

import sys

#account balance

account_balance = float(500.25)

#After defining our initial account balance, we start here with a custom function.

def balance():

#The following line is an example of a function which returns the current balance output.

 print(‘Your current balance: n %.2f’% float(account_balance))

#add another custom function here:

def deposit():

 deposit_amount = float(input(‘How much would you like to deposit today?n’))

 balance = account_balance + deposit_amount

#Another example of a function used to return the correct output, here the account balance and the deposit amount were added together for the total sum.

 print(‘Deposit was $%.2f, current balance is $%.2f’ % (deposit_amount, balance))

#We finish with a final custom function and branching in the following block of code.

def withdraw():

#The following code is an input parameter within a function. 

withdraw_amount = float(input(‘How much would you like to withdraw today?n’))

 if withdraw_amount >= account_balance:

   print(‘$%.2f is greater than your account balance of $%.2f’ % (withdraw_amount, account_balance))

 else:

   balance = account_balance – withdraw_amount

   print(‘Withdrawal amount was $%.2f, current balance is $%.2f’ % (withdraw_amount, balance))

#Finally we gather the user input using if, else, and elif conditional statements which then call the functions entered previously based on what the user inputs.

userchoice = input (“What would you like to do?n”)

if (userchoice == ‘D’):

   deposit ()

elif (userchoice == ‘W’):

   withdraw()

elif (userchoice == ‘B’):

   balance()

print(‘Thank you for banking with us.’)

 
Looking for a Similar Assignment? Order now and Get 10% Discount! Use Coupon Code "Newclient"

java code

I need help creating a java code. The code must contain two classes

As a zookeeper, it is important to know the activities of the animals in your care and to monitor their living habitats.

build monitoring system that does all of the following: 

Asks a user if they want to monitor an animal, monitor a habitat, or exit

Displays a list of animal/habitat options (based on the previous selection) as read from either the animals or habitats file (Animal and habit list will be at the bottom)

Asks the user to enter one of the options from the animal or habit list that was shown

Displays the monitoring information by finding the appropriate section in the file

Separates sections by the category and selection (such as “Animal – Lion” or “Habitat -Penguin”)

Uses a dialog box to alert the zookeeper if the monitor detects something out of the normal range (These will be denoted in the files by a new line starting with *****. Do not display the asterisks in the dialog.)

Allows a user to return to the original options

You are allowed to add extra animals, habitats, or alerts, but you may not remove the existing ones. 

ANIMAL FILE:

Details on lions
Details on tigers
Details on bears
Details on giraffes

Animal - Lion
Name: Leo
Age: 5
*****Health concerns: Cut on left front paw
Feeding schedule: Twice daily

Animal - Tiger
Name: Maj
Age: 15
Health concerns: None
Feeding schedule: 3x daily

Animal - Bear
Name: Baloo
Age: 1
Health concerns: None
*****Feeding schedule: None on record

Animal - Giraffe
Name: Spots
Age: 12
Health concerns: None
Feeding schedule: Grazing

HABITAT FILE:

Details on penguin habitat
Details on bird house
Details on aquarium

Habitat - Penguin
Temperature: Freezing
*****Food source: Fish in water running low
Cleanliness: Passed

Habitat - Bird
Temperature: Moderate
Food source: Natural from environment
Cleanliness: Passed

Habitat - Aquarium
Temperature: Varies with output temperature
Food source: Added daily
*****Cleanliness: Needs cleaning from algae
 
Looking for a Similar Assignment? Order now and Get 10% Discount! Use Coupon Code "Newclient"