Posted on

Question 1 Feeding your pet dog 7 Marks Dogs eat food which creates energy that they use to go

Question 1: Feeding your pet dog [7 Marks] Dogs eat food, which creates energy that they use to go about their lives. But how much food should you feed your dog? Your job is to write a simple program that helps people decide how much to feed their dog per day. Note: Creating more than one Scanner on System.in in the same program will cause problems. Create ONE Scanner in main, and pass it to any methods that need it. a) Weight How much you should feed your dog depends on how much it weighs. For every pound of the dog, they should have a quarter cup of food. Write a method called convertKGtoLB that accepts one double parameter - a weight in kilograms (kg). The method should calculate and return a double value - the same weight converted to pounds (lb). Write a method called readWeight that receives a Scanner as a parameter. Using the Scanner, the method should read in a dog's weight from the user and return it as a double. Ask the user if they want to enter a weight in kilograms or pounds - prompt the user to enter the letters 'k' for kilograms or 'p' for pounds. Then read in the user's response using the Scanner. If the user enters something other than 'k' or 'p', assume that they want to use pounds and print a reasonable message telling them so. Then prompt the user to enter the dog's weight in the chosen units and read it in as a double. This method should return the weight in pounds. If they entered the weight as kilograms, convert it to pounds by using the convertKGtoLB method. Puppies need more food to grow big and strong. Puppies should eat a half cup of food per pound they weigh. Write a method called readIsPuppy that receives a Scanner as a parameter. Using the Scanner, the method should read in if the dog is a puppy (a baby dog). Ask the user if the dog is a puppy - prompt the user to enter the letters 'y' for yes or 'n' for no. Then read in the user's response using Scanner. If the user enters something other than 'y' or 'n', assume that it is not a puppy and print a reasonable message telling them so. This method should return a boolean. Return true if the dog is a puppy, or false if not a puppy. c) Activity Level More active dogs will need more food. For every four miles walked a day, a dog should get a quarter cup more food. Write a method called convertKMtoMI that accepts one double parameter - a distance in kilometers (km). The method should calculate and return a double value - the same distance converted to miles (mi). Write a method called readActivityLevel that receives a Scanner as a parameter. Using the Scanner, the method should read in a dog's daily walking distance and return it as a double. Ask the user if they want to enter a distance in kilometers or miles - prompt the user to enter the letters 'k' for kilometers or 'm' for miles. Then read in the user's response using the Scanner. If the user enters something other than 'k' or 'm', assume that they want to use miles and print a reasonable message telling them so. Then prompt the user to enter the dog's daily walking distance in the chosen units and read it in as a double. This method should return the distance in miles. If they entered the distance as kilometers, convert it to miles by using the convertKMtoMI method. d) Breed Some dog breeds have special requirements. Labradors and Golden Retrievers should get a quarter cup more food per 5 pounds they weigh. German Shepherds should get a quarter cup more food per seven pounds they weigh. Bernese Mountain Dogs should get a quarter cup less food per ten pounds they weigh. Other breeds do not have special considerations. Write a method called readDogBreed that receives a Scanner as a parameter. Using the Scanner, the method should read in a dog's breed and return it as a char. Prompt the user to enter a letter to represent their dog breed as follows: 'l' for Labrador, 'r' for Golden Retriever, 'g' for German Shepherd, 'b' for Bernese Mountain Dog, or 'o' for other. Then read in the user's response using Scanner. If the user enters something other than 'l', 'r', 'g', 'b' or 'o', assume that their dog is other and print a reasonable message telling them so. This method should return the letter of the dog breed. e) Calculate the Amount Write a method called findFoodAmount that accepts several parameters - a weight in pounds (lb), whether the dog is a puppy, the dog's daily walking distance (mi), and the dog's breed. The method should compute and return the amount of food to feed the dog. In addition to the amounts stated above, the following must also be considered: - Overweight dogs should get one cup less. An overweight Labrador, Golden Retriever, or German Shepherd is over 80 lbs. An overweight Bernese Mountain Dog is over 90 lbs. There is no limit known for other breeds of dogs. - Puppies should also get one cup less, but overweight puppies (over 80/90 pounds, as above) should not have a reduction in their food. f) Print the amount Write a method called printFoodAmount that accepts the amount of food to feed the dog. The method should print a nice message telling the user how much food to feed their dog. Question 2: Farkle Scoring [8 Marks] Farkle is a dice game where you roll six dice and try to be the first to score 10,000 points or more. Your job is to create a Farkle scoring program. Given one to six dice, you will determine the score for those dice. Farkle Rules: - Each person rolls six dice and sees if they have rolled any scoring dice or combinations. Any dice that score may be set aside. You must set aside at least one scoring dice of your choice, if possible, but it is not required to set aside all scoring dice. Then you may choose to roll the remaining dice. - For example, if you rolled 1-3-3-5-5-6, you could set aside the 1 and the two 5's for scoring, or you could choose to set aside only the 1. All dice that are not set aside may be rerolled. - If all six dice are set aside for scoring, you can roll all six dice again and continue adding to your accumulated score. Or you can bank your points, end your turn, and pass the dice to the next player. - Your turn continues until either you decide to stop and score your points, or until you fail to roll any scoring dice on a throw (known as a Farkle) and all your points gained so far on that turn are lost. - At the end of your turn, any points you have scored are written down and the dice are passed to the next player. Reminder 1: Your job is to create a Farkle scoring program. Given 1 to 6 dice in ascending order, you will determine the score for those dice. You are not implementing a complete game. Reminder 2: This assignment should be completed using material from Weeks 1-6. (No loops needed!) c) Print the score Write a method called printScore that accepts the score. The method should print a nice message telling the user how much they scored. If the user scored zero points, the program should print "Farkle!". Example Outputs: Dice to Score: 123456 Points Earned: 3000 Dice to Score: 123555 Points Earned: 600 Dice to Score: 223346 Farkle!

