Question: The java code for a project was not showing the output with the new instructions (the ones colored in red). here is my base code
The java code for a project was not showing the output with the new instructions (the ones colored in red). here is my base code (scroll down for the instructions):
import java.util.Scanner; import java.util.Calendar;
public class PA2 { /*The customer can calculate the cost of multiple trades, so there can be a combination * of online and broker assisted trades. The customer is prompted for several pieces of * information pertaining to the stock purchase. Calculations for stock cost, online fees, * commissions, their respective totals, and an overall total are performed, then customer * and stock information are displayed. The customer is asked if its an online trade, if so * charge $5.95 for the trade; otherwise, ask if its a broker assisted trade, if so then charge * a 2% brokerage fee. An error massage is displayed when the customer doesnt have legitimate trade. * Calculations made prior to determining the trades legitimacy are reversed. The number of stocks * for which trades are being made is tabulated to control when to print the final output. A thank you * message is displayed before the program terminates. */ public static void main(String[] args) { Scanner input = new Scanner(System.in); Calendar cal = Calendar.getInstance(); String customerName = null; String date = null; String userName = null; String password = null; int shares = 0; int noOfStocks = 0; int userNmAttmpts = 1; Double sharePrice = 0.0; Double stockCost = 0.0; Double commission = 0.0; Double totalCost = 0.0; Double onlineFees = 0.0; Double totalStockCost = 0.0; Double totalCommission = 0.0; Double totalOnlineFees = 0.0; char onlineTrade; char brokerAssisted; char another; System.out.printf("%nYEE-Trade,Inc-The Wild West Of Electronic Trading" +"%nWelcome to Yee Trades stock purchase calculator%n");//Welcome to the programm. System.out.printf("%n%nWhat is your name? "); customerName = input.nextLine();//Captuer a String do { System.out.printf("%nEnter your log-in: "); userName = input.nextLine(); System.out.printf("%nEnter your password: "); password = input.nextLine(); if(userName.equals("Buffet2011") && password.equals("Rank1Bill2008")) { System.out.printf("%nDo you want to calculate your stock purchases?%n Enter 'Y' or 'N'" +" to Exit: "); another = input.next().charAt(0);//Capture a Char while(Character.toUpperCase(another) == 'Y') { noOfStocks += 1;//Add a 1 to noOfStocks //User input. System.out.printf("%nHow many shares did you purchase? "); shares = input.nextInt(); System.out.printf("%nWhat is the price per share? "); sharePrice = input.nextDouble(); //Calculation. stockCost = (shares * sharePrice); totalStockCost += stockCost; totalCost += stockCost; //UserInput for Prompt 5 System.out.printf("%nIs this an online trade? %n" +" Enter 'Y' or 'N': "); onlineTrade = input.next().charAt(0); //If statment for OnlineTrader. if(Character.toUpperCase(onlineTrade) == 'Y') { //Assighn $5.95 to online fee onlineFees = 5.95; //Calculation totalOnlineFees += onlineFees; totalCost += onlineFees; } else//(Character.toUpperCase(onlineTrade) == 'N'); { //UserInput 6 System.out.printf("%nIs this a broker assisted trade?%n" +" Enter 'Y' or 'N': "); brokerAssisted = input.next().charAt(0); //If statment for brokerAssisted if(Character.toUpperCase(brokerAssisted) == 'Y') { //Calculation commission = (stockCost * .02); totalCommission += commission; totalCost += commission; } else { System.out.printf("%nINVALID TRADE TYPE!%n"); //Calculation noOfStocks -= 1; totalStockCost -= stockCost; totalCost -= stockCost; }//END else }//END else //Trying to see if user want to use the program agian. System.out.printf("%nEnter 'Y' to calculate the cost of another stock purchase" +" or 'N' to Exit: "); another = input.next().charAt(0); }//END while if(noOfStocks > 0) { System.out.printf("%n YEE-TRADE, INC.%n" +" TOTAL COST OF STOCK PURCHASES%n" +" FOR %s%n" +" AS OF %tB %



and here is what the output should look like


I have finished it but my output is not correct. please help
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
