Md_Nabeel

Stock Exchange

Sep 30th, 2024
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.26 KB | Gaming | 0 0
  1. import java.util.*;
  2. public class HelloWorld
  3. {
  4.     public static void main(String[] args)
  5.     {
  6.         Scanner in = new Scanner(System.in);
  7.         int nw = 10000;
  8.         System.out.println("\tWelcome to Wall Street's\n\t\tStock Exchange");
  9.         String company[] = {"Apple", "Tesla", "Microsoft", "Google","SpaceX","Amazon","Meta","Twitter","Snapchat","Neuralink"};
  10.         int stockp[] = {100,90,80,70,60,50,80,30,30,20};
  11.         while (nw>0)
  12.         {
  13.             for(int i=0; i<10; i++)
  14.             {
  15.             int changev = (int)(Math.random()*100)+1;
  16.             int changes = (int)(Math.random()*3)+1;
  17.             if (changes == 1)
  18.             stockp[i] += changev;
  19.             else if (changes == 2)
  20.             stockp[i] -= changev;
  21.             else
  22.             continue;
  23.             }
  24.             for(int i=0; i<10; i++)
  25.             {
  26.                 int j = i+1;
  27.                 System.out.println(j + ". " + company[i]+":"+"\t"+stockp[i]);
  28.             }
  29.             System.out.println("Enter the sl.no. of Company: ");
  30.             int sn = in.nextInt();
  31.             int p = stockp[sn-1];
  32.             System.out.println("Enter the no. of stocks bought:");
  33.             int sb = in.nextInt();
  34.             nw -= (p*sb);
  35.             System.out.println("Your new Net Worth: " + nw);
  36.             for(int i=0; i<10; i++)
  37.             {
  38.             int changev = (int)(Math.random()*100)+1;
  39.             int changes = (int)(Math.random()*3)+1;
  40.             if (changes == 1)
  41.             stockp[i] += changev;
  42.             else if (changes == 2)
  43.             stockp[i] -= changev;
  44.             else
  45.             continue;
  46.             }
  47.             for(int i=0; i<10; i++)
  48.             {
  49.                 int j = i+1;
  50.                 System.out.println(j + ". " + company[i]+":"+"\t"+stockp[i]);
  51.             }
  52.             int ch = stockp[sn-1]-p;
  53.             nw += (p+ch)*sb;
  54.             System.out.println("Your new Net Worth: " + nw);
  55.             System.out.println();
  56.             System.out.println("Press 1 to exit");
  57.             int d = in.nextInt();
  58.             System.out.println();
  59.             if (d==1)
  60.             System.exit(0);
  61.             else
  62.             continue;
  63.         }
  64.         System.out.println("You are BANKRUPT!!");
  65.     }
  66. }
Add Comment
Please, Sign In to add comment