# Purchase price
oats.p <- 1.05
peas.p <- 3.17
beans.p <- 1.99
barley.p <- 0.95

# Sale price
oats.s <- 1.29
peas.s <- 3.76
beans.s <- 2.23
barley.s <- 1.65

# Genetate Discrete Uniform Random demand for the season(90 days)

set.seed(1023)
oats.sale <- c(ceiling(runif(n = 90, min = -1, max = 10)))
peas.sale <- c(ceiling(runif(n = 90, min = -1, max = 8)))
beans.sale <- c(ceiling(runif(n = 90, min = -1, max = 14)))
barley.sale <- c(ceiling(runif(n = 90, min = -1, max = 11)))

par(mfrow=c(2,2))
hist(oats.sale, xlab = "pounds", main = "Histogram of Oats Demand(lbs)")
hist(peas.sale, xlab = "pounds", main = "Histogram of peas Demand(lbs)")
hist(beans.sale, xlab = "pounds", main = "Histogram of Beans Demand(lbs)")
hist(barley.sale, xlab = "pounds", main = "Histogram of Barley Demand(lbs)")

par(mfrow=c(1,1))


# Cost, Revenue and Profit

cost <- oats.p * oats.sale + peas.p * peas.sale + beans.p * beans.sale + barley.p * barley.sale

revenue <- oats.s * oats.sale + peas.s * peas.sale + beans.s * beans.sale + barley.s * barley.sale

profit <- revenue - (oats.p * oats.sale + peas.p * peas.sale + beans.p * beans.sale + barley.p * barley.sale)


day <- c(1:90)

