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 obj=new ArrayList(); public void addItem() { System.out.println(); System.out.println("Enter the name of item"); Scanner sc = new Scanner(System.in); String ItemName = sc.nextLine(); System.out.println("Enter the price of your item"); double ItemPrice = sc.nextDouble(); System.out.println("Enter the Priority of your item"); int ItemQty = sc.nextInt(); ShoppingItem Item = new ShoppingItem(ItemName, ItemPrice,ItemQty); obj.add(Item); // sc.close(); } public void displayItem() { System.out.println( obj.size()+ " items. "); for (ShoppingItem x : obj) { System.out.println(x.toString()); }

} }

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!