Can you please Write a simple Convertor class with one method that takes in a le
ID: 3798435 • Letter: C
Question
Can you please Write a simple Convertor class with one method that takes in a length and width page parameters in inches and returns length and width in millimeters? please Print the new dimensions. Use a Static Final constant MILLIMETERSININCHES. Create a ConvertorTest class to test the Convertor class.
*** Can you please write a program that displays the dimensions of a letter size ( 8.5 * 11 inches) sheet of paper in millimeters . There are 25.4 millimeters per inch. Use constants and components in your program
** please write in .java file
Explanation / Answer
Converter.java
public class Converter {
//Declaring constant
static final double MILLIMETERSININCHES=25.4;
//Declaring instance variables
double length;
double width;
//Zero argumented constructor
public Converter() {
super();
}
//Getters and setters
public double getLength() {
return length;
}
public void setLength(double length) {
this.length = length;
}
public double getWidth() {
return width;
}
public void setWidth(double width) {
this.width = width;
}
//Method which will convert inches to millimeters
Converter convertInchesToMM(double length,double width)
{
Converter c=new Converter();
double lenInMM=MILLIMETERSININCHES*length;
double widInMM=MILLIMETERSININCHES*width;
c.setLength(lenInMM);
c.setWidth(widInMM);
return c;
}
}
____________________
ConvertorTest.java
import java.text.DecimalFormat;
import java.util.Scanner;
public class ConvertorTest {
public static void main(String[] args) {
double lenInch,widInch;
//DecimalFormat class is used to format the output
DecimalFormat df=new DecimalFormat("#.##");
//Scanner object is used to get the inputs entered by the user
Scanner sc=new Scanner(System.in);
System.out.print("Enter length (in inches) :");
lenInch=sc.nextDouble();
System.out.print("Enter width (in inches) :");
widInch=sc.nextDouble();
//Creating the converter class object
Converter conv=new Converter();
//Calling the method which will convert inches to millimeters
Converter conv1=conv.convertInchesToMM(lenInch, widInch);
//Displaying the dimensions in millimeters
System.out.println("The Dimensions of a letter whose length is :"+df.format(conv1.getLength()));
System.out.println("The Dimensions of a letter whose width is :"+df.format(conv1.getWidth()));
}
}
_______________________
output:
Enter length (in inches) :8.5
Enter width (in inches) :11
The Dimensions of a letter whose length is :215.9
The Dimensions of a letter whose width is :279.4
_________Thank You