Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data Mining Concepts And Techniques

Authors: Jiawei Han, Micheline Kamber, Jian Pei

3rd Edition

0123814790, 9780123814791

More Books

Students also viewed these Databases questions

Question

What is the difference between Needs and GAP Analyses?

Answered: 1 week ago

Question

What are ERP suites? Are HCMSs part of ERPs?

Answered: 1 week ago