Question: Using your previous lab assignment, copy the contents of the Java file AverageHeight.java, create a new File called AverageHeightFile.java , and modify it so your
Using your previous lab assignment, copy the contents of the Java file AverageHeight.java, create a new File called AverageHeightFile.java, and modify it so your program:
- Reads you name (from one line) - Your height in feet (in another line) - Your height in inches (in another line) - And the height of you partner in inches (in another line) from a text file called height.txt
Then, write the final message you had from your original program. (The average height of both of you is: Z) in the same file your name was read.
Previous java code :
import java.util.Scanner; //declare a variable
public class AverageHeight { public static void main(String[] args) { Scanner scan = new Scanner(System.in); // input from the system int feet1, feet2, inches1, inches2;
System.out.print("Enter your name: "); String name1 = scan.next();
System.out.print("Enter height in feet of "+ name1 +": "); feet1 = scan.nextInt();
System.out.print("Enter remaining inches of "+ name1 +": "); inches1 = scan.nextInt();
System.out.println("Hi "+ name1 +", you are in total "+(feet1*12+inches1)+" inches tall.");
System.out.print("Enter neighbors name: "); String name2 = scan.next();
//System.out.print("Enter height in feets of "+name2+": "); //feet2 = scan.nextInt();
System.out.print("Enter height in inches of "+name2+": "); inches2 = scan.nextInt();
System.out.println("Hi "+name1+", you are in total "+(feet1*12+inches1)+" inches tall.");
int totalInches = 12*(feet1)+inches1+inches2;
System.out.printf("The average height of both you and your neighbor is %.2f. ",(totalInches/12.0)); } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
