Primitive Data Types

Example fallback content: This browser does not support PDFs. Please download the PDF to view it: Download PDF.

/**
* ---------------------------------------------------------------------------
* File name: DataPrimitiveExercises.java
* Project name: Winter Study Guide
* ---------------------------------------------------------------------------
* Author’s name and email: Michael Schneider, schneidm@etsu.edu
* Course-Section: All
* Creation Date: 12/12/15
* Last modified: Schneider 12/13/15 schneidm@etsu.edu
* ---------------------------------------------------------------------------
*/


/**
* Class Name: DataPrimitiveExercises <br>
* Class Purpose: To give examples on declaring and initializing
*				 variables using the primitive data types <br>
*
* <hr>
* Date created: 12/12/15 <br>
* Last modified: Schneider 12/13/15 schneidm@etsu.edu
* @author Michael Schneider
*/
public class DataPrimitiveExercises{

	public static void main(String[] args){
	
		//Declare a char and initialize it with a value of m

		char letter = 'm';
		
		//Declare a boolean and initialize it with a value of false

		boolean valid = false;
		
		//Declare a float and initialize it with a value of 72.3

		float small = 72.3f;
		
		//Declare an int and initialize it with a value of -32

		int wholeNumber = -32;
		
		
		//Interpret what data type is needed for each question.

		
		//1. Create a variable that can keep track of sales tax of 9.5%

		
	
	
		//2. Create a variable that can keep track of the current day of the month

		
		
	
		//3. Create a variable that can keep track of a person's middle initial

		
	}

}
/**
* ---------------------------------------------------------------------------
* File name: DataPrimitiveExercisesAnswers.java
* Project name: Winter Study Guide
* ---------------------------------------------------------------------------
* Author’s name and email: Michael Schneider, schneidm@etsu.edu
* Course-Section: All
* Creation Date: 12/12/15
* Last modified: Schneider 12/13/15 schneidm@etsu.edu
* ---------------------------------------------------------------------------
*/


/**
* Class Name: DataPrimitiveExercisesAnswers <br>
* Class Purpose: To give answers to the primitive data type exercises <br>
*
* <hr>
* Date created: 12/12/15 <br>
* Last modified: Schneider 12/13/15 schneidm@etsu.edu
* @author Michael Schneider
*/
public class DataPrimitiveExercisesAnswers{

	public static void main(String[] args){
	
		//Declare a char and initialize it with a value of m

		char letter = 'm';
		
		//Declare a boolean and initialize it with a value of false

		boolean valid = false;
		
		//Declare a float and initialize it with a value of 72.3

		float small = 72.3f;
		
		//Declare an int and initialize it with a value of -32

		int wholeNumber = -32;
		
		
		//Interpret what data type is needed for each question.

		
		//1. Create a variable that can keep track of sales tax of 9.5%

		double taxRate = 0.095;
			//or

		float tax = 0.095f;
		
		/*************************************************************
		*	Depending on the size of the tax rate, we can either use
		*	a float or a double.  In general, we would use a double
		*	since it is more versatile with it's greater precision.
		***************************************************************/
	
		//2. Create a variable that can keep track of the current day of the month

		
		int day = 25;
		
		/*************************************************************
		*	A day of the month must be a whole number, so must use one of
		*	the integer data types.  int is the most widely used of the
		*	integer data types.  But since a maximum number of days in a month
		*	is 31, we could have also used byte, short, or even long.
		**************************************************************/
	
		//3. Create a variable that can keep track of a person's middle initial

		
		char middleInitial = 'K';
		
		/*************************************************************
		*	A middle initial is a single letter and the only primitive
		*	data type that can hold a single letter would be the char
		*	type.  
		**************************************************************/
	
	}

}