/*
* [CalcSize.java]
*
* Summary: Calculate dimensions of a screen.
*
* Copyright: (c) 2009-2017 Roedy Green, Canadian Mind Products, http://mindprod.com
*
* Licence: This software may be copied and used freely for any purpose but military.
* http://mindprod.com/contact/nonmil.html
*
* Requires: JDK 1.8+
*
* Created with: JetBrains IntelliJ IDEA IDE http://www.jetbrains.com/idea/
*
* Version History:
* 1.0 2012-12-15
*/
package com.mindprod.example;
import java.text.DecimalFormat;
import static java.lang.System.*;
/**
* Calculate dimensions of a screen.
*
* @author Roedy Green, Canadian Mind Products
* @version 1.0 2012-12-15
* @since 2012-12-15
*/
public final class CalcSize
{
private static final DecimalFormat DF1 = new DecimalFormat( "###,##0.0" );
private static final DecimalFormat DF2 = new DecimalFormat( "###,##0.00" );
/**
* Calculate dimensions of a screen.
*
* @param args diagonal in inches, width is pixels, height in pixels.
*/
public static void main( String[] args )
{
final double diagonalIn = Double.parseDouble( args[ 0 ] );
final double diagonalCm = diagonalIn * 2.54;
final int widthPx = Integer.parseInt( args[ 1 ] );
final int heightPx = Integer.parseInt( args[ 2 ] );
final double widthIn = Math.sqrt( ( diagonalIn * diagonalIn )
/ ( 1. + ( ( double ) heightPx * heightPx )
/ ( ( double ) widthPx * widthPx ) ) );
final double heightIn = Math.sqrt( ( diagonalIn * diagonalIn )
/ ( 1. + ( ( double ) widthPx * widthPx )
/ ( ( double ) heightPx * heightPx ) ) );
final double widthCm = widthIn * 2.54;
final double heightCm = heightIn * 2.54;
out.println( "diagonal: " + DF2.format( diagonalIn ) + " inches " + DF1.format( diagonalCm ) + " cm" );
out.println( "width x height "
+ widthPx + " x " + heightPx + " pixels "
+ DF2.format( widthIn ) + " x " + DF2.format( heightIn ) + " inches "
+ DF1.format( widthCm ) + " x " + DF1.format( heightCm ) + " cm" );
out.println( "\ndiagonal: "
+ DF1.format( diagonalCm )
+ " cm, "
+ DF2.format( diagonalIn )
+ " inches,\n"
+ "width × height "
+ widthPx
+ " × "
+ heightPx
+ " pixels,\n"
+ DF1.format( widthCm )
+ " × "
+ DF1.format( heightCm )
+ " cm,\n"
+ "("
+ DF2.format( widthIn )
+ " × "
+ DF2.format( heightIn )
+ " inches)"
);
}
}