df <- data.frame(day, oats.sale, peas.sale, beans.sale, barley.sale, cost, revenue, profit )
colnames(df) <- c("Day", "Oats Demand(lbs)", "Peas Demand(lbs)", "Beans Demand(lbs)", "Barley Demand(lbs)", "Cost($)", "Revenue($)", "Profit($)")
knitr::kable(df)
Day Oats Demand(lbs) Peas Demand(lbs) Beans Demand(lbs) Barley Demand(lbs) Cost($) Revenue($) Profit($)
1 2 3 3 3 20.43 25.50 5.07
2 2 2 9 10 35.85 46.67 10.82
3 10 1 2 11 28.10 39.27 11.17
4 5 3 12 2 40.54 47.79 7.25
5 4 8 6 5 46.25 56.87 10.62
6 4 6 11 0 45.11 52.25 7.14
7 9 5 9 3 46.06 55.43 9.37
8 1 4 8 0 29.65 34.17 4.52
9 2 1 14 2 35.03 40.86 5.83
10 1 3 13 3 39.28 46.51 7.23
11 3 5 3 4 28.77 35.96 7.19
12 9 1 13 0 38.49 44.36 5.87
13 8 6 9 3 48.18 57.90 9.72
14 8 7 8 0 46.51 54.48 7.97
15 0 7 11 6 49.78 60.75 10.97
16 2 2 1 8 18.03 25.53 7.50
17 1 5 12 2 42.68 50.15 7.47
18 1 0 8 10 26.47 35.63 9.16
19 10 2 13 10 52.21 65.91 13.70
20 3 7 1 1 28.28 34.07 5.79
21 0 7 6 9 42.68 54.55 11.87
22 5 6 11 10 55.66 70.04 14.38
23 10 1 14 10 51.03 64.38 13.35
24 2 0 1 11 14.54 22.96 8.42
25 7 1 10 8 38.02 48.29 10.27
26 3 8 3 5 39.23 48.89 9.66
27 8 2 5 8 32.29 42.19 9.90
28 6 1 8 5 30.14 37.59 7.45
29 5 1 1 0 10.41 12.44 2.03
30 1 4 7 3 30.51 36.89 6.38
31 8 0 9 0 26.31 30.39 4.08
32 6 7 5 3 41.29 50.16 8.87
33 1 0 1 5 7.79 11.77 3.98
34 5 4 13 0 43.80 50.48 6.68
35 10 4 10 5 47.83 58.49 10.66
36 2 8 0 10 36.96 49.16 12.20
37 7 5 13 5 53.82 65.07 11.25
38 8 2 13 10 50.11 63.33 13.22
39 8 5 6 4 39.99 49.10 9.11
40 5 5 13 0 46.97 54.24 7.27
41 7 2 2 6 23.37 30.91 7.54
42 8 8 5 2 45.61 54.85 9.24
43 6 6 9 10 52.73 66.87 14.14
44 4 3 0 2 15.61 19.74 4.13
45 9 7 12 1 56.47 66.34 9.87
46 2 3 14 2 41.37 48.38 7.01
47 7 3 10 6 42.46 52.51 10.05
48 5 8 2 7 41.24 52.54 11.30
49 5 0 11 3 29.99 35.93 5.94
50 6 0 13 1 33.12 38.38 5.26
51 9 8 11 6 62.40 76.12 13.72
52 0 4 7 11 37.06 48.80 11.74
53 9 2 13 4 45.46 54.72 9.26
54 9 6 13 4 58.14 69.76 11.62
55 2 3 9 4 33.32 40.53 7.21
56 7 6 3 9 40.89 53.13 12.24
57 3 1 5 3 19.12 23.73 4.61
58 6 6 8 3 44.09 53.09 9.00
59 0 5 1 11 28.29 39.18 10.89
60 2 7 6 1 37.18 43.93 6.75
61 10 5 10 11 56.70 72.15 15.45
62 10 1 6 5 30.36 38.29 7.93
63 9 8 14 1 63.62 74.56 10.94
64 1 2 8 5 28.06 34.90 6.84
65 10 2 11 1 39.68 46.60 6.92
66 6 1 13 1 36.29 42.14 5.85
67 5 1 5 11 28.82 39.51 10.69
68 8 3 5 2 29.76 36.05 6.29
69 5 3 1 7 23.40 31.51 8.11
70 8 3 3 6 29.58 38.19 8.61
71 8 4 0 8 28.68 38.56 9.88
72 0 2 2 9 18.87 26.83 7.96
73 1 1 9 0 22.13 25.12 2.99
74 8 5 12 11 58.58 74.03 15.45
75 1 3 2 11 24.99 35.18 10.19
76 0 3 7 8 31.04 40.09 9.05
77 4 2 2 2 16.42 20.44 4.02
78 4 8 8 6 51.18 62.98 11.80
79 4 3 2 9 26.24 35.75 9.51
80 0 7 12 10 55.57 69.58 14.01
81 9 4 14 2 51.89 61.17 9.28
82 3 0 11 9 33.59 43.25 9.66
83 2 3 12 10 44.99 57.12 12.13
84 7 4 6 2 33.87 40.75 6.88
85 0 2 12 7 36.87 45.83 8.96
86 3 3 2 0 16.64 19.61 2.97
87 4 2 4 5 23.25 29.85 6.60
88 9 2 7 7 36.37 46.29 9.92
89 7 1 6 1 23.41 27.82 4.41
90 7 4 2 9 32.56 43.38 10.82
plot(cost, type = "o", col = "red", xlab = "Day", ylab = "Dollars", main = "Total Cost, Renenue and Profit by Day")
lines(revenue, type = "o", col = "blue")
lines(profit, type = "o", col = "green")

# Total cost, revenue and profit in 90 days

total.cost <- sum(cost)
total.revenue <- sum(revenue)
total.profit <- sum(profit)

df1 <- data.frame(total.cost, total.revenue, total.profit)
colnames(df1) <- c("Total Cost($)", "Total Revenue($)", "Total Profit($)")
knitr::kable(df1)
Total Cost($) Total Revenue($) Total Profit($)
3306.41 4097.44 791.03
bar <- c(total.cost, total.revenue, total.profit)
label <- c("Total Cost", "Total Revenue", "Total Profit")
p <- barplot(bar, names.arg = label, col = "orange", ylab = "Dollars", main = "Total Cost, Revenue and Profit in 90 Days (Dollars)")
mtext(at = p, text = bar)