Question: NEED HELP import java.util.Scanner; public class FruitMethod { public static void main(String[] args) { // Declare and initialize three variables int oranges = 0; int

NEED HELP

import java.util.Scanner;

public class FruitMethod

{

public static void main(String[] args)

{

// Declare and initialize three variables

int oranges = 0;

int apples = 0;

int fruit=0;

Scanner keyboard = new Scanner(System.in);

//input statements to get oranges from user

System.out.println("Enter the number of oranges: ");

oranges = keyboard.nextInt();

//input statements to get apples from user

System.out.println("Enter the number of apples: ");

apples = keyboard.nextInt();

fruit = oranges + apples; //Calculate total fruit

// Display results of number of fruit

System.out.println("Total fruit is " + fruit);

}

}

  1. Move the code to display the results (lines 31 and 32) to a method definition nameddisplayResults.
  2. Replace the moved code with an appropriate method call.
  3. Compile and execute the code to ensure correct results.
  4. Add a method comment header to the method definition.
  5. Move the code to prompt the user for the number of oranges (lines 20 - 22) to a method definition namedinputOranges.
  6. Replace the moved code with an appropriate method call.
  7. Compile and execute the code to ensure correct results.
  8. Add a method comment header to the method definition.
  9. Move the code to prompt the user for the number of apples (lines 24 - 26) to a method definition namedinputApples.
  10. Replace the moved code with an appropriate method call.
  11. Compile and execute the code to ensure correct results.
  12. Add a method comment header to the method definition.
  13. Move the code to calculate the total fruit (line 29) to a method definition namedcalculateFruit.
  14. Replace the moved code with an appropriate method call.
  15. Compile and execute the code to ensure correct results.
  16. Add a method comment header to the method definition
  17. Don't forget to comment your code!!!

import java.util.Scanner;

public class FruitMethod

{

public static void main(String[] args)

{

// Declare and initialize three variables

int oranges = 0;

int apples = 0;

int fruit=0;

Scanner keyboard = new Scanner(System.in);

//input statements to get oranges from user

System.out.println("Enter the number of oranges: ");

oranges = keyboard.nextInt();

//input statements to get apples from user

System.out.println("Enter the number of apples: ");

apples = keyboard.nextInt();

fruit = oranges + apples; //Calculate total fruit

// Display results of number of fruit

System.out.println("Total fruit is " + fruit);

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!