In: Computer Science
Kindly upvote if
this helped
OUTPUT:
CODE for indentation:
CODE as plain text:
import java.util.Scanner;
public class ConvertToMetric {
double standard;
public double getStandard() {
return standard;
}
public ConvertToMetric(double standard) {
this.standard = standard;
}
public double getMeters() {
return this.standard * 0.3048; // 1 foot is 0.3048m
}
public double getCentiMeters() {
return this.standard * 30.48; // 1 foot is 30.48cm
}
}
class TestingMetric {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in); // creating object of scanner class to take the input from user from keyboard
System.out.println("Enter standard value (in feet)");
double input = sc.nextDouble();
sc.close(); // close the Scanner object. No longer we want to take input from user now
ConvertToMetric c = new ConvertToMetric(input);
double met = c.getMeters();
double cms = c.getCentiMeters();
System.out.println(input + " feet in meters is " + met + " and in centimeters is " + cms);
}
}