Assignment #12 and Variables and Names
Code
/// Name: Ali Kurland
/// Period: 6
/// Program Name: Variables and Names
/// File Name: VariablesandNames.java
/// Date Finished: 9/11/2015
//In this case, it is not necessary to use 4.0 for space_in_a_car (because it is a double variable and not an int variable). Using just 4 yields the same answer.
//A floating-point number is a number with a decimal point and any number of digits before and after it.
public class VariablesandNames
{
public static void main( String[] args )
{
//This line sets up the variables that will be used in the program.
int cars, drivers, passengers, cars_not_driven, cars_driven;
double space_in_a_car, carpool_capacity, average_passengers_per_car;
//The line below is a variable assignment that assigns the value 100 to the variable 'cars'.
cars = 100;
//This line assigns the value 4 to the variable 'space_in_a_car'.
space_in_a_car = 4;
//This line assigns the value 30 to the variable 'drivers'.
drivers = 30;
//This line assigns the value 90 to the variable 'passengers'.
passengers = 90;
//This line assigns the operation cars - drivers to the variable 'cars_not_driven'.
cars_not_driven = cars - drivers;
//This line assigns the variable 'drivers' to the variable 'cars_driven'.
cars_driven = drivers;
//This line assigns the operation cars_driven * space_in_a_car to the variable 'carpool_capacity'.
carpool_capacity = cars_driven * space_in_a_car;
//This line assigns the operation 'passengers / cars_driven to the variable 'average_passengers_per_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." );
}
}
Picture of the output