Write a program that sums the area of all lands and displays the total volume in
ID: 3595965 • Letter: W
Question
Write a program that sums the area of all lands and displays the total volume in acres. There are 0.404687261 hectares in an acre and 4 roods in an acre. Display the acreage with only three decimal digits of accuracy.
Java language
land.txt:
8:50 AM @* 100% @ D. blackboard.ncat.edu COMP163 Liquid Volume An apothecary has a large collection of vile liquids in partially filled containers The EPA wants to know how much there is. You are to write a peogram that calculates how much medication they have in all containers combined The data file 1iquids.txt contains a list of mumbers representing the volume of liquid in the contaimors. Each line of the ile coetains a number with a decimal poim followed by the unit ef measurement. The units can be cup (represented by "c" quart (represented as " or liter (represented by "LT The units might be in a mixture of upper and lower case letlcs A. 185 points] Write a program that sumes the volume of all containers and displays the sotal velume in Iners. There ane 0.946352946 liters in a quart and 4 cups in a quat B. [15 points Display the sum of the liquid volame with only two decimal digits of accuracy Sample outpeut The total vol une is 102.01631521805561 liters The total volune is 102.02 liters Upload your complesed program so Blackboard before the end of your lab period moExplanation / Answer
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class CalculateLandArea_File {
public static void main(String[] args) {
File file = new File("land.txt");
double ac=0,ha=0, rood=0, t;
String s;
try {
Scanner sc = new Scanner(file);
while (sc.hasNextLine()) {
t= sc.nextDouble();
s=sc.next();
if(s.equalsIgnoreCase("ac"))
ac+=t;
else if(s.equalsIgnoreCase("ha"))
ha+=t;
else if(s.equalsIgnoreCase("rood"))
rood+=t;
}
sc.close();
//System.out.println(ac+" "+ha+" "+rood);
ac+=(rood/4);
ac+= ha/0.404687261;
System.out.printf("Total area is %.3f",ac);
}
catch (FileNotFoundException e) {
e.printStackTrace();
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.