Forex Broker

Report a typo

Suppose you are building a Forex Broker application. Forex broker has two commands which are buy and sell. The user gives an input sequence which is the amount of money (Option) to be bought and sold. If the user gives a positive number it is to be bought. If the user gives a negative number, that amount must be sold.

Use the following guidelines:

  • Don't change the provided code.

  • If the user amount is X>0, the X amount must be bought. The buy command must print X was bought.

  • If the user amount is X<0, the X amount must be sold. The sell command must print X was sold.

  • The user will give only three inputs.

Sample Input 1:

5 -8 10

Sample Output 1:

5 was bought
-8 was sold
10 was bought
Write a program in Java 17
import java.util.Scanner;

public class Main {
public static void main(String[] args) {
int[] amountList = new int[3];

Scanner scanner = new Scanner(System.in);
for (int i = 0; i < 3; i++) {
amountList[i] = scanner.nextInt();
}

Broker broker = new Broker();
for (int i = 0; i < 3; i++) {
Option option = new Option(amountList[i]);
Command command;
if (amountList[i] > 0) {
/* write your code here */
} else {
/* write your code here */
}
broker.setCommand(command);
broker.executeCommand();
}
}
}

class Option {
private int amount;

Option(int amount) {
this.amount = amount;
}

void buy() {
System.out.println(amount + " was bought");
}
___

Create a free account to access the full topic