Question: Convert the Code below to include inheritance, separating at least one class into two classes. One of the classes has to be an abstract class
Convert the Code below to include inheritance, separating at least one class into two classes.
One of the classes has to be an abstract class
Include an interface in the application that must be implemented
Replace the sorting algorithm with one of the following:
Bubble sort
Quick sort
Selection sort
Merge sort
import java.util.ArrayList; import java.util.Scanner; class Item { public static void main(String[] args) { Scanner sc = new Scanner(System.in); ShoppingList List = new ShoppingList(); int Opt = 0; while (Opt != 3) { System.out.println("--------------------------"); System.out.println("----- Shopping List------"); System.out.println("1.Add an item to the list. "); System.out.println("2.Display list and total number of items. "); System.out.println("3.Exit. "); Opt = sc.nextInt(); if (Opt == 1) { List.addItem(); } if (Opt == 2) { List.displayItem(); } } sc.close(); }
}
class ShoppingItem { private String ItemName; private double ItemPrice; private int ItemQty; public ShoppingItem() { ItemName = "Apple"; ItemPrice = 100; ItemQty = 1; } public ShoppingItem(String ItemName, double ItemPrice, int ItemQty ) { this.ItemName = ItemName; this.ItemPrice = ItemPrice; this.ItemQty = ItemQty; } public String getItemName() { return ItemName; } public double getItemPrice() { return ItemPrice; } public double getItemTotalPrice() { return ItemPrice * ItemQty; } public int getItemQty() { return ItemQty; }
public void setItemName(String ItemName) { this.ItemName = ItemName; }
public void setItempPrice(double ItemPrice) { this.ItemPrice = ItemPrice; } public void setItemQty(int ItemQty) { this.ItemQty = ItemQty; } public String toString() { String state = ItemName + " - $" + ItemPrice + " x " + ItemQty; return state; } }
import java.util.ArrayList; import java.util.Scanner;
class ShoppingList { ArrayList
} }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
