Exercise 1: Using Primitive Type Variables in a Program
The objective of this exercise is to create a class containing several variable declarations.
Task 1 – Creating a Class With Variables
In this task, you compile and execute a Customer class with several variables. Follow
these steps to create your Customer class:
1. Go to the data_types directory.
2. Open a text editor, and create a file in this directory called Customer.java.
3. In the Customer.java file, write a class called Customer that creates and
assigns default values to the variables for the following information (use constants if
appropriate):
· A customer ID
· The customer status of ‘N’ for new or ‘O’ for old
· Total purchases for the year
4. Create a method within the class called displayCustomerInfo that uses the
System.out.println method to print each value to the screen with a
corresponding label (such as "Purchases are: ").
5. Compile and run the program using the provided CustomerTest
class file. Check the output to be sure that it contains the values you assigned.
Note – All of the examples and exercises in this course require a test class.
In most situations, the test class is provided. However, in some situations,
you will create the class.
No comments:
Post a Comment