Assignment #12 and VariablesAndNames
Code
/// Name: Mahima Choudhary
/// Period: 6
/// Program Name: VariablesAndNames.java
/// File Name: VariablesAndNames
/// Date Finished: 9/17/2015
//---------------------------------------------------------------------------------------
// I used 4.0 for space_in_a_car, but is that necessary? What happens if it's just 4?
// It is not necessary to use decimal point because variable type is primitive type of double
// that support a floating point
//---------------------------------------------------------------------------------------
public class VariablesAndNames
{
public static void main( String[] args )
{
// defining variables
int cars, drivers, passengers, cars_not_driven, cars_driven;
double space_in_a_car, carpool_capacity, average_passengers_per_car;
// assigning values to variables
cars = 100;
space_in_a_car = 4.0;
drivers = 30;
passengers = 90;
cars_not_driven = cars - drivers;
cars_driven = drivers;
carpool_capacity = cars_driven * space_in_a_car;
average_passengers_per_car = passengers / cars_driven;
// Concatenating value of variable cars with String
System.out.println( "There are " + cars + " cars available." );
// Concatenating value of variable drivers with String
System.out.println( "There are only " + drivers + " drivers available." );
// Concatenating value of variable car_not_driven with String
System.out.println( "There will be " + cars_not_driven + " empty cars today." );
// Concatenating value of variable carpool_capacity with String
//4 is changed to a non-floating point. to show it makes no difference
System.out.println( "We can transport " + carpool_capacity + " people today." );
// Concatenating value of variable passengers with String
System.out.println( "We have " + passengers + " to carpool today." );
// Concatenating value of variable average_passengers_per_car with String
System.out.println( "We need to put about " + average_passengers_per_car + " in each car." );
}
}
Picture of the output