Question: For each problem, study the supplied code, and list the code smells you see. For this exercise the code smells should be one of these:

For each problem, study the supplied code, and list the code smells you see. For this exercise the code smells should be one of these:

  • long method,
  • large class,
  • duplicate code (aka cut and paste code),
  • long parameter list,
  • primitive obsession, and
  • magic numbers.

For each code smell,

  • list the line numbers of the code where the smell is focused,
  • identify the design principle(s) that are violated, and
  • identify some program change that the smell would complicate.

For each problem, study the supplied code, and list the code smells

you see. For this exercise the code smells should be one of

Smells and locations?

Design principles?

Maintenance Consequences?

private static Cart checkOut (Cart customersCart) { Scanner sc = new Scanner (System.in); Random rand = new Random (); int c = rand.nextInt (3) +2; ArrayList items = new ArrayList(customersCart.getItems ()); for(Item i: items) { System.out.println("your current cart:"); displayCart(customersCart.getItems ()); System.out.println("would you like to remove an item? (y)"); if(sc.next().equals ("y")) { printItemsFromList(customersCart.getItems ()); System.out.println("type the number of the item to remove:"); customersCart.getItems (). remove (sc.nextInt ()-1); }else { break; 3 6. 10 11 12 13 14 15 16 17 items = customersCart.getItems (); if(items.size() == 0) { System.out.println("your cart is empty"); return new Cart(items); 18 19 20 21 22 int total = 0; for(Item i : items) { total += i.getPrice(); 23 24 25 26 System.out.println("your total is: $" + total); String s; int shipCost = 7; System.out.println("Would you like to ship these items?(y)"); String ans = sc.next(); String [] ch; if(ans.equals ("y")) { System.out.println("Please enter your address:"); System.out.println("City, State"); while(true) { S = sc.nextLine(); ch = s.split(", "); //System.out.println("length"+ch. length); if(ch. length !=2) { System.out.println("Please write it in this format. For instance: (Ames, Iowa)") continue; 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 break; 44 45 46 System.out.println ("Choose your delivery option:"); 47 48 if(ch[1].charAt (0) == 'I' || ch[1].charAt (0) == 'M') { System.out.println("(1) 1 day shipping - $" + shipcost); System.out.println("(2) 3-4 day shipping - $" + c); 49 50 51 52 else { shipCost = 10; C+= 2; System.out.println("(1) 1 day shipping - $" + shipCost); System.out.println("(2) 3-4 day shipping - $" + c); 53 54 55 56 57 58 int n = sc.nextInt(); if(n==1) { total+=shipCost; 59 60 61 62 63 else if(n==2) { total+=c; 64 65 66 System.out.println ("your total is now: $" + total); 67 68 System.out.println("please input your card number:"); String cardNumber = sc.next(); System.out.println("is " + cardNumber + " valid? (y)"); if(sc.next().equals ("n")) { 69 70 71 72 boolean cardNumberValid = false; while(!cardNumberValid) { System.out.println("your total is: $" + total); System.out.println("please input your card number:"); String nextCardNumber = sc.next(); System.out.println ("is " + nextCardNumber + " valid? (y)"); if(sc.next().equals ("y")) { cardNumberValid = true; 73 74 75 76 77 78 79 80 81 82 Cart cart = new Cart (items); cart.setDiscount (0 - shipCost); System.out.println("would you like to continue shopping? (y)"); if(sc.next().equals ("y")) { Cart deepCart addToCart(); customersCart.getItems (). addAll(deepCart.getItems ()); return customersCart; }else { return customersCart; 83 84 85 86 87 89 90 91 92 93 return cart; 94 95

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!