Question

WRITE A JAVA PROGRAM 1. Assignment Description Write a stock transaction program that calculates a customer's...

WRITE A JAVA PROGRAM

1. Assignment Description

Write a stock transaction program that calculates a customer's profit (or loss) within a certain period of time.

1) First, the program need to get user's name, the stock's code, number of shares and the price he/she purchased the stock, it also asks the user for the price he/she sold the stock later on. The program then compute the following:

  • The amount of money the customer paid for the stock.

  • The amount of commission the customer paid when he/she bought the stock

  • The amount that the cusotmer sold the stock for.

  • The amount of commission the customer paid his broker when he sold the stock

  • The amount of profit or loss that the customer had after selling his stock and paying both buy & sell commissions.

See below for the sample run of the program.

2) Assume for both buying or selling the stock, the agent charges 2% of the total amount from customer. (Hint: this should be declared as a constant)

3) Your program also need to meet the specifications stated below:

  • For the input and output, the exact spacing is not necessary, but what's important is that your program's output looks good and the columns align, i.e. your program's output should be very similar to our sample output. You should consider using escape sequence such as \t, \n to achieve this.

  • Pick and use identifiers which are self-descriptive. One-letter variable names should not be used. As an example, if you were referring to the stock's purchasing price, the variable needed might be declared as double purchasePrice; instead of double x;

  • All ouput price and amounts should be formatted as currency by using DecimalFormat class.

  • Depends on whether the profit is postivie or negative, your program should display different messages on screen, see our two output test cases for this. To achieve this, you will need to use simple if..else statement. Check Lab #2 if you don't know how to do this.  

Note: User input is in bold.

Enter Your Name: John Smith

Enter the stock code you bought: APPL

At what price did you buy it: 176.42

How many shares did you buy: 100

At what price did you sell it: 208.8

******** Stock Transaction Report *********
Customer Name:         John Smith
Stock Code:            APPL

Number of Shares:      100
Purchase Price:        $176.42
Purchase Amt:          $17642.00
Purchase Commission:   $352.84

Sell Price:            $208.80
Sell Amt:              $20880.00
Sell Commission:       $417.60

Profit is:             $2467.56

Test Case 1 Input:

Joe Dow
UBER
45.0
3500
33.06

Test Case 1 Output:

******** Stock Transaction Report *********
Customer Name:          Joe Dow
Stock Code:             UBER

Number of Shares:       3500
Purchase Price:         $45.00
Purchase Amt:           $157500.00
Purchase Commission:    $3150.00

Sell Price:             $33.06
Sell Amt:               $115710.00
Sell Commission:        $2314.20

You lose:               $47254.20

Homework Answers

Answer #1
Thanks for the question.

Below is the code you will be needing  Let me know if you have any doubts or if you need anything to change.

Thank You !!

===========================================================================


import java.util.Scanner;

public class StockTrader {
    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        System.out.print("Enter Your Name: ");
        String name = scanner.nextLine();
        System.out.print("Enter the stock code you bought: ");
        String code = scanner.nextLine();
        System.out.print("At what price did you buy it: ");
        double buyingPrice = scanner.nextDouble();
        System.out.print("How many shares did you buy: ");
        int shares = scanner.nextInt();
        System.out.print("At what price did you sell it: ");
        double sellingPrice = scanner.nextDouble();

        System.out.println("******** Stock Transaction Report *********");
        System.out.println("Customer Name:   " + name);
        System.out.println("Stock Code:      " + code);
        System.out.println();
        System.out.println("Number of Shares:      " + shares);
        System.out.printf("Purchase Price:       $%.2f\n", buyingPrice);
        System.out.printf("Purchase Amt:         $%.2f\n", buyingPrice * shares);
        System.out.printf("Purchase Commission:  $%.2f\n", buyingPrice * shares * 0.02);
        System.out.println();
        System.out.println("Sell Price:           $" + sellingPrice);
        System.out.printf("Sell Amt:             $%.2f\n", sellingPrice * shares);
        System.out.printf("Sell Commission:      $%.2f\n", sellingPrice * shares * 0.02);

        double netCost = buyingPrice * shares * (1.02);
        double netSelling = sellingPrice * shares * (1.02);

