Java Student Project         

SquareFeet
Ability Level: Beginner  
Estimated Time: 40 minutes
Objectives:
  • To learn how to use variables and constants.
  • To learn about the int, floating-point, and char data types.
  • To learn how to write arithmetic statements.
  • To learn about the boolean data type. 
  • To learn about numeric type conversions.
Materials & Resources:
  • Java Software
  • Textbook
Overview: Write a program that declares variables to represent the 15 foot length and 25 foot width of a room in feet and the price of carpeting ($11.50) per square foot in dollars and cents. Compute and display the floor space of the room in square feet (area = length * width). Compute the cost of carpeting the room. Display explanatory text with the values.
Instructions:
  1. Create an introductory function to explain your program to the user.

  2. Write a Java program to compute the square feet of a room following these steps:
    1. Assign the value for the length and the width of a room in feet.
    2. Assign the value for the price of carpeting per square foot in dollars and cents.
    3. Compute the square feet of the room.
    4. Compute the cost of carpeting the room.
    5.Display the square feet of the room and the cost of carpeting the room.
    6. Use the following template:
    public class squareFeet
     { 
       public static void main(String args[]) 
        { 
           System.out.println("Program Square Feet");
           .....[code here]
         }
       }
Hints: Some important points to keep in mind in doing this project:
  1. Data is constant when it cannot be changed after a program is compiled.
  2. Data is variable when it might be changed.
  3. Variables are named memory locations that your program can use to store values.
  4. You can name a variable using any legal identifier beginning with a letter which is not a keyword.
  5. All variables must be declared to be used in a program.
  6. A variable declaration requires a type and a name. It can also include an assigned value. Example: int counter = 1;
  7. Java provides for eight primitive types of data: boolean, byte, char, double, float, int, long, and short.
  8. A variable declaration includes: a data type that identifies the type of data that the variable will store; an identifier that is the variable's name; an optional assigned value, when you want a variable to contain an initial value; and an ending semicolon.
  9. The equal sign (=) is the assignment operator. Any value to the right of an equal sign is assigned to the variable on the left of the equal sign.
  10. You can declare multiple variables of the same type in separate statements or in a single statement, separated by commas. Example: double number1, number2;
  11. Variables of type int are used to hold integers, or whole numbers. An integer can hold any whole number value from -2,147,483,648 to 2,147,483,647. The types byte, short, and long are all variables of the integer type.
  12. There are five standard arithmetic operators for integers: + - * / and %.
  13. Operator precedence is the order in which parts of a mathematical expression are evaluated. Multiplication, division, and modulus always take place prior to addition or subtraction in an expression.
  14. A boolean type variable can hold true or false.
  15. There are six comparison operators:  
     <   ==   >= <= !=
  16. A floating-point number contains decimal positions. The Java programming language supports two floating-point data types: float and double.
  17. When you perform mathematical operations on unlike types, the Java programming language implicitly converts the variables to a unifying type. 
  18. You can explicitly override the unifying type imposed by the Java programming language by performing a type cast. Example (int) number1;
  19. The char data type is used to hold any single character. Example: char ch = 'a';
  20. Constant character values are keyed in single quotation marks. 
  21. String constants that store more than one character are keyed between double quotation marks. Example: String word = "apple";
  22. The characters used in Java programming are represented in the 16-bit Unicode scheme.
  23. You can store some characters using an escape sequence, which always begins with a backslash. Examples: 
    \b  // backspace
    \t  // tab
    \n // new line,
     \f  // form feed, 
    \r // carriage return,
     \" // Double quotation mark
    \'  // Single quotation mark
    \\  // Backslash
  24. In case you still need help, look in this lecture: Starting Java


PROJECT EXTRA
  • Calculate the price of carpeting per square yard in dollars and cents. 
    (Hint: There are nine square feet in one square yard.)