Question 1: Feeding your pet dog [7 Marks]

Dogs eat food, which creates energy that they use to go about their lives. But how much food should you feed your dog? Your job is to write a simple program that helps people decide how much to feed their dog per day.

Note: Creating more than one Scanner on System.in in the same program will cause problems. Create ONE Scanner in main, and pass it to any methods that need it.

a) Weight

How much you should feed your dog depends on how much it weighs. For every pound of the dog, they should have a quarter cup of food.

Write a method called convertKGtoLB that accepts one double parameter – a weight in kilograms (kg). The method should calculate and return a double value – the same weight converted to pounds (lb).

Write a method called readWeight that receives a Scanner as a parameter. Using the Scanner, the method should read in a dog’s weight from the user and return it as a double. Ask the user if they want to enter a weight in kilograms or pounds – prompt the user to enter the letters ‘k’ for kilograms or ‘p’ for pounds. Then read in the user’s response using the Scanner. If the user enters something other than ‘k’ or ‘p’, assume that they want to use pounds and print a reasonable message telling them so. Then prompt the user to enter the dog’s weight in the chosen units and read it in as a double. This method should return the weight in pounds. If they entered the weight as kilograms, convert it to pounds by using the convertKGtoLB method.

Puppies need more food to grow big and strong. Puppies should eat a half cup of food per pound they weigh.

Write a method called readIsPuppy that receives a Scanner as a parameter. Using the Scanner, the method should read in if the dog is a puppy (a baby dog). Ask the user if the dog is a puppy – prompt the user to enter the letters ‘y’ for yes or ‘n’ for no. Then read in the user’s response using Scanner. If the user enters something other than ‘y’ or ‘n’, assume that it is not a puppy and print a reasonable message telling them so. This method should return a boolean. Return true if the dog is a puppy, or false if not a puppy.

c) Activity Level

More active dogs will need more food. For every four miles walked a day, a dog should get a quarter cup more food.

Write a method called convertKMtoMI that accepts one double parameter – a distance in kilometers (km). The method should calculate and return a double value – the same distance converted to miles (mi).

