Advertisement
Guest User

Untitled

a guest
Oct 19th, 2018
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 40.75 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package stock.market.project;
  7.  
  8. import java.io.BufferedWriter;
  9. import java.io.FileNotFoundException;
  10. import java.io.FileReader;
  11. import java.io.FileWriter;
  12. import java.io.IOException;
  13. import java.text.DecimalFormat;
  14. import java.util.Scanner;
  15. import java.util.NoSuchElementException;
  16.  
  17. /**
  18. *
  19. * * Password: SpanishInquisition
  20. * Admin Password: Shinobu
  21. * @author MIKU
  22. */
  23. public class StockMarketProject
  24. {
  25. static Scanner InputSC = new Scanner (System.in);
  26.  
  27. /**
  28. * @param args the command line arguments
  29. * @throws java.io.IOException
  30. */
  31. public static void main(String[] args) throws IOException , NoSuchElementException
  32. {
  33. boolean Pw = true , Loop = true , Adp;
  34. String operation;
  35.  
  36. System.out.println(": : : : : : : : : : : : : : : : : : : : : : : : : : : : : ");
  37. System.out.println(": WELCOME TO THE PHILIPPINE STOCK EXCHANGE(PSE) :");
  38. System.out.println(": : : : : : : : : : : : : : : : : : : : : : : : : : : : : ");
  39. System.out.println(" ");
  40. System.out.println("Enter Username: Zeo Q. Juntilla");
  41. while(Pw == true)
  42. {
  43. Pw = Password();
  44. /* Password: SpanishInquisition */
  45. /* Admin Password: Shinobu */
  46. }
  47.  
  48. System.out.println(": : : : : : : : : : : : : : ");
  49. System.out.println(": : ");
  50. System.out.println(": MAIN MENU :");
  51. System.out.println(": : ");
  52. System.out.println(": [1] Add new Index : ");
  53. System.out.println(": [2] View User Info :");
  54. System.out.println(": [3] View Indices :");
  55. System.out.println(": [4] Delete Index : ");
  56. System.out.println(": [5] Sell Stock :");
  57. System.out.println(": [6] Buy Stock :");
  58. System.out.println(": [7] Exit :");
  59. System.out.println(": : ");
  60. System.out.println(": : : : : : : : : : : : : : ");
  61.  
  62. while(Loop == true)
  63. {
  64. System.out.println(" ");
  65. System.out.print(" Enter operation: ");
  66. operation = InputSC.next();
  67. switch(operation)
  68. {
  69. case "1":
  70. Adp = AdminPAssword();
  71. if(Adp == true)
  72. {
  73. AddIndex();
  74. }
  75. break;
  76.  
  77. case "2":
  78. UserInfo();
  79.  
  80. break;
  81.  
  82. case "3":
  83. ViewAll();
  84.  
  85. break;
  86.  
  87. case "4":
  88. Adp = AdminPAssword();
  89. if(Adp == true)
  90. {
  91. DeleteIndex();
  92. }
  93.  
  94. break;
  95.  
  96. case "5":
  97. SellStock();
  98.  
  99. break;
  100.  
  101. case "6":
  102. BuyStock();
  103.  
  104. break;
  105.  
  106. case "7":
  107. Loop = false;
  108.  
  109. break;
  110.  
  111. default:
  112. {
  113. System.out.print("Wrong Operation!!");
  114. }
  115.  
  116. }
  117. }
  118.  
  119. }
  120.  
  121. private static boolean Password()
  122. {
  123. String input;
  124. System.out.print("Enter Password: ");
  125. input = InputSC.next();
  126.  
  127. if("SpanishInquisition".equals(input))
  128. {
  129. System.out.println(" ");
  130. return false;
  131. }
  132. else
  133. {
  134. System.out.println(": : : : : : : : : : : : : : : : : : : ");
  135. System.out.println(": Wrong Password Please Try Again : ");
  136. System.out.println(": Hint: Unexpected Pssword :");
  137. System.out.println(": : : : : : : : : : : : : : : : : : : ");
  138. System.out.println(" ");
  139.  
  140. }
  141. return true;
  142.  
  143. }
  144.  
  145. private static boolean AdminPAssword()
  146. {
  147. String input;
  148. System.out.print("Enter Admin Password: ");
  149. input = InputSC.next();
  150.  
  151. if("Shinobu".equals(input))
  152. {
  153. System.out.println(" ");
  154. return true;
  155. }
  156. else
  157. {
  158. System.out.println(": : : : : : : : : : : : : : : : : : : ");
  159. System.out.println(": Wrong Password Please Try Again : ");
  160. System.out.println(": Hint: Doge :");
  161. System.out.println(": : : : : : : : : : : : : : : : : : : ");
  162. System.out.println(" ");
  163. }
  164. return false;
  165.  
  166.  
  167. }
  168.  
  169. private static void AddIndex() throws IOException
  170. {
  171. try (BufferedWriter bufferedwriter = new BufferedWriter(new FileWriter("rc\\stock\\market\\project\\Stock.txt", true)))
  172. {
  173. Scanner input = new Scanner(System.in);
  174. String flower;
  175. int price,quantity;
  176. System.out.print("Enter Index name ");
  177. flower = input.next();
  178. System.out.print("Enter price: ");
  179. price = input.nextInt();
  180. System.out.print("Enter quantity: ");
  181. quantity = input.nextInt();
  182. bufferedwriter.append(flower+" "+price+" "+quantity+"\n");
  183. }
  184. }
  185.  
  186. private static void UserInfo() throws FileNotFoundException
  187. {
  188. System.out.println("");
  189. System.out.println(": : : : : : : : : : : : : : ");
  190. System.out.println(": : ");
  191. System.out.println(": USER'S INFO MENU :");
  192. System.out.println(": :");
  193. System.out.println(": [1] View Bought Stocks :");
  194. System.out.println(": [2] View Sold Stocks :");
  195. System.out.println(": [3] Back :");
  196. System.out.println(": : ");
  197. System.out.println(": : : : : : : : : : : : : : ");
  198.  
  199. boolean Loop = true;
  200. String operation;
  201. while(Loop == true)
  202. {
  203. String In , In1 , In2 , In3 , In4 , In5 ;
  204. Scanner txt=new Scanner(new FileReader("src\\stock\\market\\project\\UserFiles"));
  205. System.out.println(" ");
  206. System.out.print(" Enter operation: ");
  207. operation = InputSC.next();
  208.  
  209. switch(operation)
  210. {
  211.  
  212. case "1":
  213. System.out.println(": : : : : : : : : : : : : : : : : : : : : : : : : : : : : ");
  214. System.out.println(":\t"+"Index"+"\t"+":"+"\t"+"Price"+"\t"+":"+"\t"+"Quantity"+"\t"+":");
  215.  
  216. while(txt.hasNextLine())
  217. {
  218. String line=txt.nextLine();
  219. Scanner textline= new Scanner(line);
  220. In = textline.next();
  221. In1 = textline.next();
  222. In2 = textline.next();
  223. In3 = textline.next();
  224. In4 = textline.next();
  225.  
  226. if(line.equals(" "))
  227. {
  228. /*continue*/
  229. }
  230. if("Buy".equals(In4))
  231. {
  232. System.out.println(":\t"+In+"\t"+":"+"\t"+In1+"\t"+":"+"\t"+In2+"\t\t"+":" );
  233. }
  234. }
  235. System.out.println(": : : : : : : : : : : : : : : : : : : : : : : : : : : : : ");
  236. txt.reset();
  237. break;
  238.  
  239. case "2":
  240. System.out.println(": : : : : : : : : : : : : : : : : : : : : : : : : : : : : ");
  241. System.out.println(":\t"+"Index"+"\t"+":"+"\t"+"Price"+"\t"+":"+"\t"+"Quantity"+"\t"+":");
  242.  
  243. while(txt.hasNextLine())
  244. {
  245. String line=txt.nextLine();
  246. Scanner textline= new Scanner(line);
  247. In = textline.next();
  248. In1 = textline.next();
  249. In2 = textline.next();
  250. In3 = textline.next();
  251. In4 = textline.next();
  252.  
  253. if(line.equals(" "))
  254. {
  255. /*continue*/
  256. }
  257. if("Sell".equals(In4))
  258. {
  259. System.out.println(":\t"+In+"\t"+":"+"\t"+In1+"\t"+":"+"\t"+In2+"\t\t"+":" );
  260. }
  261. }
  262. System.out.println(": : : : : : : : : : : : : : : : : : : : : : : : : : : : : ");
  263. txt.reset();
  264. break;
  265.  
  266. case "3":
  267. Loop = false;
  268. break;
  269.  
  270. default:
  271. System.out.print("Wrong Operation!!");
  272. break;
  273.  
  274. }
  275. if(Loop == false)
  276. {
  277. System.out.println(": : : : : : : : : : : : : : ");
  278. System.out.println(": : ");
  279. System.out.println(": MAIN MENU :");
  280. System.out.println(": : ");
  281. System.out.println(": [1] Add new Index : ");
  282. System.out.println(": [2] View User Info :");
  283. System.out.println(": [3] View Indices :");
  284. System.out.println(": [4] Delete Index : ");
  285. System.out.println(": [5] Sell Stock :");
  286. System.out.println(": [6] Buy Stock :");
  287. System.out.println(": [7] Exit :");
  288. System.out.println(": : ");
  289. System.out.println(": : : : : : : : : : : : : : ");
  290. }
  291.  
  292.  
  293. }
  294. }
  295.  
  296. private static void ViewAll() throws FileNotFoundException, IOException
  297. {
  298.  
  299. String In , In1 ,In2 ;
  300.  
  301. boolean Loop = true;
  302. String operation;
  303.  
  304. System.out.println("");
  305. System.out.println(": : : : : : : : : : : : : : ");
  306. System.out.println(": : ");
  307. System.out.println(": INDICES MENU :");
  308. System.out.println(": :");
  309. System.out.println(": [1] View ALL :");
  310. System.out.println(": [2] Search Index :");
  311. System.out.println(": [3] View Available : ");
  312. System.out.println(": [4] View Out of Stock : ");
  313. System.out.println(": [5] Edit Price : ");
  314. System.out.println(": [6] Back :");
  315. System.out.println(": : ");
  316. System.out.println(": : : : : : : : : : : : : : ");
  317. while(Loop == true)
  318. {
  319. Scanner txt=new Scanner(new FileReader("src\\stock\\market\\project\\Stock.txt"));
  320.  
  321. System.out.println(" ");
  322. System.out.print(" Enter operation: ");
  323. operation = InputSC.next();
  324. switch(operation)
  325. {
  326. case "1":
  327.  
  328. System.out.println(": : : : : : : : : : : : : : : : : : : : : : : : : : : : : ");
  329. System.out.println(":\t"+"Index"+"\t"+":"+"\t"+"Price"+"\t"+":"+"\t"+"Quantity"+"\t"+":");
  330.  
  331. while(txt.hasNextLine())
  332. {
  333. String line=txt.nextLine();
  334. Scanner textline= new Scanner(line);
  335. In = textline.next();
  336. In1 = textline.next();
  337. In2 = textline.next();
  338. if(line.equals(" "))
  339. {
  340. /*continue*/
  341. }
  342. System.out.println(":\t"+In+"\t"+":"+"\t"+In1+"\t"+":"+"\t"+In2+"\t\t"+":" );
  343. }
  344. System.out.println(": : : : : : : : : : : : : : : : : : : : : : : : : : : : : ");
  345. txt.reset();
  346.  
  347. break;
  348.  
  349. case "2":
  350. String input;
  351.  
  352. System.out.print("Enter an Index: ");
  353. input=InputSC.next();
  354.  
  355. while(txt.hasNextLine())
  356. {
  357. String line=txt.nextLine();
  358. if(line.equals(" "))
  359. {
  360. /*continue*/
  361. }
  362. else
  363. {
  364. Scanner sline= new Scanner(line);
  365. String index=sline.next();
  366. String index1=sline.next();
  367. String index2=sline.next();
  368.  
  369. if(index.equals(input))
  370. {
  371. System.out.println(": : : : : : : : : : : : : : : : : : : : : : : : : : : : : ");
  372. System.out.println(":\t"+"Index"+"\t"+":"+"\t"+"Price"+"\t"+":"+"\t"+"Quantity"+"\t"+":");
  373. System.out.println(":\t"+index+"\t"+":"+"\t"+index1+"\t"+":"+"\t"+index2+"\t\t"+":" );
  374. System.out.println(": : : : : : : : : : : : : : : : : : : : : : : : : : : : : ");
  375. break;
  376. }
  377. }
  378. }
  379. txt.reset();
  380.  
  381. break;
  382.  
  383. case "3":
  384. System.out.println(": : : : : : : : : : : : : : : : : : : : : : : : : : : : : ");
  385. System.out.println(":\t"+"Index"+"\t"+":"+"\t"+"Price"+"\t"+":"+"\t"+"Quantity"+"\t"+":");
  386.  
  387. while(txt.hasNextLine())
  388. {
  389. String line=txt.nextLine();
  390. Scanner textline= new Scanner(line);
  391. In = textline.next();
  392. In1 = textline.next();
  393. In2 = textline.next();
  394. if(In2.equals("0"))
  395. {
  396.  
  397. }
  398. else
  399. {
  400. System.out.println(":\t"+In+"\t"+":"+"\t"+In1+"\t"+":"+"\t"+In2+"\t\t"+":" );
  401. }
  402. }
  403. System.out.println(": : : : : : : : : : : : : : : : : : : : : : : : : : : : : ");
  404. txt.reset();
  405.  
  406. break;
  407.  
  408. case "4":
  409. System.out.println(": : : : : : : : : : : : : : : : : : : : : : : : : : : : : ");
  410. System.out.println(":\t"+"Index"+"\t"+":"+"\t"+"Price"+"\t"+":"+"\t"+"Quantity"+"\t"+":");
  411.  
  412. while(txt.hasNextLine())
  413. {
  414. String line=txt.nextLine();
  415. Scanner textline= new Scanner(line);
  416. In = textline.next();
  417. In1 = textline.next();
  418. In2 = textline.next();
  419. if(In2.equals("0"))
  420. {
  421. System.out.println(":\t"+In+"\t"+":"+"\t"+In1+"\t"+":"+"\t"+In2+"\t\t"+":" );
  422. }
  423. }
  424. System.out.println(": : : : : : : : : : : : : : : : : : : : : : : : : : : : : ");
  425. txt.reset();
  426. break;
  427.  
  428. case "5":
  429. boolean Adp;
  430. Adp = AdminPAssword();
  431. if(Adp == true)
  432. {
  433. String line , Data ="";
  434. System.out.print ("Enter Index name: ");
  435. String Index = InputSC.next();
  436. System.out.print ("Enter new price for "+Index+":");
  437. String newprice = InputSC.next();
  438.  
  439. while (txt.hasNextLine())
  440. {
  441. line = txt.nextLine();
  442. if(line.equals(" "))
  443. {
  444. /*continue*/
  445. }
  446.  
  447. Scanner lineinput = new Scanner(line);
  448. String Index1;
  449. Index1 = lineinput.next();
  450.  
  451. if(Index.equals(Index1))
  452. {
  453. String oldprice = lineinput.next();
  454. line = line.replace (oldprice,newprice);
  455. }
  456. Data = Data + line+ "\n";
  457. }
  458. try (BufferedWriter bw = new BufferedWriter(new FileWriter("src\\stock\\market\\project\\Stock.txt")))
  459. {
  460. bw.append(Data);
  461. }
  462. }
  463. txt.reset();
  464.  
  465. break;
  466.  
  467. case "6":
  468. Loop = false;
  469. break;
  470.  
  471. default:
  472. System.out.print("Wrong Operation!!");
  473. }
  474. if(Loop == false)
  475. {
  476. System.out.println("");
  477. System.out.println(": : : : : : : : : : : : : : ");
  478. System.out.println(": : ");
  479. System.out.println(": MAIN MENU :");
  480. System.out.println(": : ");
  481. System.out.println(": [1] Add new Index : ");
  482. System.out.println(": [2] View User Info :");
  483. System.out.println(": [3] View Indices :");
  484. System.out.println(": [4] Delete Index : ");
  485. System.out.println(": [5] Sell Stock :");
  486. System.out.println(": [6] Buy Stock :");
  487. System.out.println(": [7] Exit :");
  488. System.out.println(": : ");
  489. System.out.println(": : : : : : : : : : : : : : ");
  490. }
  491. else
  492. {
  493. System.out.println("");
  494. System.out.println(": : : : : : : : : : : : : : ");
  495. System.out.println(": : ");
  496. System.out.println(": INDICES MENU :");
  497. System.out.println(": :");
  498. System.out.println(": [1] View ALL :");
  499. System.out.println(": [2] Search Index :");
  500. System.out.println(": [3] View Available : ");
  501. System.out.println(": [4] View Out of Stock : ");
  502. System.out.println(": [5] Edit Price : ");
  503. System.out.println(": [6] Back :");
  504. System.out.println(": : ");
  505. System.out.println(": : : : : : : : : : : : : : ");
  506. }
  507.  
  508.  
  509.  
  510. }
  511. }
  512.  
  513. private static void DeleteIndex() throws IOException
  514. {
  515.  
  516. Scanner Dsc;
  517. Dsc = new Scanner (new FileReader("src\\stock\\market\\project\\Stock.txt"));
  518. String line , Data ="";
  519. System.out.print ("Enter Index name: ");
  520. String Index = InputSC.next();
  521. while (Dsc.hasNextLine())
  522. {
  523. line = Dsc.nextLine();
  524. if(line.equals(" "))
  525. {
  526. /*continue*/
  527. }
  528. Scanner lineinput = new Scanner(line);
  529. String Index1;
  530. Index1 = lineinput.next();
  531. if(Index.equals(Index1))
  532. {
  533. /*continue*/
  534. }
  535. else
  536. {
  537. Data = Data + line+ "\n";
  538. }
  539.  
  540. }
  541. Dsc.close();
  542.  
  543. try (BufferedWriter bw = new BufferedWriter(new FileWriter("src\\stock\\market\\project\\Stock.txt"))) {
  544. bw.append(Data);
  545. }
  546.  
  547. }
  548.  
  549. private static void BuyStock() throws IOException
  550. {
  551. Boolean Loop = true , Loop2 = true;
  552.  
  553. Double Credit = 0.0 , Price = 0.0 , TPrice = 0.0, VAT ,Ofees , Comm , NDebit ;
  554. Integer Price1 ;
  555. String Amount , Data1 = "" ;
  556. while(Loop == true)
  557. {
  558. boolean Loop1 = true ;
  559. Scanner Dsc = new Scanner (new FileReader("src\\stock\\market\\project\\Stock.txt"));
  560. Scanner Usc = new Scanner (new FileReader("src\\stock\\market\\project\\UserFiles"));
  561. String line , Data ="" , Data2 = "", Data3 = "";
  562. System.out.print ("Enter Index name: ");
  563. String Index = InputSC.next();
  564. System.out.print ("Enter Buy Amount:");
  565. String NewAmount = InputSC.next();
  566.  
  567.  
  568. while (Dsc.hasNextLine())
  569. {
  570. line = Dsc.nextLine();
  571. if(line.equals(" "))
  572. {
  573. /*continue*/
  574. }
  575. Scanner lineinput = new Scanner(line);
  576. String Index1 = lineinput.next();
  577. String Index2 = lineinput.next();
  578. String Index3 = lineinput.next();
  579. while(Usc.hasNextLine() && Index.equals(Index1))
  580. {
  581. String line2=Usc.nextLine();
  582. if(line2.equals(" "))
  583. {
  584. /*continue*/
  585. }
  586.  
  587. {
  588. Scanner lineinput1 = new Scanner(line2);
  589. String Index11 = lineinput1.next();
  590. String Index22 = lineinput1.next();
  591. if(Index11.equals("Credit"))
  592. {
  593. Credit = Double.parseDouble(Index22);
  594. Double Credit1 = Credit;
  595. Price = Double.parseDouble(NewAmount) * Double.parseDouble(Index2);
  596. Credit1 = Credit1 - Price;
  597. line2 = line2.replace(String.valueOf(Credit),String.valueOf(Credit1));
  598. Data3 = Data3 + line2 + "\n";
  599. }
  600. else
  601. {
  602. Data3 = Data3 + line2 + "\n";
  603. }
  604. }
  605.  
  606. }
  607.  
  608.  
  609. if(Index.equals(Index1) && Credit < Price )
  610. {
  611. System.out.println ("Insuficient Balance");
  612. System.out.print ("Plz Try again \n");
  613. Data = Data +line+ "\n";
  614.  
  615. continue;
  616. }
  617. if(Integer.parseInt(NewAmount)> Integer.parseInt(Index3)&& Index.equals(Index1))
  618. {
  619. if("0".equals(Index3))
  620. {
  621. System.out.println ("This Index is Out of Stock");
  622. System.out.print ("Plz Try again \n");
  623. }
  624. else
  625. {
  626. System.out.println ("Buy amount can not excide Base amount");
  627. System.out.print ("Plz Try again \n");
  628. Data = Data +line+ "\n";
  629. continue;
  630. }
  631. }
  632. if(Index.equals(Index1) && !"0".equals(Index3))
  633. {
  634. if(Credit >=Price && Loop2 == true)
  635. {
  636. DecimalFormat Df3 = new DecimalFormat(".##");
  637. double PriceIn = 0.0;
  638. PriceIn = Price + (Price * 0.0025) + (Price * 0.0003) + (Price * 0.0001);
  639. String OldAmount = Index3;
  640. Amount = NewAmount;
  641. NewAmount = String.valueOf(Integer.parseInt(OldAmount) - Integer.parseInt(NewAmount));
  642. line = line.replace (OldAmount,NewAmount);
  643. Price1 = Integer.parseInt(Amount) * Integer.parseInt(Index2) ;
  644. Data = Data +line+ "\n";
  645. Data1 = Data1+":\t"+Index+"\t\t->\t"+Amount+"\t\t->\t"+Index2+"\t\t->\t"+Price+"\t\t :"+"\n";
  646. Data2 =Index + " " + Index2 + " " + Amount + " " + Df3.format(PriceIn) + " Buy" + " Available" + "\n";
  647. TPrice = Price + TPrice;
  648. Loop2 = false;
  649. }
  650. else
  651. {
  652. Data = Data +line+ "\n";
  653. }
  654.  
  655. }
  656. else
  657. {
  658. Data = Data +line+ "\n";
  659. }
  660.  
  661. }
  662. Dsc.close();
  663.  
  664. if(Loop2 == false)
  665. {
  666. try (BufferedWriter bw = new BufferedWriter(new FileWriter("src\\stock\\market\\project\\Stock.txt")))
  667. {
  668. bw.append(Data);
  669. }
  670.  
  671. try (BufferedWriter bw1 = new BufferedWriter(new FileWriter("src\\stock\\market\\project\\UserFiles")))
  672. {
  673. bw1.append(Data3);
  674. }
  675.  
  676. try (BufferedWriter bw2 = new BufferedWriter(new FileWriter("src\\stock\\market\\project\\UserFiles", true)))
  677. {
  678. bw2.append(Data2);
  679. }
  680. }
  681. Dsc.reset();
  682. Usc.reset();
  683. Loop2 = true;
  684. System.out.print("Would you like to Buy more [Y] [N] :");
  685. String YNloop;
  686. YNloop = InputSC.next();
  687. if("N".equals(YNloop) || "n".equals(YNloop) )
  688. {
  689. Loop = false;
  690. }
  691.  
  692.  
  693. }
  694. DecimalFormat Df3 = new DecimalFormat(".##");
  695. Comm = TPrice * 0.0025;
  696. VAT = TPrice * 0.0003;
  697. Ofees = TPrice * 0.0001;
  698. NDebit = TPrice + Comm + VAT + Ofees;
  699. System.out.println("RECIEPT");
  700. System.out.println(": : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : :");
  701. System.out.println(":\t"+"Issue Code"+"\t:\t"+"Quantity"+"\t:\t"+"Unit Price"+"\t:\t"+"Extension"+"\t :");
  702. System.out.print(Data1);
  703. System.out.println(": \t\t\t\t\t\t\t\t"+" __________________"+"\t :");
  704. System.out.println(": \t\t \t DEBIT = "+Df3.format(TPrice)+"\t\t :");
  705. System.out.println(":\t\t\t\t\t\t\t\t\t\t\t\t :");
  706. System.out.println(": \t\t \t Commision = "+Df3.format(Comm)+"\t\t :");
  707. System.out.println(": \t\t \t VAT = "+Df3.format(VAT)+"\t\t :");
  708. System.out.println(": \t\t \t SCCP FEES = "+Df3.format(Ofees)+"\t\t :");
  709. System.out.println(": \t\t\t\t\t\t\t\t"+" __________________"+"\t :");
  710. System.out.println(": \t \t\t\t\t\t NET DEBIT = "+Df3.format(NDebit)+"\t\t :");
  711. System.out.println(": : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : :");
  712. }
  713.  
  714. private static void SellStock() throws IOException , NoSuchElementException
  715. {
  716. {
  717. Boolean Loop = true ;
  718.  
  719. Double Credit = 0.0 , Price = 0.0 , STP = 0.0 , TPrice = 0.0, VAT ,Ofees , Comm , NDebit , Stax , GL , Value = 0.0 ;
  720. Integer Price1 = 0;
  721. String Amount , Data1 = "" ;
  722. while(Loop == true)
  723. {
  724. boolean Loop1 = true , Loop2 = true , Loop3 = true;
  725. Scanner Dsc = new Scanner (new FileReader("src\\stock\\market\\project\\Stock.txt"));
  726. Scanner D1sc = new Scanner (new FileReader("src\\stock\\market\\project\\Stock.txt"));
  727. Scanner Usc = new Scanner (new FileReader("src\\stock\\market\\project\\UserFiles"));
  728. Scanner U1sc = new Scanner (new FileReader("src\\stock\\market\\project\\UserFiles"));
  729. String line , line1 , Data ="" , Data2 = "", Data3 = "";
  730. System.out.print ("Enter Index name: ");
  731. String Index = InputSC.next();
  732. System.out.print ("Enter Sell Amount:");
  733. String NewAmount = InputSC.next();
  734. while(Usc.hasNextLine())
  735. {
  736. line1 = Usc.nextLine();
  737. if(line1.equals(" "))
  738. {
  739. /*continue*/
  740. }
  741. Scanner lineinput = new Scanner(line1);
  742. String Index11 = lineinput.next();
  743. String Index21 = lineinput.next();
  744. String Index31 = lineinput.next();
  745. String Index41 = lineinput.next();
  746. String Index51 = lineinput.next();
  747. String Index61 = lineinput.next();
  748.  
  749.  
  750. if("Credit".equals(Index11))
  751. {
  752. Credit = Double.parseDouble(Index21);
  753. }
  754. if(Integer.parseInt(Index31) < Integer.parseInt(NewAmount)&& Index.equals(Index11))
  755. {
  756.  
  757. if("Buy".equals(Index51))
  758. {
  759. System.out.println ("Sell amount can not excede Base amount");
  760. System.out.print ("Plz Try again \n");
  761. break;
  762. }
  763. }
  764. if(Index.equals(Index11) && Loop2 == true && Index61.equals("Available") )
  765. {
  766. while(D1sc.hasNextLine())
  767. {
  768. String line11 = D1sc.nextLine();
  769. if(line1.equals(" "))
  770. {
  771. /*continue*/
  772. }
  773. Scanner lineinput1 = new Scanner(line11);
  774. String Index111 = lineinput1.next();
  775. String Index211 = lineinput1.next();
  776. if(Index.equals(Index111))
  777. {
  778. STP = Double.parseDouble(Index211);
  779. }
  780. }
  781. DecimalFormat Df3 = new DecimalFormat(".##");
  782. double PriceIn = 0.0;
  783. Amount = NewAmount;
  784. Price = Double.parseDouble(NewAmount) * STP;
  785. PriceIn = Price + (Price * 0.0025) + (Price * 0.0003) + (Price * 0.0001) + (Price * 0.0055);
  786. Data1 = Data1+":\t"+Index+"\t\t->\t"+Amount+"\t\t->\t"+Index21+"\t\t->\t"+Price+"\t\t :"+"\n";
  787. Data2 =Index + " " + STP + " " + Amount + " " + Df3.format(PriceIn) + " Sell" + " w" + "\n";
  788. TPrice = TPrice + Price;
  789. Loop2 = false;
  790. }
  791.  
  792. }
  793.  
  794. Usc.reset();
  795. String line11;
  796. while(U1sc.hasNextLine() && Loop2 == false)
  797. {
  798.  
  799. line11 = U1sc.nextLine();
  800. if(line11.equals(" "))
  801. {
  802. /*continue*/
  803. }
  804. Scanner lineinput1 = new Scanner(line11);
  805. String Index111 = lineinput1.next();
  806. String Index211 = lineinput1.next();
  807. String Index311 = lineinput1.next();
  808. String Index411 = lineinput1.next();
  809. String Index511 = lineinput1.next();
  810. String Index611 = lineinput1.next();
  811.  
  812. if("Credit".equals(Index111))
  813. {
  814.  
  815. Credit = Credit + Price;
  816. line11 = line11.replace (Index211,String.valueOf(Credit));
  817. Data3 = Data3 + line11 + "\n";
  818.  
  819. }
  820. else if(Index.equals(Index111) && Index611.equals("Available") && Loop3 == true)
  821. {
  822. line11 = line11.replace (Index611,"SoldOut");
  823. Value = Double.parseDouble(Index411);
  824. Data3 = Data3 + line11 + "\n";
  825. Loop3 = false;
  826. }
  827. else
  828. {
  829. Data3 = Data3 + line11 + "\n";
  830. }
  831.  
  832.  
  833.  
  834. }
  835. String line12;
  836. while(Dsc.hasNextLine() && Loop2 == false)
  837. {
  838.  
  839. line12 = Dsc.nextLine();
  840. if(line12.equals(" "))
  841. {
  842. /*continue*/
  843. }
  844. Scanner lineinput = new Scanner(line12);
  845. String Index12 = lineinput.next();
  846. String Index22 = lineinput.next();
  847. String Index32 = lineinput.next();
  848.  
  849. if(Index.equals(Index12))
  850. {
  851.  
  852. String NewAmount12 = String.valueOf(Integer.parseInt(Index32) + Integer.parseInt(NewAmount));
  853. line12 = line12.replace (Index32,NewAmount12);
  854. Data = Data + line12 + "\n";
  855.  
  856. }
  857. else
  858. {
  859. Data = Data + line12 + "\n";
  860. }
  861.  
  862.  
  863.  
  864. }
  865. if(Loop2 == false)
  866. {
  867. try (BufferedWriter bw = new BufferedWriter(new FileWriter("src\\stock\\market\\project\\Stock.txt")))
  868. {
  869. bw.append(Data);
  870.  
  871. }
  872.  
  873. try (BufferedWriter bw1 = new BufferedWriter(new FileWriter("src\\stock\\market\\project\\UserFiles")))
  874. {
  875. bw1.append(Data3);
  876.  
  877. }
  878. try (BufferedWriter bw2 = new BufferedWriter(new FileWriter("src\\stock\\market\\project\\UserFiles", true)))
  879. {
  880. bw2.append(Data2);
  881.  
  882. }
  883. }
  884. Loop1 = true;
  885. System.out.print("Would you like to Buy more [Y] [N] :");
  886. String YNloop;
  887. YNloop = InputSC.next();
  888. if("N".equals(YNloop) || "n".equals(YNloop) )
  889. {
  890. Loop = false;
  891. }
  892.  
  893.  
  894.  
  895. }
  896. DecimalFormat Df3 = new DecimalFormat(".##");
  897. Comm = TPrice * 0.0025;
  898. VAT = TPrice * 0.0003;
  899. Ofees = TPrice * 0.0001;
  900. Stax = TPrice * 0.0055;
  901. NDebit = TPrice + Comm + VAT + Ofees + Stax;
  902. GL = NDebit - Value ;
  903.  
  904. System.out.println("RECIEPT");
  905. System.out.println(": : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : :");
  906. System.out.println(":\t"+"Issue Code"+"\t:\t"+"Quantity"+"\t:\t"+"Unit Price"+"\t:\t"+"Extension"+"\t :");
  907. System.out.print(Data1);
  908. System.out.println(": \t\t\t\t\t\t\t\t"+" __________________"+"\t :");
  909. System.out.println(": \t\t \t Profit = "+Df3.format(TPrice)+"\t\t :");
  910. System.out.println(":\t\t\t\t\t\t\t\t\t\t\t\t :");
  911. System.out.println(": \t\t \t Commision = "+Df3.format(Comm)+"\t\t :");
  912. System.out.println(": \t\t \t VAT = "+Df3.format(VAT)+"\t\t :");
  913. System.out.println(": \t\t \t Sales Tax = "+Df3.format(Stax)+"\t\t :");
  914. System.out.println(": \t\t \t SCCP FEES = "+Df3.format(Ofees)+"\t\t :");
  915. System.out.println(": \t\t\t\t\t\t\t\t"+" __________________"+"\t :");
  916. System.out.println(": \t \t\t\t\t\t NET Profit = "+Df3.format(NDebit)+"\t\t :");
  917. System.out.println(":\t\t\t\t\t\t\t\t\t\t\t\t :");
  918. System.out.println(": \t \t\t\t\t\t NET Gain/Loss = "+Df3.format(GL)+"\t\t :");
  919. System.out.println(":\t\t\t\t\t\t\t\t\t\t\t\t :");
  920. System.out.println(": : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : :");
  921. }
  922.  
  923. }
  924. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement