Could someone help me with my exercises, because I suck at java programming and I need to get these done before my course ends.
I beg of you to help me..
Here goes nothing,
You can find the files mentioned in the exercises from here:
Index of /maximillian
First exercise:
In this task, you write a test class that adds multiple Shirt objects to an
Order object and displays a total current amount, in dollars, for the order.
Follow these steps to write your test class:
1. Go to the working directory and open an editor.
2. Open the Shirt.java file and examine the member variables and
the method in it.
3. Open the Order.java file and examine its member variables and
method in it.
4. Write a new class called OrderTest containing a main method.
5. In the main method:
a. Create and initialize an object of type Order and an object of
type Shirt. The Order class (Order.java) and the Shirt class
(Shirt.java) are provided in the exercise1 directory.
b. Declare a variable of type double, name it as totalCost and
initialize it by 0.0.
c. Assign the price for the Shirt object to 14.00.
d. Invoke the addShirt method of the Order class using the
Order instance to add the shirt instance to the order. Store the
return value of the addShirt method in the totalCost variable.
The documentation for the addShirt method is as follows:
public double addShirt (Shirt s)
Adds a shirt to a list of shirts in an order
Parameters:
s – An object reference to a Shirt object
Returns:
A total current amount for the order
e. Display the return order amount. For example:
Total amount for the order is: 14.00
6. Compile and execute your program. Verify if the total order value is
displayed.
7. In the main method of OrderTest class, create additional Shirt
objects, assign values to the price variable of the new Shirt objects,
and add the Shirt objects to your order by invoking the addShirt
method.
8. Save and compile the OrderTest.java file.
9. Execute OrderTest class and verify that the total order value is
displayed correctly.
Second exercise:
In this task, you write a Customer class with an overloaded method called
setCustomerInfo.
Follow these steps to write your class:
1. Go to the working directory and open an editor.
2. Create a class called Customer and save the file as Customer.java
in the working directory.
3. Within the Customer class, add two overloaded methods called
setCustomerInfo.
Depending on how the setCustomerInfo method is called, it does
one of the following:
● Sets the ID, name, address, and phone number for a Customer
object. (This is the minimum information needed for a new
Customer.)
● Sets the ID, name, address, phone number, and email address
for a Customer object.
4. Create a display method to display the values of all the member
variables of the Customer class.
5. Save and close the Customer.java file.
6. Open the file called CustomerTest.java to test the overloaded
methods of the Customer class.
Developing and Using Methods 1-7
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision A
7. In the main method of CustomerTest class write code to perform the
following tasks:
a. Create two object references to different Customer objects.
b. Use each variation of the setCustomerInfo method to provide
information for each Customer object.
c. Display the contents of each Customer object.
8. Save and compile the file CustomerTest.java file.
9. Execute the CustomerTest class and view the output of the class.
Third Exercise:
In this task, you create a class containing private attributes and try to
access them in another class.
Follow these steps to write your test class:
1. Go to the working directory and open an editor.
2. Create a class called DateOne that contains three member variables
of type int named: day, month, and year. Give public access to all
the member variables. Save the class with the name DateOne.java.
3. Open the DateOneTest.java file provided in the working directory
and write the following in its main method:
a. Create and initialize an object of type DateOne.
b. Assign different numeric values to the member variables of the
DateOne instance.
c. Display the value of the member variables of the DateOne
instance.
4. Save and compile DateOneTest.java file.
5. Execute the DateOneTest class file and examine the output.
6. Create a new class called DateTwo similar to DateOne with three
member variables and save it as DateTwo.java.
7. Modify the access specifier of the three member variables of DateTwo
to private.
8. Open the DateTwoTest.java file provided in the working directory
and perform the same steps as in Step 3. However, in this case create
an instance of DateTwo class instead of DateOne class. The other
lines of code will remain the same.
9. Save and compile DateTwoTest.java.
10. Examine the compilation errors and identify the reason of the
compilation errors.
Fourth exercise:
In this task, you create a class with private attributes and enable them to
be manipulated from another class.
Complete the following steps:
1. Create a class called DateThree and save it with DateThree.java
file name.
2. DateThree class has the same three private member variables as
DateTwo class.
3. Add the following methods in the DateThree class:
a. get and set methods for all three member variables. For
example:
public void setDay(int d) { day = d; } public int getDay() { return day; }