Question

In: Computer Science

You can use any language. You have to provide all the data, output and input. You...

You can use any language. You have to provide all the data, output and input.

You are to use Linked Lists to do this Program.

The XYZ Widget store receives shipments of widgets at various costs. The store’s policy is to charge a 30% markup, and to sell widgets which were received earlier before widgets which were received later. This is called a FIFO policy.

Write a program using linked lists that reads in three types of input data and does the following:

A sales record which contains an “S” in column 1 and a quantity which represents the number of Widgets sold

A receipt record which contains an “R” in column 1 and a quantity and a price which represent the receipt of a quantity of widgets at the stated cost per widget.

A promotion card which contains a “P” in column 1 and a number such as 25 which would represent a 25% discount to the next 2 buying customers (the next 2 sales cards )

The program should

Print a message after each receipt record is read in with the price of the widgets received.

Print a message after each promotion card is read in with the amount of discount the next to customers will be receiving.

After a sales record is read in print a message stating the number sold and the price of each widget and total price of the order. For example if 200 widgets were sold and there were 50 widgets at $1.00 and 100 at $2.00 and 50 at $3.00 print (recall the 30% markup and the FIFO policy)

          200 Widgets sold

          50   at 1.30 each           Sales: $   65.00

          100 at 2.60 each          Sales: $ 260.00  

          50   at 3.90 each           Sales: $ 195.00

                               Total Sale:    $ 520.00

If there are an insufficient number of widgets in stock to fill an order sell as many as are available and then print

“ Remainder   of xxx   Widgets not available”

Do not forget the promotional discount.

At the end of the data before exiting the program print out under a separate heading the widgets still left in stock and their original purchase price.

Data for program

R/S/P           # widgets or           Price

                     discount%

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

Solutions

Expert Solution

CONSIDERING THE CONDITIONS AND PARMETERSFROM QUESTION WE SHOW THE WORK AS:

AVA CODE :

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:-

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:-

150 widgets received at 1.0 each. Total Received: $158.0

130 widgets received at 2.0 each. Total Received: $260.0

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

50 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

50 widgets received at 4.0 each. Total Received: $200.0

30 widgets received at 5.0 each. Total Received: 150.0

40 widgets received at 5.5 each. Total Received: $220.0

Next 2 custome rs will receive 30% discount.

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

30 Widgets sold

PLEASE UPVOTE ITS VERY NECESSARY FOR ME


Related Solutions

Write a program to create a tree randomly. You can use C++ programming language. The input...
Write a program to create a tree randomly. You can use C++ programming language. The input is the number of vertices in the tree, and the output is an adjacent list of the tree. (Managed to complete this assignment with a binary tree. But, was told I needed a general tree instead)
IN JAVA!!! In this project, you will use radix.txt as the input file, and output the...
IN JAVA!!! In this project, you will use radix.txt as the input file, and output the integers SORTED USING RADIX SORT. You may assume all your input consists of integers <=9999. Your main program will input the integers and put them into a QUEUE. It will then pass this queue to a method called radixSort which will sort the numbers in the queue, passing the sorted queue back to main. The main program will then call another method to print...
Instructions Today, all input and output has been taken care of for you. All you need...
Instructions Today, all input and output has been taken care of for you. All you need to do is finish off the function wordCount that calculates the number of words in a string. Function Details Input Input has been handled for you. A string will be read in. Processing Complete the wordCount function. Note that you have been given Java comments describing its expected parameters and return value. /** * wordCount (String) -> int * Calculates the number of words...
Provide Atmel AVR assembly language statements to implement the following pseudocodes. You can assume that all...
Provide Atmel AVR assembly language statements to implement the following pseudocodes. You can assume that all the variables A, B, C, D correspond to CPU general purpose registers as follows: A →R0, B→R1, C→R2, D→R3. You can also use additional registers from R4- R31 as needed. You must not use any variant of the multiplication instructions. Your assembly code segments should be properly commented. (a) if D < 0 C = A+B else C = A-B (b) if D <...
Write Lexical Analyzer program in C language. Below is the sample input and ouput. /* output...
Write Lexical Analyzer program in C language. Below is the sample input and ouput. /* output Enter the string: if(a<b){a=10;} Tokens are identifier :if punctuation mark : ( identifier :a operator:< identifier :b punctuation mark : ) punctuation mark : { identifier :a operator:= constant :10 punctuation mark : ; punctuation mark : } */
5. Suppose that a data scientist have 200 observations, 300 input variables, and a categorical output...
5. Suppose that a data scientist have 200 observations, 300 input variables, and a categorical output variable. Here is his/her analysis procedure: Step 1. Find a small subset of good predictors that show fairly strong (univariate) association with the output variable. Step 2. Using the input variables selected in Step 1, build LDA (linear discriminant analysis) and QDA (quadratic discriminant analysis) models. Step 3. Perform 5-fold cross-validation for both LDA and QDA models with input variables selected in Step 1....
5. Suppose that a data scientist have 200 observations, 300 input variables, and a categorical output...
5. Suppose that a data scientist have 200 observations, 300 input variables, and a categorical output variable. Here is his/her analysis procedure: Step 1. Find a small subset of good predictors that show fairly strong (univariate) association with the output variable. Step 2. Using the input variables selected in Step 1, build LDA (linear discriminant analysis) and QDA (quadratic discriminant analysis) models. Step 3. Perform 5-fold cross-validation for both LDA and QDA models with input variables selected in Step 1....
Which of the following can serve as both an input to and an output of the...
Which of the following can serve as both an input to and an output of the acquisition / payment process? Check Purchase Order Both A and B Neither A and B
kindly provide the pros and con allong with their properties such as input impedence and output...
kindly provide the pros and con allong with their properties such as input impedence and output impedence , no derivations just knwoledge of the following op amps 1-inverting amplifier 2-non-inverting 3-summer amplifier 4-voltage follower 5-op amp difference amplifier 6-integrator op amp 7- differentiator op amp.
1. Identify and discuss four types of input the organisation can use to achieve its output/s....
1. Identify and discuss four types of input the organisation can use to achieve its output/s. 2. Fully discuss how the inputs are transformed into the final products or services of the organisation. 3. Critically analyse the nature of the outputs and their significance for the organisation and society at large. 4. Make recommendations on what the organisation can do to increase its outputs.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT