Question

M. Lowenthal You are to use Linked Lists to do this program The XYZ Widget Store receivee shipments of widgots at varlous oo
0 0 Aca 100 200 220 400 500 350 45 68 8 dow 150 130 195 50 75 180 50 30 40 BPH 50 30 50 5 60 70 17 40 75 110 30 40 4353 RRsRS
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer:

require code is in java:

import java.util.*;

import java.io.*;

class Node{

char col1;

int col2;

double price;

Node next = null;

public Node(char col1,int col2,double price){

this.col1 = col1;

this.col2 = col2;

this.price = price;

}

public Node(char col1,int col2){

this.col1 = col1;

this.col2 = col2;

}

}

public class LinkedList{

Node head = null;

Node tail = null;

void addNode(char col1,int col2, double price){

Node newNode = new Node(col1,col2,price);

if(head==null){

head = newNode;

tail = newNode;

}else{

tail.next = newNode;

tail = newNode;

}

}

void addNode(char col1,int col2){

Node newNode = new Node(col1,col2);

if(head==null){

head = newNode;

tail = newNode;

}else{

tail.next = newNode;

tail = newNode;

}

}

Node removeNode(){

if(head==null){return null;}

Node newNode = head;

head = head.next;

return newNode;

}

void readFile(){

String filename = "data.txt";

try{

FileInputStream fstream = new FileInputStream(filename);

Scanner fileIn = new Scanner(fstream);

while(fileIn.hasNextLine()){

String line = fileIn.nextLine();

String[] arr = line.split("\\s+");

if(arr.length==3){

char col1 = arr[0].charAt(0);

int col2 = Integer.parseInt(arr[1]);

double price = Double.parseDouble(arr[2]);

addNode(col1,col2,price);

}else if(arr.length==2){

char col1 = arr[0].charAt(0);

int col2 = Integer.parseInt(arr[1]);

addNode(col1,col2);

}

}

}catch(FileNotFoundException e){

System.out.println(filename + " not found. Exiting the program.");

}

}

void loopList(){

Node curr = head,sale = head;

int numCustomers = 0;

double currDiscount = 0;

while(curr!=null){

if(curr.col1=='R'){

double totalPrice = curr.col2*curr.price;

System.out.println(curr.col2 + " widgets received at " + curr.price + " each.");

System.out.println("Total Received: $" + totalPrice);

}else if(curr.col1=='P'){

System.out.println("Next 2 customers will receive " + curr.col2 + "% discount.");

numCustomers = 2;

currDiscount = curr.col2;

}else{

Node tempSale = sale;

int totalWidgets = 0;

while(tempSale!=curr && totalWidgets<=curr.col2){

if(tempSale.col1=='R'){

totalWidgets += tempSale.col2;

}

tempSale = tempSale.next;

}

if(totalWidgets>=curr.col2){

totalWidgets = curr.col2;

}

System.out.println(totalWidgets + " Widgets sold");

double totalPrice = 0;

tempSale = sale;

while(tempSale!=curr && totalWidgets>0){

if(tempSale.col1=='R'){

double newPrice = tempSale.price*1.3;

if(tempSale.col2<=totalWidgets){

System.out.println(tempSale.col2 + " at " + newPrice + " each\tSales:$" + newPrice*tempSale.col2);

totalPrice += newPrice*tempSale.col2;

totalWidgets-=tempSale.col2;

tempSale.col2 = 0;

tempSale = tempSale.next;

}else{

System.out.println(totalWidgets + " at " + newPrice + " each\tSales:$" + newPrice*totalWidgets);

totalPrice += newPrice*totalWidgets;

tempSale.col2 -= totalWidgets;

totalWidgets = 0;

}

}else{

tempSale = tempSale.next;

}

}

sale = tempSale;

System.out.println("\t\tTotal Sales:$" + totalPrice);

if(numCustomers>0){

System.out.println("\t\tDiscount:$" + totalPrice*(currDiscount/100));

numCustomers--;

}

System.out.println("\tTotal Sales after Dicount:$" + totalPrice*(1-currDiscount/100));

}

curr = curr.next;

System.out.println();

}

}

public static void main(String[] args) {

LinkedList l = new LinkedList();

l.readFile();

l.loopList();

}

}

Input:-

-------------------------data.txt------------------------

R 150 1.00
R 130 2.00
S 145
R 50 2.50
S 75
S 180
R 50 4.00
R 30 5.00
R 40 5.50
P 30
S 50
S 30
R 50 6.00
R 265 10.00
S 60
P 50
S 100
S 70
S 175
R 40 14.00
R 75 15.00
S 110
R 30 16.00
R 40 18.00

Sample Output:-

15θ widgets received at 1.0 each. Total Received: $158.θ

13θ widgets received at 2.0 each. Total Received: $26θ.θ

145 Widgets sold 145 at 1.3 each Sales: $188.5 Total Sales: $188.5 Total Sales after Dicount:$188.5

5θ widgets received at 2.5 each. Total Received: $125.0

Widgets sold 75 5 at 1.3 each Sales:$6.5 7θ at 2.6 each Sales: $182.0 Total Sales: $188.5 Total Sales after Dicount:$188.5