        if (netCost < netSelling) {
            System.out.printf("\nProfit is:       $%.2f\n", (netSelling - netCost));
        } else {
            double totalLoss = (buyingPrice - sellingPrice) * shares +
                    sellingPrice * shares * 0.02 + buyingPrice * shares * 0.02;
            System.out.printf("\nLoss is:       $%.2f\n", (totalLoss));
        }

    }
}
Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
in C++ Write a program. The program should prompt the user for the number of shares...
in C++ Write a program. The program should prompt the user for the number of shares purchased, purchase price per share, the commission for the purchase, sale commission paid, and the price the shares were sold at. The program should validate each of these values to ensure they are acceptable (none can be less than zero) and should then pass them to a function called numberfunction.The function should use the following formula to determine the profit: Profit = ((number of...
Write a complete Java program which prompts the user of the program to input his/her first...
Write a complete Java program which prompts the user of the program to input his/her first name, then prompts the user for the middle initial and finally prompts the user for the last name. As indicated, there are three prompts to the user. The program should output the user’s name with the first name first, followed by the middle initial, and the last name last, all on one line (with appropriate spacing). If you could also pinpoint exactly where to...
This is a Java program Program Description You work for a local cell phone company and...
This is a Java program Program Description You work for a local cell phone company and have been asked to write a program to calculate the price of a cell phone data plan being purchased by a customer. The program should do the following tasks: Display a menu of the data plans that are available to be purchased. Read in the user’s selection from the menu.  Input Validation: If the user enters an invalid option, the program should display an error...
**JAVA LANGUAGE** Write a program that models an employee. An employee has an employee number, a...
**JAVA LANGUAGE** Write a program that models an employee. An employee has an employee number, a name, an address, and a hire date. A name consists of a first name and a last name. An address consists of a street, a city, a state (2 characters), and a 5-digit zip code. A date consists of an integer month, day and year. All fields are required to be non-blank. The Date fields should be reasonably valid values (ex. month 1-12, day...
JAVA ASSIGNMENT 1. Write program that opens the file and process its contents. Each lines in...
JAVA ASSIGNMENT 1. Write program that opens the file and process its contents. Each lines in the file contains seven numbers,which are the sales number for one week. The numbers are separated by comma.The following line is an example from the file 2541.36,2965.88,1965.32,1845.23,7021.11,9652.74,1469.36. The program should display the following: . The total sales for each week . The average daily sales for each week . The total sales for all of the weeks .The average weekly sales .The week number...
QUESTION ONE Mr D. Hamabwe places K100 000 into a margin account to take a long...
QUESTION ONE Mr D. Hamabwe places K100 000 into a margin account to take a long position in a stock with a price of K200. If the initial margin requirement is 80%, how many shares can he purchase on margin?                                            What amount in Kwacha will he borrow in this margin transaction?                                                                       He will receive a margin call if the margin rate drops below 35%. Below what price will you receive a margin call?                                            ...
Problem 1 (Defining products and Creating a Menu) Write a program called a2_p1.py that asks a...
Problem 1 (Defining products and Creating a Menu) Write a program called a2_p1.py that asks a shop owner for product information and creates a menu system that allows customers to purchase multiple products of varying quantities. The program should start by asking the shop owner’s name (string) and company name (string). Next it should ask for three (3) products (strings), their prices (int – not ideal, but for now we will keep it this way), and the number of products...
1. Martin Corp. stock has a bid price of $38.10 and an ask price of $38.35....
1. Martin Corp. stock has a bid price of $38.10 and an ask price of $38.35. Assume there is a $19 brokerage commission per trade. What is your round-trip transaction cost if you buy 100 shares and then immediately sell 100 shares? A) $44 B) $63 C) $13 D) $25 E) $6 1 points 2) Suppose a security has a bid price of $39.50 and an ask price of $39.80. At what price can you sell the security to a...
Finish the CustomerAccountTransactions program that reads customer accounts receivable data from a file and then applies...
Finish the CustomerAccountTransactions program that reads customer accounts receivable data from a file and then applies a series of transactions to the accounts. Its main() method uses the CustomerAccounts class to manage a collection of CustomerAccount objects: reading customer accounts data & transactions, and obtaining a String showing the customer accounts data after the operations are complete. You will need to complete the readCustomerAccounts () and applyTransactions() methods in the CustomerAccounts class. First, please fill in your name in the...
You are to write a C++ program to produce an inventory report for a local company....
You are to write a C++ program to produce an inventory report for a local company. Your input will be item name, item number, quantity, price per item, safe stock value. The following shows which columns the input will be in: item name             item number         quantity                  price                      safe stock 20 chars                 5 char                     3 char                      6 chars                 3 chars Output will be as follows: item number         item name    quantity   price     price*quantity   %ofStock    flag You will put a symbol in the...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT