Assignemnt #12: Variabls and Names
Code
/// Name: Sean Harrison
/// Period: 7
/// Program name: VariablesAndNames
/// File Name: VariablesAndNames.java
/// Date Finished: 9/15/2015
public class VariablesAndNames
{
public static void main( String[] args )
{
int cars, drivers, passengers, cars_not_driven, cars_driven;
double space_in_a_car, carpool_capacity, average_passengers_per_car;
//this variable represents 100 cars to begin with
cars = 100;
//space in a car represents the number of people per ride.
space_in_a_car = 4.0;
//number of drivers they have
drivers = 30;
//number of passengers
passengers = 90;
//this calculation computes the remaining cars but subtracting drivers from cars
cars_not_driven = cars - drivers;
//this calculation accounts for the number of cars = drivers
cars_driven = drivers;
// this calculation allows the amount of passengers in total to be calculated
carpool_capacity = cars_driven * space_in_a_car;
// this stastic would be an average of passengers per each car
average_passengers_per_car = passengers / cars_driven;
System.out.println( "There are " + cars + " cars available." );
System.out.println( "There are only " + drivers + " drivers available.");
System.out.println( "There will be " + cars_not_driven + " empty cars today.");
System.out.println( "We can transport " + carpool_capacity + " people today.");
System.out.println( "We have " + passengers + " to carpool today." );
System.out.println( "We need to put about " + average_passengers_per_car + " in each car." );
// 1. If you only use a 4, in place of the 4.0 the java's 32-bit IEEE 754 floating point will round the number to a different placement of precision.
// 2. A floating point number is derived from the fact there is no fixed number of digits before and after the decimal point.
// 3. = is allowing the java to assign an value for that int
}
}
Picture of the output