Monday, January 23, 2017

Programming By Doing Lesson 10

Programming By Doing Lesson 10 - My Code

public class MoreVariablesAndPrinting
{
public static void main( String[] args )
{
String name, eyes, teeth, hair;
int age, height, weight;

name = "Zed A. Shaw";
age = 35;  //not a lie
height = 74;  //inches
weight = 180; //lbs
eyes = "Blue";
teeth = "White";
hair = "Brown";

double inToCm = height * 2.54;
double poundsToKilos = weight * 0.453592;

System.out.println( "Let's talk about " + name + "." );
System.out.println( "He's " + height + " inches (or " + inToCm + " cm) tall." );
System.out.println( "He's " + weight + " pounds (or " + poundsToKilos + " kg) heavy." );
System.out.println( "Actually, that's not too heavy." );
System.out.println( "He's got " + eyes + " eyes and " + hair + " hair." );
System.out.println( "His teeth are usually " + teeth + " depending on the coffee." );

//This line is tricky; try to get it exactly right.
System.out.println( "If I add " + age + ", " + height + ", and " + weight + " I get " + (age + height + weight) + "." );

}
}

My output from command prompt is slightly different probably because I used a double variable. 

c:\Users\jenni\OneDrive\Documents\CompSci>java MoreVariablesAndPrinting
Let's talk about Zed A. Shaw.
He's 74 inches (or 187.96 cm) tall.
He's 180 pounds (or 81.64656 kg) heavy.
Actually, that's not too heavy.
He's got Blue eyes and Brown hair.
His teeth are usually White depending on the coffee.
If I add 35, 74, and 180 I get 289.

No comments:

Post a Comment