forked from Denisolt/CSCI-160
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStockReport.java
More file actions
110 lines (108 loc) · 3.86 KB
/
StockReport.java
File metadata and controls
110 lines (108 loc) · 3.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
package StockMarket;
/****************************************************
*Project Inormaiton
*Course: CSCI 185/504 Spring 2016
*Project Name: Project #5
*File Name: StockReport
*Author: Denisolt Shakhbulatov
*Date Created: 04/22/2016
*Date Updated: 04/22/2016 class has been created
*Description: This class uses printwriter, stores inputted information in arrays and creates a txt file with information in them
* Also DowSold class and DowBuy class extends StockReport. Project reads a txt file and gives an output.
*****************************************************************************************************************************************/
import java.util.*;
import java.util.Scanner;
import java.io.*;
public class StockReport
{
Scanner keyboard = new Scanner(System.in);
String Name;
StockReport(String Name)
{
String dowNAme = Name;
}
public void DisplaySold()
{
System.out.println("Starting Dow Jones Sold Report");
}
public void DisplayBuy()
{
System.out.println("Starting Dow Jones Buy Report");
}
public class DowSold extends StockReport
{
String stockNAme;
DowSold(String stockName)
{
super(stockName);
String STOCKname = stockNAme;
try
{
int [] dow = new int [4];
int [] Quantity = new int [4];
double [] Price = new double [4];
String [] name = new String [4];
double total=0;
double price;
int quant;
File file = new File("StockDataIn.txt");
Scanner inFile = new Scanner(file);
for(int i=0; i<4; i++)
{
dow[i] = inFile.nextInt();
quant = inFile.nextInt();
Quantity[i] = quant;
price = inFile.nextInt();
Price[i] = price;
name[i] = inFile.nextLine();
total = total + (price*quant);
System.out.println("Sold " +Quantity[i] + " of "+ name[i] + " (DOW: " + dow[i]+") at $"+Price[i]+" each.");
}
System.out.println("The total: " + total);
inFile.close();
}
catch(Exception e){
System.err.println("Error occured");
}
}
}
public class DowBuy extends StockReport
{
String fileName;
DowBuy(String dowName)
{
super(dowName);
String dowNAme = dowName;
try
{
int [] dow = new int [4];
int [] Quantity = new int [4];
double [] Price = new double [4];
String [] name = new String [4];
double total=0;
double price;
int quant;
Scanner kb = new Scanner(System.in);
PrintWriter filesWrited = new PrintWriter("StockDataOut.txt");
filesWrited.println("Dow Quantity Price StockName");
for(int i=0; i<4; i++)
{
System.out.println("Enter Dow, Quantity, Price, StockName: ");
dow[i] = kb.nextInt();
quant = kb.nextInt();
Quantity[i] = quant;
price = kb.nextInt();
Price[i] = price;
name[i] = kb.nextLine();
total = total + (price*quant);
filesWrited.println(dow[i]+" "+Quantity[i]+" "+Price[i]+" "+ name[i]);
}
filesWrited.println("The total: " + total);
filesWrited.close();
}
catch(Exception e){
System.err.println("File does not exist");
}
}
}
}