Question

Answer using Java

Part I: Feeding the Animals (3 points) Filename(s): PetShelter.java Alicia is responsible for buying a weeks supply of food

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Logic behind the code:

Let the money spent on each dog for food and medication be 2x.

Let the money spent on each cat for food and medication be x.

According to question-

No of dogs * 2 * x + No of cats * x = Weekly budget.

We will find x, and then further calculate 2 * x i.e the money spent on each dog.

Code -------------------->

public class Question {

public static void main (String args[]) {

Scanner s = new Scanner(System.in);

int cats, dogs, budget;

System.out.println("Enter number of cats");

cats = s.nextInt();

System.out.println("Enter number of dogs");

dogs= s.nextInt();

System.out.println("Enter weekly budget");

budget= s.nextInt();

int ans = moneySpentOnEachDog(cats, dogs, budget);

System.out.println(ans);

}

private static int moneySpentOnEachDog(int cats, int dogs, int budget) {

int ans = (budget / (2 * dogs + cats));

return 2 * ans;

}

}

Add a comment
Know the answer?
Add Answer to:
Answer using Java Part I: Feeding the Animals (3 points) Filename(s): PetShelter.java Alicia is responsible for...
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
  • For this assignment, suppose that a fence is recording entry and exit into the park via...

    For this assignment, suppose that a fence is recording entry and exit into the park via a string as the gate swings open and folks walk in or out with their pet. For example, C++ DP+dp+CP+cp would indicate that an adult dog and an adult entered the park, then a puppy and child entered the park, then an adult cat and an adult entered the park and finally a kitten and a child entered the park. From this information, note...

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