Question

Java Code import java.util.Scanner; /** Create two methods as instructed below and then call them appropriately....

Java Code

import java.util.Scanner; /** Create two methods as instructed below and then call them appropriately. Hint: Only one of the methods you create needs to be called from the main method. */

public class LandCalculation

{

public static void main(String[] args)

{

final int FEET_PER_ACRE = 43560; // Number of feet per acre

double tract = 0.0, acres = 0.0;

Scanner keyboard = new Scanner(System.in);

System.out.print("Enter the tract size: ");

tract = keyboard.nextDouble(); // Validate the user's input. while(tract < 1)

{

System.out.print("Tract must be at least 1 square foot. Enter the tract size: ");

tract = keyboard.nextDouble();

}

// Calculate the number of acres.

acres = tract / 43560;

// Display the results. System.out.printf("A tract of land with %,.2f square feet has %,.2f acres.", tract, acres);

}

/** Write a method here that accepts a size (in square feet) of a tract of land The method should return the size (in acres) of that tract of land */ /** Write a void method here that accepts a size (in square feet) of a tract of land The method should print out a message that displays the size of the tract of land in square feet and in acres */

}

end of code.....

Rewrite the Java code so that it adheres to what is asked in the comment section.

Once completed with no errors, it should look like this

Enter the tract size: -1

Invalid input! Tract size must be 1 or greater.

Enter the tract size: 123456

A tract of land with 123,456.00 square feet has 2.83 acres.

Homework Answers

Answer #1

CODE:

OUTPUT:

RAW CODE:

import java.util.*;
public class LandCalculation{
   public static void main(String[] args){
       final int FEET_PER_ACRE = 43560; // Number of feet per acre
       double tract = 0.0, acres = 0.0;
       Scanner keyboard = new Scanner(System.in);
       System.out.print("Enter the tract size: ");
       tract = keyboard.nextDouble(); // Validate the user's input. while(tract < 1)
       while(tract < 1 ){
           System.out.print("Tract must be at least 1 square foot.\nEnter the tract size: ");
           tract = keyboard.nextDouble();
       }

       // calling methods

       acres = Tract_to_Acres(tract); // calling the Tract_to_Acres() method with tract as parameter
       System.out.printf("A tract of land with %,.2f square feet has %,.2f acres.", tract, acres); // Display the results.
       System.out.println(); // new line

       tract_to_acres(tract); // calling the void tract_to_acres() method with tract as parameter
       System.out.println(); // new line
   }

   /** Write a method here that accepts a size (in square feet) of a tract of land The method should return the size (in acres) of
   that tract of land **/
   static Double Tract_to_Acres(double tract){
       double acres = tract / 43560 ; // Calculate the number of acres
       return (acres);
   }
   /** Write a void method here that accepts a size (in square feet) of a tract of land The method should print
   out a message that displays the size of the tract of land in square feet and in acres **/
   static void tract_to_acres(double tract){
       double acres = tract / 43560 ; // Calculate the number of acres
       System.out.printf("A tract of land with %,.2f square feet has %,.2f acres.", tract, acres); // Display the results.
   }
}