110 Widgets sold 60 at 2.6 each Sales:$156.0 50 at 3.25 each Sales: $162.5 Total Sales: $318.5 Total Sales after Dicount:$318.5

5θ widgets received at 4.0 each. Total Received: $2θθ.θ

3θ widgets received at 5.0 each. Total Received: 150.θ

40 widgets received at 5.5 each. Total Received: $220.θ

Next 2 custome rs will receive 30% discount.

50 Widgets sold 5θ at 5.2 each Sales: $268.0 Total Sales: $268. θ Discount : $78. θ Total Sales after Dicount: $182.0

3θ Widgets sold

it is useful if having any doubt or problem please commnet orelse please give positive feedback.

Add a comment
Know the answer?
Add Answer to:
M. Lowenthal You are to use Linked Lists to do this program The "XYZ Widget Store...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • c++ File name: 2170 107b.ee Purpose: This program demonstrates the use of multi-linked lists. //This file...

    c++ File name: 2170 107b.ee Purpose: This program demonstrates the use of multi-linked lists. //This file contains the implementation file for the 2170_10_7b.h header file. This implementation uses a dynamic linked list structure implementing the // Multi ListClass object. The implementation uses nodes which have two pointer fields one to point to the next record by name (nextName) and one to point Ito the next record by account number(nextNum). The linked list is also maintained I with a dummy header...

  • Write a JAVA program to monitor the flow of an item into an out of a...

    Write a JAVA program to monitor the flow of an item into an out of a warehouse. The warehouse has numerous deliveries and shipments for this item (a widget) during the time period covered. A shipment out (an order) is billed at a profit of 50% over the cost of the widget. Unfortunately each incoming shipment may have a different cost associated with it. The accountants of the firm have instituted a last-in, first out system for filling orders. This...

  • Write a complete JAVA program to do the following program. The main program calls a method...

    Write a complete JAVA program to do the following program. The main program calls a method to read in (from an input file) a set of people's three-digit ID numbers and their donations to a charity (hint: use parallel arrays)Then the main program calls a method to sort the ID numbers into numerical order, being sure to carry along the corresponding donations. The main program then calls a method to print the sorted 1ists in tabular form, giving both ID...

  • For this program, you will be working with data from the NASA website which lists Near...

    For this program, you will be working with data from the NASA website which lists Near Earth Objects detected by the JPL Sentry System. You are given a text file listing the designation and impact probability (with Earth, generally within the next 100 years) of 585 Near Earth Objects. Your job will be to sort these objects by their impact probabilities. Input File Format The input file contains 585 records. Each record is on a separate line. Each line contains...

  • Write a C++ program that will calculate the total amount of money for book sales at...

    Write a C++ program that will calculate the total amount of money for book sales at an online store. For each sale, your program should ask the number of books sold and then the price for each book and the shipping method (‘S’ for standard shipping and ‘E’ for expedited shipping). The program will produce a bill showing the subtotal, the sales tax, the discount, the shipping charge, and the final total for the sale. The program will continue processing...

  • On February 14, 2017, Prime Company sold 50 air-conditioning units to L&P Heating and Cooling. The...

    On February 14, 2017, Prime Company sold 50 air-conditioning units to L&P Heating and Cooling. The units were shipped and their titles were transferred to L&P Heating and Cooling on February 14, 2017. The units are listed for retail at $700 each, but L&P was granted a 30% trade discount. All of Prime's sales are subject to terms 2/10, n/30. Prime uses the net method of accounting for sales discounts. Required: a. Prepare the journal entry to record the sale...

  • 2. Write a program to prepare email address with name of person, email ID. This program...

    2. Write a program to prepare email address with name of person, email ID. This program should collect number of persons with their details menstion in the above. Finally, print all the registerd preson with their details and also print selected particular person's emails. 1. Write a program to prepare departmental store records with item name, number of items. This program should collect number of items with its details menstion in the above. Finally, print all the registerd items with...

  • NOTE: All C++ programs that you write must have comments at the top with the program...

    NOTE: All C++ programs that you write must have comments at the top with the program name, your name, and the pseudocode describing what the program will do. 1. Create a new program that will calculate the total cost for software purchased from a store. Each software package costs $99.00, but discounts are given on the total cost, based on the number of packages purchased. a. Ask the user for the number of packages they want to buy b. Calculate...

  • Using python 3 to create the UDP Ping Clien and server. Using UDP sockets, you will...

    Using python 3 to create the UDP Ping Clien and server. Using UDP sockets, you will write a client and server program that enables the client to determine the round-trip time (RTT) to the server. To determine the RTT delay, the client records the time on sending a ping request to the server, and then records the time on receiving a ping response from the server. The difference in the two times is the RTT. The ping message contains 2...

  • NOTE: Write the Program in python as mentioned below and use while loop and flags as...

    NOTE: Write the Program in python as mentioned below and use while loop and flags as necessary. And please write the code following the program description given below. Directions: Read the program description below carefully. All requirements must be met by your program to receive full credit. Thus, pay particular attention to input and output requirements, structural requirements, and so on. Furthermore, code that contains syntax errors will not receive any credit, so be sure that your code interprets correctly...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT