Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

Project 02 Materials / C07_YourID_Exercise07

.docx
Скачиваний:
22
Добавлен:
14.10.2016
Размер:
1.26 Mб
Скачать

exercise 07: limitations on integers

Application Development

Name: <your name goes here>

Purpose: The purpose of this assignment is to give you more practice creating from scratch a very simple program in Eclipse and to explore the limits of the various types of integer values in Java.

Perform each of the following activities. If you have questions, issues, or doubts, please ask for help and do not just guess!

  1. Be sure the file name of this document starts with your StudentID which is followed by a single blank and that is followed by “Exercise07.doc”.

  2. Replaced the “<your name goes here>” (including the “<” and the “>”) with your name.

  3. Start Eclipse.

  4. Create a new project named “YourStudentID Exercise07”. Do this by using the “File” menu and select the “New” / “Java Project” option, fill in the “Project name:” textbox with the name using your StudentID followed by a space and then “Exercise07”, and then click the “Finish” button.

  5. In the Package Explorer window, click on the “+” or the triangle to the immediate left of the icon to the left of the Exercise07 project you just created so you can see the “src” folder. When you can see the “src” folder, click on its icon.

  6. Create a new package named “exercise07” in the “src” folder. Do this by using the “File” menu and select the “New” / “Package” option, fill in the “Name:” textbox with “exercise07”, and then click on the “Finish” button.

  7. Create a new mainline class named “Exercise07” in the “exercise07” package. Do this by using the “File” menu and select the “New” / “Class” option, fill in the “Name:” textbox with “Exercise07”, and then click on the “Finish” button.

  8. You should now see the following in an edit window in the middle of the Eclipse window:

package exercise07;

public class Exercise07 {

}

  1. In the line immediately below the “package” line, insert a block comment with your name as the program author and the name of this program. (Recall, block comments start with a “/*” and end with a “*/”.

  2. Between the “{“ and “}” braces following the public class line, insert the following code:

public static void main(String[] args){

System.out.println("Exercise07 written by: <your name>");

}

  1. After the call to the println method and before the closing brace (“}”), insert the following sequence of statements:

  • A statement to declare an integer value of type “byte” and initialize it to the largest possible value that you believe can be stored in a byte typed variable. (You can find that value on the bottom of page 49 of the textbook.)

  • A statement to display the current value of that variable to the display.

  • A statement to increment the value of the variable.

  • A statement to display the new current value of the variable to the display.

  • Click on the save icon ( ) to save the changes you have made.

  • Click on the run icon ( ) and specify in the space below what the output was in the Console window:

    1. We see the output we expect for the first value, but we do not see what non-computer people would expect for the second line. Why do we see this value?

    1. Modify the program, so the type of the variable is “short” as opposed to “byte” and make no other changes. Run the program and show in the space below the output in the Console window:

    1. Why is this output different from the output shown for step 13?

    1. Modify the program so the initial value of the short variable is now the largest possible short value (again, page 49 in the textbook can help you) and specify in the space below what the output was in the Console window:

    1. From what you see here, what would be displayed if we changed the “short” type to “int” and changed the constant to the largest possible constant for an int?

    1. This is the end of the exercise. Save your work and upload this exercise to the LMS following the instructions given in Exercises 1 and 2. (Be sure the name of the file is correct and specify your StudentID and “Exercise07” in the “name” field when you submit this to the LMS.)

    ©iCarnegie - Distribution or copying without permission is prohibited.

  • Соседние файлы в папке Project 02 Materials