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: <span class=\"metric\">"
+ DF1.format( diagonalCm )
+ " cm</span>, <span class=\"imperial\">"
+ DF2.format( diagonalIn )
+ " inches</span>,\n"
+ "width × height <span class=\"times\">"
+ widthPx
+ " × "
+ heightPx
+ "</span> pixels,\n<span class=\"metric\">"
+ DF1.format( widthCm )
+ " × "
+ DF1.format( heightCm )
+ " cm</span>,\n"
+ "<span class=\"imperial\">("
+ DF2.format( widthIn )
+ " × "
+ DF2.format( heightIn )
+ " inches)</span>"
);
}
}