Question: Modify the Lab 7 program, creating a class with the methods for functional decomposition of the code. remove the two methods and put them in

Modify the Lab 7 program, creating a class with the methods for functional decomposition of the code. remove the two methods and put them in a different class and connect the two classes so it will work perfectly.And give the user the option in which method to use

import java.io.File; import java.io.FileNotFoundException; import java.io.PrintWriter; import java.util.Scanner;

public class Lab40 {

public static void main(String[] args) throws FileNotFoundException { //assign the path of output file in string s String s= "J:\\jgrasp\ esult1.txt"; //declare all local variables double Fahrenheit, Celsius, Kelvin ; String inpVal; int temp,count=0; //scanner object to read the user choice of conversion of each temperature values Scanner Keyboard = new Scanner(System.in); PrintWriter outputFile = new PrintWriter(s); File file = new File ("C:\\Users\\erorr\\Desktop\\Data.txt"); Scanner inputFile= new Scanner(file); //reading each line of input file while (inputFile.hasNext()) { temp= Integer.parseInt(inputFile.nextLine()); System.out.println(); System.out.println("the textfile value you are converting: " + temp); count++; System.out.println(" Choose an option for temperature value "+count); System.out.println("FTC - Fahrenheit to Celsius"); System.out.println("CTF - Celsius to Fahrenheit"); System.out.println("FTK - Fahrenheit to Kelvin"); System.out.println("KTF - Kelvin to Fahrenheit"); System.out.println("CTK - Celsius to Kelvin"); System.out.println("KTC - Kelvin to Celsius");

System.out.println(" Enter Choice: ");

String Type= Keyboard.next(); if (Type.equalsIgnoreCase("FTC")) { Fahrenheit = temp; Celsius= ((5*(Fahrenheit-32))/9) ;

System.out.println("The value of the temperature in Celsius = " + Celsius); outputFile.println("Fahrenheit = " + Fahrenheit + "===> Celsius = " + Celsius); } else if (Type.equalsIgnoreCase("CTF")) {

Celsius = temp; Fahrenheit = ((9*Celsius)/5)+32;

System.out.println("The value of the temperature in Fahrenheit = " + Fahrenheit);

outputFile.println("Celsius = " + Celsius + "===> Fahrenheit = " + Fahrenheit); } else if(Type.equalsIgnoreCase("CTK")) { Celsius = temp; Kelvin = Celsius +273 ;

System.out.println("The value of the temperature in Kelvin = " + Kelvin);

outputFile.println("Celsius = " + Celsius + "===> Kelvin = " + Kelvin); } else if(Type.equalsIgnoreCase("KTC")) { System.out.println("Enter the value of temperature in Kelvin degrees: ");

Kelvin = temp; Celsius = Kelvin - 273 ;

System.out.println("The value of the temperature in Celsius = " + Celsius);

outputFile.println("Kelvin = " + Kelvin + "===> Celsius = " + Celsius); } else if(Type.equalsIgnoreCase("FTK")) { Fahrenheit = temp; Kelvin =(5.0/9)*(Fahrenheit - 32) + 273;;

System.out.println("The value of the temperature in Kelvin = " + Kelvin);

outputFile.println("Fahrenheit = " + Fahrenheit + "===> Kelvin = " + Kelvin); } else if(Type.equalsIgnoreCase("KTF")) { Kelvin = temp; Fahrenheit =(9.0/5)*( Kelvin - 273) + 32;

System.out.println("The value of the temperature in Fahrenheit = " + Fahrenheit);

outputFile.println("Kelvin = " + Kelvin + "===> Fahrenheit = " + Fahrenheit); }

}

outputFile.close();

System.out.println("Finish! The output file location is: " + s);

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!