NOTE:
If You have any doubts feel free to comment in comment section.
DO VOTE(LIKE).

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Covert the following Java program to a Python program: import java.util.Scanner; /* Calculates and displays the...
Covert the following Java program to a Python program: import java.util.Scanner; /* Calculates and displays the area of a rectangle * based on the width and length entered by the user. */ public class RectangleArea2 {             public static void main(String[] args) { int length; //longer side of rectangle             int width; //shorter side of rectangle int area; //calculated area of rectangle Scanner input = new Scanner(System.in);                               System.out.print("Enter the length: ");            length = input.nextInt(); System.out.print("Enter...
Covert the following Java program to a Python program: import java.util.Scanner; /** * Displays the average...
Covert the following Java program to a Python program: import java.util.Scanner; /** * Displays the average of a set of numbers */ public class AverageValue { public static void main(String[] args) { final int SENTINEL = 0; int newValue; int numValues = 0;                         int sumOfValues = 0; double avg; Scanner input = new Scanner(System.in); /* Get a set of numbers from user */ System.out.println("Calculate Average Program"); System.out.print("Enter a value (" + SENTINEL + " to quit): "); newValue =...
JAVA 4.35 (Sides of a Triangle) Write an application that reads three nonzero values entered by...
JAVA 4.35 (Sides of a Triangle) Write an application that reads three nonzero values entered by the user and determines and prints whether they could represent the sides of a triangle. Here's the code: import java.util.Scanner; class TriangleYN {    public static void main(String[] args) {        Scanner input = new Scanner(System.in);               double a;        double b;        double c;               System.out.print("Enter three sizes, separated by spaces(decimals values are acceptable):");...
IN JAVA Methods*: Calorie estimator Write a method ActivityCalories that takes a string indicating an activity...
IN JAVA Methods*: Calorie estimator Write a method ActivityCalories that takes a string indicating an activity (sit, walk, jog, bike, swim) and duration in minutes (integer), and returns the estimated calories expended (double). Calories per minute for a 150 lb person (source): sit: 1.4 walk: 5.4 run: 13.0 bike: 6.8 swim: 8.7 If the input is sit 2, the output is 2.8 Hints: Use an if-else statement to determine the calories per minute for the given activity. Return the calories...
2). Question with methods use scanner (Using Java): You are going to invest the amount, then...
2). Question with methods use scanner (Using Java): You are going to invest the amount, then you going to compute that amount with annual interest rate. 1) Prompt the user to enter student id, student name, student major 2) Declare variables consistent with names that you are prompting and relate them to the scanner 3) Declare the amount invested in college, prompt the user to ask for amount and declare variable and scanner to input 4) Declare the annual interest...
Download the ProductUpTo3.java file, and open it in jGrasp (or a text editor of your choice)....
Download the ProductUpTo3.java file, and open it in jGrasp (or a text editor of your choice). This program will read in three integers with Scanner, put the values in an array of int, and then print the product of the three values. Example output of the program is shown below, with user input shown in bold: Enter first integer: 3 Enter second integer: 4 Enter third integer: 5 Product: 60 More details about the method you need to write are...
I need this before the end of the day please :) In Java 10.13 Lab 10...
I need this before the end of the day please :) In Java 10.13 Lab 10 Lab 10 This program reads times of runners in a race from a file and puts them into an array. It then displays how many people ran the race, it lists all of the times, and if finds the average time and the fastest time. In BlueJ create a project called Lab10 Create a class called Main Delete what is in the class you...
import java.util.Scanner; public class InRange { private int min; private int max; public InRange(int initialMin, int...
import java.util.Scanner; public class InRange { private int min; private int max; public InRange(int initialMin, int initialMax) { min = initialMin; max = initialMax; } // You need to write two instance methods: // 1.) A method named inRange, which takes an int. // This returns true if the int is within the given range // (inclusive), else false. // // 2.) A method named outOfRange which takes an int. // This returns false if the int is within the...
import java.util.Scanner; import java.util.Random; public class ScoreDice { private Random r; public ScoreDice(long seed) { r...
import java.util.Scanner; import java.util.Random; public class ScoreDice { private Random r; public ScoreDice(long seed) { r = new Random(seed); } public int rollD6() { return r.nextInt(6) + 1; } public int score() { int roll1 = rollD6(); int roll2 = rollD6(); return scoreWithNumbers(roll1, roll2); }    // You will need to write a static method named scoreWithNumbers. // scoreWithNumbers returns a score based on the values // of its inputs, as such: // // - If both inputs are 1...
2.13 LAB: Driving cost - methods Write a method drivingCost() with input parameters drivenMiles, milesPerGallon, and...
2.13 LAB: Driving cost - methods Write a method drivingCost() with input parameters drivenMiles, milesPerGallon, and dollarsPerGallon, that returns the dollar cost to drive those miles. All items are of type double. If the method is called with 50 20.0 3.1599, the method returns 7.89975. Define that method in a program whose inputs are the car's miles/gallon and the gas dollars/gallon (both doubles). Output the gas cost for 10 miles, 50 miles, and 400 miles, by calling your drivingCost() method...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT