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 =...
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.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...
please write the code in java so it can run on jGRASP import java.util.Scanner; 2 import...
please write the code in java so it can run on jGRASP import java.util.Scanner; 2 import java.io.*; //This imports input and output (io) classes that we use 3 //to read and write to files. The * is the wildcard that will 4 //make all of the io classes available if I need them 5 //It saves me from having to import each io class separately. 6 /** 7 This program reads numbers from a file, calculates the 8 mean (average)...
The language is Java. Using a singly-linked list, implement the four queue methods enqueue(), dequeue(), peek(),...
The language is Java. Using a singly-linked list, implement the four queue methods enqueue(), dequeue(), peek(), and isEmpty(). For this assignment, enqueue() will be implemented in an unusual manner. That is, in the version of enqueue() we will use, if the element being processed is already in the queue then the element will not be enqueued and the equivalent element already in the queue will be placed at the end of the queue. Additionally, you must implement a circular queue....
Complete a Java program named ARMgr that maintains customer accounts receivable in a database. The code...
Complete a Java program named ARMgr that maintains customer accounts receivable in a database. The code to initialize the CustomerAccountsDB database table and add a set of customer accounts is provided. Finish the code in these 3 methods in CustomerAccountDB.java to update or query the database: -purchase(double amountOfPurchase) -payment(double amountOfPayment) -getCustomerName() Hint: For getCustomerName(), look at the getAccountBalance() method to see an example of querying data from the database. For the purchase() and payment() methods, look at the addCustomerAccount() method...
I am a beginner when it comes to java codeing. Is there anyway this code can...
I am a beginner when it comes to java codeing. Is there anyway this code can be simplified for someone who isn't as advanced in coding? public class Stock { //fields private String name; private String symbol; private double price; //3 args constructor public Stock(String name, String symbol, double price) { this.name = name; this.symbol = symbol; setPrice(price); } //all getters and setters /** * * @return stock name */ public String getName() { return name; } /** * set...
Code in JAVA The requirements are as follows: The input will be in a text file...
Code in JAVA The requirements are as follows: The input will be in a text file whose name is given by arg[0] of main(). It will contain a fully-parenthesized infix expression containing only: "(", ")", "+", "-" and integers. Need help on the main and fixing the Queue. //Input: ( ( 1 + 2 ) - ( ( 3 - 4 ) + ( 7 - 2 ) ) ) ( ( 1 + 2 ) - ( 3 -...
Java: ModifyStudentList.javato use anArrayListinstead of an array In StudentList.java, create two new public methods: The addStudent...
Java: ModifyStudentList.javato use anArrayListinstead of an array In StudentList.java, create two new public methods: The addStudent method should have one parameter of type Student and should add the given Student to the StudentList. The removeStudent method should have one parameter of type String. The String is the email of the student to be removed from the StudentList. In Assign5Test.java do the following: Create a new StudentList containing 3 students. Print the info of all the Students in the StudentList using...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT