(Solved) : Use Object Oriented Language Java C C Solve Following Problems 1 Write Pair Classes Square Q42729434 . . .

Use an object-oriented language (Java, C#, or C++) to solve thefollowing problems. 1. Write a pair of classes, Square1 andRectangle1. Define Square1 as a subclass of Rectangle1. In additionto setters and getters, provide such methods as computeArea andcomputePerimeter. Specify the preconditions, postconditions andclass invariants, if any, as comments (30%) 2. Write a pair ofclasses, Square2 and Rectangle2. Define Rectangle2 as a subclass ofSquare2. In addition to setters and getters, provide such methodsas computeArea and computePerimeter. Specify the preconditions,postconditions and class invariants, if any, as comments (30%) 3.Compare (1) and (2), illustrating the pros and cons of (1) and (2),respectively. (40%)

he problems arebased on the following Java code, which is part of a sales systemthat supports a discount. If you use a different programminglanguage, it is your responsibility for the programtranslation.

public class Sale{

                                          private static double DISCOUNT_RATE = 0.05;

                                          private Vector itemList = new Vector();

                                          public void addItem(Item item) {



public doublegetDiscountRate(){

                                                     return DISCOUNT_RATE;


                                          public double getDiscount(){

                                                     return getSubTotal()*getDiscountRate();


                                          public double getSubTotal() {

double subTotal = 0.0;

                      Enumeration items = itemList.elements();               while (items.hasMoreElements()) {                                 Item theNextItem = (Item)nextElement();

                                                                subTotal += theNextItem.getItemTotal();





                                           public double getDiscountedSubTotal() {

                                                     return getSubTotal() – getDiscount();



Requirements: Clearly describe the ideas ofyour program design and refactoring. Copy and paste all thesource code, test cases, and testing results as screen shots.Comment your code if necessary. Handwriting answers will not beaccepted.

  1. Complete the Item class to make the program executable. Theinstance variables of Item should at least include title,(original) unit price, and quantity. Test the program withappropriate test cases.
  2. Update your program to support different discounts for seniorsand preferred customers. Retest your program and add appropriatenew test cases. Your program must use switch (case)statement(s).
  3. Update your program for 2) to support that the senior’sdiscount is only on Tuesday. Retest your program and addappropriate new test cases. Your program must keep the switch(case) statement(s).
  4. Refactor your program for 3) to eliminate the switchstatement(s), and retest your program. Update your program for 4)to handle the new discount policy “buy one, get the second (and therest of the same item) 50% off” for certain items.

Expert Answer

Answer to Use an object-oriented language (Java, C#, or C++) to solve the following problems. 1. Write a pair of classes, Square1 …

Leave a Comment


We are the best freelance writing portal. Looking for online writing, editing or proofreading jobs? We have plenty of writing assignments to handle.

Quick Links

Browse Solutions

Place Order

About Us

× How can I help you?