Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions