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);
}
}
- Move the code to display the results (lines 31 and 32) to a method definition nameddisplayResults.
- Replace the moved code with an appropriate method call.
- Compile and execute the code to ensure correct results.
- Add a method comment header to the method definition.
- Move the code to prompt the user for the number of oranges (lines 20 - 22) to a method definition namedinputOranges.
- Replace the moved code with an appropriate method call.
- Compile and execute the code to ensure correct results.
- Add a method comment header to the method definition.
- Move the code to prompt the user for the number of apples (lines 24 - 26) to a method definition namedinputApples.
- Replace the moved code with an appropriate method call.
- Compile and execute the code to ensure correct results.
- Add a method comment header to the method definition.
- Move the code to calculate the total fruit (line 29) to a method definition namedcalculateFruit.
- Replace the moved code with an appropriate method call.
- Compile and execute the code to ensure correct results.
- Add a method comment header to the method definition
- 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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started