Knowee
Questions
Features
Study Tools

Have the user input two integers between 1 to 20, inclusive. Create a teaParty method that takes two integer parameters that represent the quantity of tea and candy. In the teaParty method determine if the party is 1=bad, 2=good, or 3=great.A party is good (2) if both tea and candy are at least 5.if either tea or candy is at least double the amount of the other one, the party is great (3).if either tea or candy is less than 5, the party is always bad (1).Return to the main method the integer value if the party is 1=bad, 2=good, or 3=great.Method call Example: teaParty(tea, candy);Test Data:teaParty(6, 8) → 2teaParty(3, 8) → 1teaParty(20, 6) → 3

Question

Have the user input two integers between 1 to 20, inclusive. Create a teaParty method that takes two integer parameters that represent the quantity of tea and candy. In the teaParty method determine if the party is 1=bad, 2=good, or 3=great.A party is good (2) if both tea and candy are at least 5.if either tea or candy is at least double the amount of the other one, the party is great (3).if either tea or candy is less than 5, the party is always bad (1).Return to the main method the integer value if the party is 1=bad, 2=good, or 3=great.Method call Example: teaParty(tea, candy);Test Data:teaParty(6, 8) → 2teaParty(3, 8) → 1teaParty(20, 6) → 3

...expand
🧐 Not the exact question you are looking for?Go ask a question

Solution

Here is a step-by-step guide on how to implement the teaParty method in Java:

  1. First, you need to create a method named teaParty that takes two integer parameters, tea and candy.
public static int teaParty(int tea, int candy) {
    // method body goes here
}
  1. Inside the teaParty method, you need to implement the logic to determine if the party is bad, good, or great.

  2. First, check if either tea or candy is less than 5. If so, the party is bad, so return 1.

if (tea < 5 || candy < 5) {
    return 1;
}
  1. If the first condition is not met, check if either tea or candy is at least double the amount of the other. If so, the party is great, so return 3.
if (tea >= 2 * candy || candy >= 2 * tea) {
    return 3;
}
  1. If neither of the above conditions are met, the party is good, so return 2.
return 2;
  1. Now, you need to get the user input for tea and candy. In the main method, create a Scanner object to get the user input.
public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    System.out.println("Enter the quantity of tea:");
    int tea = scanner.nextInt();
    System.out.println("Enter the quantity of candy:");
    int candy = scanner.nextInt();
}
  1. Finally, call the teaParty method with the user input and print the result.
int result = teaParty(tea, candy);
System.out.println("The party is: " + result);

Here is the complete code:

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("Enter the quantity of tea:");
        int tea = scanner.nextInt();
        System.out.println("Enter the quantity of candy:");
        int candy = scanner.nextInt();
        int result = teaParty(tea, candy);
        System.out.println("The party is: " + result);
    }

    public static int teaParty(int tea, int candy) {
        if (tea < 5 || candy < 5) {
            return 1;
        }
        if (tea >= 2 * candy || candy >= 2 * tea) {
            return 3;
        }
        return 2;
    }
}

This problem has been solved

Similar Questions

In a school, there is a row of  N students, each with their own academic rating. The teachers want to reward the students with candies, but they have specific rules:Minimum Candy Rule: Every student must receive at least one candy.Higher Rating, More Candies: Students with a higher academic rating should receive more candies than their neighbors.What is the minimum number of candies you must give?Input FormatThe first and only argument is an integer array A representing the rating of children.Output FormatReturn an integer representing the minimum candies to be given.Example InputsInput 1: A = [1, 2]Input 2: A = [1, 5, 2, 1]Example OutputsOutput 1: 3Output 2: 7Problem Constraints1 <= N <= 105-109 <= A[i] <= 109

Chef is buying sweet things to prepare for Halloween!The shop sells both chocolate and candy.Each bar of chocolate has a tastiness of 𝑋X.Each piece of candy has a tastiness of 𝑌Y.One packet of chocolate contains 22 bars, while one packet of candy contains 55 pieces.Chef can only buy one packet of something sweet, and so has to make a decision: which one should he buy in order to maximize the total tastiness of his purchase?Print Chocolate if the packet of chocolate is tastier, Candy if the packet of candy is tastier, and Either if they have the same tastiness.Input FormatThe first line of input will contain a single integer 𝑇T, denoting the number of test cases.Each test case consists of one line of input, containing two space-separated integers 𝑋X and 𝑌Y — the tastiness of one bar of chocolate and one piece of candy, respectively.Output FormatFor each test case, output on a new line the answer:Chocolate if the packet of chocolate is tastier.Candy if the packet of candy is tastier.Either if they have the same tastiness.You may print each character of the output in either uppercase or lowercase, i.e, Candy, CANDY, CaNdY and cANDy will all be treated as equivalent.Constraints1≤𝑇≤1001≤T≤1001≤𝑋,𝑌≤101≤X,Y≤10Sample 1:InputOutput45 15 25 33 10ChocolateEitherCandyCandyExplanation:Test case 11: The packet of chocolate has a tastiness of 2×5=102×5=10, while the packet of candy has a tastiness of 5×1=55×1=5. The chocolate is tastier.Test case 22: The packet of chocolate has a tastiness of 2×5=102×5=10, while the packet of candy has a tastiness of 5×2=105×2=10. They have the same tastiness.Test case 33: The packet of chocolate has a tastiness of 2×5=102×5=10, while the packet of candy has a tastiness of 5×3=155×3=15. The candy is tastier.Test case 44: The packet of chocolate has a tastiness of 2×3=62×3=6, while the packet of candy has a tastiness of 5×10=505×10=50. The candy is tastier.

Develop a Java program for a ticket pricing system. Prompt the user to enter their age and the type of ticket they want to purchase (1 for regular, 2 for VIP). Use if-then-else statements to calculate the ticket price based on the following criteria:Regular Ticket Prices:Age 0-5: FreeAge 6-12: $10Age 13-18: $15Age 19 and above: $20VIP Ticket Prices:Age 0-5: $5Age 6-12: $15Age 13-18: $20Age 19 and above: $30Display the calculated ticket price to the user. Ensure that your program handles invalid input, such as negative age or an invalid ticket type.

Mary has a bag of candies and decides to share them with her friends.Input the total number of candies Mary has, the number of candies Mary eats, and the number of friends Mary wants to share the remaining candies with. Calculate the remaining candies after Mary eats some, and use a pointer to store the result. Calculate and display how many candies each friend will receive.Input format :The first line of input consists of an integer m, representing the total number of candies Mary has.The second line consists of an integer n, representing the number of candies Mary eats.The third line consists of an integer x, representing the number of friends to share with.Output format :

Mary has a bag of candies and decides to share them with her friends.Input the total number of candies Mary has, the number of candies Mary eats, and the number of friends Mary wants to share the remaining candies with. Calculate the remaining candies after Mary eats some, and use a pointer to store the result. Calculate and display how many candies each friend will receive.Input format :The first line of input consists of an integer m, representing the total number of candies Mary has.The second line consists of an integer n, representing the number of candies Mary eats.The third line consists of an integer x, representing the number of friends to share with.

1/1

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.