Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hello, I am taking a simulation and modeling class and we are using java. I am having some trouble with this assignment. Here is what

Hello, I am taking a simulation and modeling class and we are using java. I am having some trouble with this assignment. Here is what my assignment looks like:

The Newsboy Problem

Suppose a newsboy knows from past experience that customers' demand maybe 15,16,17,18,19 or 20 newspapers a day. He knows that that relative frequency will be;

Customer Demand Relative Frequency

15 1/12

16 1/12

17 5/12

18 2/12

19 2/12

20 1/12

The newsboy buys papers for 35 cents and sells them for $1.00. All extra papers he has left at the end of the day can be returned for 5 cents each. Write a program to determine the best reordering policy of the following

  1. Order 16 papers each day.
  2. Order the same number each day as called for the last.
  3. Order one less each day than called for the previous day.

Run each reordering policy for 1,000 days and print the results.

Modify the Newsboy simulation. Add to the Newsboy object the ability to maintain statistics. The new object should be able to return the average papers sold per day, the average papers demanded per day, and the variance for both the papers sold and demanded. Further, the new object must produce the average profit per day and the variance of the daily profit.

I have been able to implement A from the assignment but my question is how do I implement B and C into my code?

Here is what I have for my code:

/*This is a simulation program written in Java. Each day the news boy must order the papers for the next day. He buys the papers for 10 cents and sells them for 20 cents. The simulation runs for 100 days and generates the paper demand (from 10 to 15 per day) randomly for an observed distribution. Over the 1000 day period, the simulation collects profit per day, average profit per day and the average papers demanded per day. */ import java.io.*; import java.io.IOException; import javax.swing.*; import java.util.*; import java.io.File; import java.io.FileNotFoundException; import java.lang.*; import java.util.NoSuchElementException; import java.math.*; public class NewsBoySim { public static void main(String[] args)throws Exception { PrintWriter outpt; // now equate the internal name to an external file through the PrintWriter outpt=new PrintWriter(new File("NewsBoyOut.txt")); int i, day; // Inventory pans=new Inventory(15.75, 10); cstats statics=new cstats(); //Initiate statistics newsboy joe=new newsboy(); // initiate Joe dmdproc wantpaper=new dmdproc(); //initiate wantpaper process int dmd; double sales, money; //now start a loop to test joe's behavior for 5 days. Have demand constant at 11 for (day=1;day<=1000;day++) {// get the demand for today dmd=wantpaper.dmdtoday(); //give Joe the demand for today joe.setdemand(dmd); // record the statistics for this day statics.setprofit(joe.getprofit()); // order papers for tomorrow joe.order(); if(day>=500&&day<=505) { System.out.println("for day "+day+" demand "+dmd+" sold "+joe.getsold()); System.out.println(" profit "+joe.getprofit()+" ordered "+joe.getordered()); outpt.println("for day "+day+" demand "+dmd+" sold "+joe.getsold()); outpt.println(" profit "+joe.getprofit()+" ordered "+joe.getordered()); } }; //end of timing loop System.out.println("sold "+joe.getsold()+" ordered "+joe.getordered()); System.out.println("profit "+joe.getprofit()); System.out.println("**************Statics for 1000 Days of Sales***************"); System.out.println("average profit "+statics.getaverage()); System.out.println("variance "+statics.getvar()+" st dev "+statics.getstdev()); System.out.println("count "+statics.getcount()); // a test of the Math.random function int x; for ( i=1;i<=30;i++) {x=(int)(Math.random()*100); //System.out.println( x); } }// end of main }//end of newsboysim class newsboy{ private int demand;// this is the demand for the day private int ordered;// this is the amount ordered for today private int bought;//this is the amount bought for today private int sold;// this is the amount sold for today private double profit;// // now for the behaviors of the newsboy public newsboy() {// this is the constructor for the newsboy // set all values to 0 and start him with 10 papers demand=0; ordered=10; bought=0; sold=0; profit=0.0; }//end of newsboy constructor public int order() {// this is a private policy function for how many the newsboy will order daily int x; x=16; // order 16 papers daily ordered=x; return x; } private void behavior() {// this is the behavior of the newsboy. // recieve the papers ordered yesterday bought=ordered; // System.out.println ("nboybehavior bought "+bought+" demand "+demand); // calculate the papers sold if(demand>=bought)sold=bought; else sold=demand; // calculate profit profit=0.20*sold-0.10*bought; // order for tomorrow ordered=order(); // System.out.println(" bought "+bought+" ordered "+ordered+" demand "+demand+" sold "+sold); }// this is the end of the behavior of the newsboy public void setdemand(int x) {// we will give the newsboy a demand and then let him behave as appropriate demand=x; //given the demand for the day, activate the behavior of the newsboy object behavior(); }//end of setdemand //********************************Now Create the Utility functions to Interrograte the News Boy Objecct public double getprofit(){return profit;} public int getsold(){return sold;} public int getordered(){return ordered;} }// end of newsboy class //**********************Now Setup the Calculator Class********************************* class cstats { private double profit;//profit for today private double psum;//sum of profit for all days private double psum2;//sum squaared of profit private double average;//average profit private double stdev;//standard deviation private double variance;// variance private int count;// public cstats() {//constructor for cstats profit=psum=psum2=average=stdev=variance=0; count=0; } public void setprofit(double x) {// this function sets profit and calculates the stats for the day profit=x; psum+=profit; psum2+=profit*profit; count++; average=psum/count; variance=psum2/count-average*average; stdev=Math.sqrt(variance); return; }// end of setprofit // Utility functions to return values from cstats public double getprofit() {return profit;} public double getaverage(){return average;} public double getvar(){return variance;} public double getstdev(){return stdev;} public int getcount(){return count;} }// end of class cstats class dmdproc {//this is the process generator for the demand private int demand; public dmdproc() {// this is the conctructor for dmdproc demand=0; } public int dmdtoday() {//this is the process generator for the demand today //the demand for papers considered with percents on a daily basis is // 10-10%, 11-20%,12-30%, 13-10%, 14-10%, 15-20% int x; // this is the random variante U(0-100) x=(int)(Math.random()*100); if (x<=20)demand=10; else if(x<=30)demand=11; else if(x<=60)demand=12; else if(x<=70)demand=13; else if(x<=80)demand=14; else demand=15; // System.out.println(" x and demand"+x+" "+demand); return demand; }// end of dmdtoday }//end of class dmdproc 

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

Database Concepts

Authors: David Kroenke, David Auer, Scott Vandenberg, Robert Yoder

9th Edition

0135188148, 978-0135188149, 9781642087611

More Books

Students also viewed these Databases questions

Question

Calculate the lifetime value (LTV) of a loyal customer.

Answered: 1 week ago