Question: 1. Using the Linked List showed below, Modify them to compute the total cost purchased by a customer. The program has a menu that will

1. Using the Linked List showed below, Modify them to compute the total cost purchased by a customer. The program has a menu that will show the items and the prices. The program will ask the user the item to purchase and after the user chooses the item, the program will ask the quantity purchased. The user can add more item purchased as soon as the user quit from the menu.

Note: The ItemNo, Qty and Price should be saved in the list. Since the program discussed above has only two data and a link to point to a node, you need to add one more data. It means the total data should be three (3) and a link to point to a node.

List of Products

Item No. Items Price (Dhs)

101 T-Shirt 70.25

102 Polo 160.75

103 Long Sleeve 250.45

104 Pants 300.35

105 Shoes 200.85

Menu [1] Enter Order

[2] Print Receipt

[3] Exit

Enter your choice: 1

Enter Item No.:101 Enter Quantity:2

----------------------------------------

Menu [1] Enter Order

[2] Print Receipt

[3] Exit

Enter your choice: 1

Enter Item No.:102 Enter Quantity:1

-----------------------------------------

Menu [1] Enter Order

[2] Print Receipt

[3] Exit

Enter your choice: 2

Item No. Price Qty Cost

101 70.25 2 140.50 102 160.75 1 160.75

Total Cost: 301.25

----------------------------------------------------------

class Link {

public int iData;

public double dData;

public Link next;

public Link(int id, double dd)

{

iData = id;

dData = dd;

}

public void displayLink() // display ourself

{

System.out.print("{" + iData + ", " + dData + "} "); }

}

class LinkList {

private Link first;

public LinkList()

{

first = null;

}

public boolean isEmpty()

{

return (first==null); }

public void insertFirst(int id, double dd)

{

Link newLink = new Link(id, dd);

newLink.next = first;

}

public Link deleteFirst() {

Link temp = first; first = first.next; return temp;

}

public void displayList() {

System.out.print("List (first-->last): ");

Link current = first; while(current != null)

{

current.displayLink();

current = current.next;

}

System.out.println("");

}

}

class LinkListApp {

public static void main(String[] args) {

LinkList theList = new LinkList();

 theList.insertFirst(22, 2.99); theList.insertFirst(44, 4.99); theList.insertFirst(66, 6.99); theList.insertFirst(88, 8.99); 
 theList.displayList(); 

while( !theList.isEmpty() ) {

// make new list // insert four items 
// display list 

Link aLink = theList.deleteFirst();

System.out.print("Deleted ");

aLink.displayLink();

// start at beginning of list // until end of list,

// print data

//

until it's empty, 
 // delete link // display it

System.out.println("");

 } theList.displayList(); } // end main() 

} // end class LinkListApp

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!