Code
/// Name: Afaf Nabeeha
/// Period: 7
/// Program Name: Variables and Names
/// File Name: Variables.java
/// Date Finished: 9/18/2015 public class Numbers
public class Variables
{
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;
//Everytime in the println there is the word cars not in quotations the program will substitute it with 100
cars = 100;
//The space_in_a_car is used to calculate later variable assignments.
space_in_a_car = 4;
//The word drivers indicates the number of drivers available; similar to the assignment "cars"
drivers = 30;
//Same as "cars" and "drivers"
passengers = 90;
//This uses previously assigned variables to calculate total # of empty cars
cars_not_driven = cars - drivers;
//This indicates that the number of cars driven must also be = to # of drivers
cars_driven = drivers;
//This uses previously assigned variables to calculate total # of passengers to carpool
carpool_capacity = cars_driven * space_in_a_car;
//This uses previously assigned variables to average the # of 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