Assignemnt #12 and Variables And Names
Code
///Name: Dakota Donahue
///Period: 5
///Project Name: Variables And Names
///File Name: VariablesAndNames
///Date: 9/9/2015
//1. Writing 4.0 rather than 4 allows the number of people that can be transported to a place of 2 significant figures rather than 1.
//2.A floating point number has no fixed number of digits before or after the decimal point.
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;
//There are a total of 100 cars available
cars = 100;
//4.0 people can fit into a single car
space_in_a_car = 4.0;
//There are 30 drivers available
drivers = 30;
//There are 90 passengers
passengers = 90;
//Calculates difference between variable: cars, and variable: drivers
cars_not_driven = cars - drivers;
//Makes number of cars driver equal to number of drivers
cars_driven = drivers;
//Calculates product of number of cars driven and how many people can fit into a car
carpool_capacity = cars_driven * space_in_a_car;
//Divides total passengers by cars driver
average_passengers_per_car = passengers / cars_driven;
//Displays total number of cars available
System.out.println( "There are " + cars + " cars available." );
//Displays total number of drivers available
System.out.println( "There are only " + drivers + " drivers available." );
//Displays total number of cars which will not be used
System.out.println( "There will be " + cars_not_driven + " empty cars today." );
//Displays total number of passengers that can be held in all the cars being driven
System.out.println( "We can transport " + carpool_capacity + " people today." );
//Displays total number of passengers that need to be transported
System.out.println( "We have " + passengers + " to carpool today." );
//Displays total number of passengers divided by the number of cars driven
System.out.println( "We need to put about " + average_passengers_per_car + " in each car." );
}
}
Picture of the output