1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Helga [31]
3 years ago
11

Within MethodsPractice.java, write a method public static int planParty2(int f, int c, int p) that performs the same calculation

s as the previous problem, but returns the number of p-packs needed. planParty2 does not need to consider the number of extra cans, and it should not print anything. Here are some example arguments for the planParty2 method and their expected return values:

Computers and Technology
1 answer:
Vesna [10]3 years ago
3 0

Answer:

// class definition of MethodPractice

public class MethodPractice {

   // main method that begin program execution

   public static void main(String args[]) {

       // call to the planParty2 method is done using some parameter

       // and the return value is displayed

     System.out.println("The number of p-packs needed is: " + planParty2(9, 14, 6));

     System.out.println("The number of p-packs needed is: " + planParty2(4, 6, 3));

     System.out.println("The number of p-packs needed is: " + planParty2(4, 6, 4));

   }

   

   // planParty2 method with 3 parameters and it return an integer

   // the calculation needed to get the required pack is done here

   public static int planParty2(int f, int c, int p){

       // the party owner is added to list of friend

       // and the value is assigned to totalPeople

       int totalPeople = f + 1;

       // the totalPeople times the can drink

       // is assigned to totalDrinkNeeded

       int totalDrinkNeeded = totalPeople * c;

       // number of packs required is declared

       int numberOfPacks;

       // if the totalDrinkNeeded contains exact multiple of a pack

       // we return the numberOfPack by dividing totalDrinkNeeded with p

       if (totalDrinkNeeded % p == 0){

           return numberOfPacks = totalDrinkNeeded / p;

       }

       // else we compute if the totalDrinkNeeded is not a multiple of a pack

       //  first we get the remainder when the totalDrinkNeeded is divided with p

       // then the needed can is computed by subtracting remainder from p

       // the neededCan is added to totalDrinkNeeded, then divided with p

       // and assigned to numberOfPacks

       // numberOfPacks is returned.

       else {

           int remainder = totalDrinkNeeded % p;

           int neededCan = p - remainder;

           numberOfPacks = (totalDrinkNeeded + neededCan) / p;

           return numberOfPacks;

       }

   }

}

Explanation:

Image showing the detailed question is attached.

The program is written in Java and is well commented. A sample image of program output when it is executed is attached.

You might be interested in
How do you know if something is in the public domain
liraira [26]
You can start by looking at the date. Anything made before 1923, no matter what, will be definitely in the public domain. ... Most times, it's impossible to determine whether something is in the public domain just by the date. There are three ways you can find out definitively whether a work is in the public domain.
8 0
3 years ago
_____ allows you to use the internet for making phone calls instead of leasing traditional telephone lines from the phone compan
TEA [102]
Using a browser would help in doing that.
3 0
2 years ago
To create a datetime object for the current date and time, you can use theGroup of answer choicestoday() method of the date clas
SVEN [57.7K]

var theDate = new DateTime (DateTime.Today.Year, DateTime.Today.Month, DateTime.Today.Day, hours, minute, second);

6 0
2 years ago
Give state diagrams of DFAs that recognize the following languages.
k0ka [10]

Answer:

Following is attached the solution of each part step-by-step. I hope it will help you!

Explanation:

6 0
3 years ago
list the version of Windows you are using XP, Windows7, Windows8 and then explain the steps you will use to find the programs
zhannawk [14.2K]

The type of windows I am using is:Windows 8.1
7 0
3 years ago
Other questions:
  • [Submit on zyLabs] Please write a function with one input, a matrix, and one output, a matrix of the same size. The output matri
    10·1 answer
  • John would like to move from the city into the suburbs and has been saving up a large down payment for a home. Which is the most
    7·1 answer
  • Where is line-of-sight Internet common?<br> In space<br> Outdoors<br> Inside<br> In businesses
    10·1 answer
  • Where is permanent data in the computer stored whenever gym starts his laptop He sees some commands in numbers appearing on the
    12·1 answer
  • I need help with workplace safety systems please help
    10·1 answer
  • So I was looking at my profile and it says i'm a brainly PLUS member didn't sign up for it tho. Any ideas why this could have ha
    14·2 answers
  • How are online sources used? Check all that apply.
    8·2 answers
  • Software que busca, detecta y elimina malware tipo espía; puede instalarse en la computadora de manera aislada o en conjunto con
    11·1 answer
  • Define the term algorithm and describe how programmers use algorithms when designing a program.
    13·1 answer
  • HELPPP PLEASE <br><br> Html can be used to create complicated mobile applications <br> True or false
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!