Write a method called readActivityLevel that receives a Scanner as a parameter. Using the Scanner, the method should read in a dog’s daily walking distance and return it as a double. Ask the user if they want to enter a distance in kilometers or miles – prompt the user to enter the letters ‘k’ for kilometers or ‘m’ for miles. Then read in the user’s response using the Scanner. If the user enters something other than ‘k’ or ‘m’, assume that they want to use miles and print a reasonable message telling them so. Then prompt the user to enter the dog’s daily walking distance in the chosen units and read it in as a double. This method should return the distance in miles. If they entered the distance as kilometers, convert it to miles by using the convertKMtoMI method.

d) Breed

Some dog breeds have special requirements. Labradors and Golden Retrievers should get a quarter cup more food per 5 pounds they weigh. German Shepherds should get a quarter cup more food per seven pounds they weigh. Bernese Mountain Dogs should get a quarter cup less food per ten pounds they weigh. Other breeds do not have special considerations.

Write a method called readDogBreed that receives a Scanner as a parameter. Using the Scanner, the method should read in a dog’s breed and return it as a char. Prompt the user to enter a letter to represent their dog breed as follows: ‘l’ for Labrador, ‘r’ for Golden Retriever, ‘g’ for German Shepherd, ‘b’ for Bernese Mountain Dog, or ‘o’ for other. Then read in the user’s response using Scanner. If the user enters something other than ‘l’, ‘r’, ‘g’, ‘b’ or ‘o’, assume that their dog is other and print a reasonable message telling them so. This method should return the letter of the dog breed.

e) Calculate the Amount

Write a method called findFoodAmount that accepts several parameters – a weight in pounds (lb), whether the dog is a puppy, the dog’s daily walking distance (mi), and the dog’s breed. The method should compute and return the amount of food to feed the dog.

In addition to the amounts stated above, the following must also be considered:
– Overweight dogs should get one cup less. An overweight Labrador, Golden Retriever, or German Shepherd is over 80 lbs. An overweight Bernese Mountain Dog is over 90 lbs. There is no limit known for other breeds of dogs.
– Puppies should also get one cup less, but overweight puppies (over 80/90 pounds, as above) should not have a reduction in their food.

f) Print the amount

Write a method called printFoodAmount that accepts the amount of food to feed the dog. The method should print a nice message telling the user how much food to feed their dog.

Question 2: Farkle Scoring [8 Marks]

Farkle is a dice game where you roll six dice and try to be the first to score 10,000 points or more. Your job is to create a Farkle scoring program. Given one to six dice, you will determine the score for those dice.

Farkle Rules:
– Each person rolls six dice and sees if they have rolled any scoring dice or combinations. Any dice that score may be set aside. You must set aside at least one scoring dice of your choice, if possible, but it is not required to set aside all scoring dice. Then you may choose to roll the remaining dice.
– For example, if you rolled 1-3-3-5-5-6, you could set aside the 1 and the two 5’s for scoring, or you could choose to set aside only the 1. All dice that are not set aside may be rerolled.
– If all six dice are set aside for scoring, you can roll all six dice again and continue adding to your accumulated score. Or you can bank your points, end your turn, and pass the dice to the next player.
– Your turn continues until either you decide to stop and score your points, or until you fail to roll any scoring dice on a throw (known as a Farkle) and all your points gained so far on that turn are lost.
– At the end of your turn, any points you have scored are written down and the dice are passed to the next player.

Reminder 1: Your job is to create a Farkle scoring program. Given 1 to 6 dice in ascending order, you will determine the score for those dice. You are not implementing a complete game.

Reminder 2: This assignment should be completed using material from Weeks 1-6. (No loops needed!)

c) Print the score

Write a method called printScore that accepts the score. The method should print a nice message telling the user how much they scored. If the user scored zero points, the program should print “Farkle!”.

Example Outputs:
Dice to Score: 123456
Points Earned: 3000

Dice to Score: 123555
Points Earned: 600

Dice to Score: 223346
Farkle!


 
Solved By Verified
Study Co-Pilot All Study Co-Pilots are evaluated by Gotit Pro as an expert in their subject area.

 
Instant
Download

Student review: (4 ratings) 4 out of 4 people found this solution helpful.