Assignemnt #12 and Variables And Names

Code


///Name: Ben Borglin
///Period: 6
///Program Name: Variables and Names
///File Name: VariablesAndNames.java
///Date Finished: 9/10/2015
 public class VariablesAndNames
{
    public static void main( String[] args )
    {
        //tells java what variables are going to be used
        int cars, drivers, passengers, cars_not_driven, cars_driven;
        double space_in_a_car, carpool_capacity, average_passengers_per_car;
        
        //cars is equal to 100
        cars = 100;
        
        //space_in_a_car is a double or floating point and it is equal to 4.0
        space_in_a_car = 4.0;
        
        //drivers is equal to 30
        drivers = 30;
        
        //passengers is equal to 90
        passengers = 90;
        
        //car_not_driven is equal to the variable cars minus the variable drivers, so 100-30=70 car_not_driven
        cars_not_driven = cars - drivers;
        
        //cars_driven is equal to the variable drivers which is 30
        cars_driven = drivers;
        
        //carpool_capacity is equal to the variable cars_driven is replaced by the space_in_a_car
        carpool_capacity = cars_driven * space_in_a_car;
        
        //the variable average_passengers_per_car is equal to the variables passengers divided by the cars_driven
        average_passengers_per_car = passengers / cars_driven;
        //displays all "" but in +variable+ it displays what the variable amount is
        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) 4.0 was used because the space_in_a_car was defined as a double variable 
        //2) floating point is a number with a decimal and java interprets it as a double
    }
}   
    

Picture of the output

Assignment 12