Advertisement
Guest User

Lab#1

a guest
Sep 16th, 2014
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.22 KB | None | 0 0
  1. Lab #1: Methods and Arrays
  2. Laboratory Exercises for Monday, September 15
  3. (Source: Bloss, A and Ingram, N.J., Lab Manual for Java Software Solutions, Pearson, 2009)
  4. The following laboratory activities should be completed by the end of today’s laboratory session. Upon completion of each laboratory exercise, you are expected to have the lab instructor or one of the lab assistants check the correctness of the program by demonstrating the execution of the program. Make sure you have a printout of the source code ready before demonstrating your program. At that time, the lab instructor (or student lab assistant) will assign a grade for the completed program. If you have not completed both exercises by the end of the laboratory session, you still have to make sure you submit a printout of any partially working program to get partial credit for your efforts. Failure to do so will result in a grade of ZERO for the lab exercise.
  5.  
  6. Exercise #2: A Shopping Cart
  7.  
  8. In this exercise you will complete a class that implements a shopping cart as an array of items. The file Item.java contains the definition of a class named Item that models an item one would purchase. An item has a name, price, and quantity (the quantity purchased). The file ShoppingCart.java (found in DocSharing) implements the shopping cart as an array of Item objects.
  9.  
  10. Complete the ShoppingCart class by doing the following:
  11.  
  12. Declare an instance variable cart to be an array of Items and instantiate cart in the constructor to be an array holding capacity Items.
  13.  
  14. Fill in the code for the increaseSize method. Your code should increase the size of the cart by 3 elements.
  15.  
  16. Fill in the code for the addToCart method. This method should add the item to the cart and update thetotalPrice instance variable (note this variable takes into account the quantity).
  17.  
  18. Compile your class.
  19.  
  20. Write a program that simulates shopping. The program should have a loop that continues as long as the user wants to shop. Each time through the loop read in the name, price, and quantity of the item the user wants to add to the cart. After adding an item to the cart, the cart contents should be printed. After the loop print a "Please pay ..." message with the total price of the items in the cart.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement