Question
Having issues getting this code to produce the output show at the end. Code: import java.util.Scanner; import java.util.Calendar; public class J002 { /** * Method
Having issues getting this code to produce the output show at the end.
Code:
import java.util.Scanner;
import java.util.Calendar;
public class J002
{
/**
* Method Purpuse:
*
*/
final static int Attempts= 2;
final static String Login = "Buffet2011";
final static String Password = "Rank1Bill2008";
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
String userName = "";
String password = "";
String customerName = "";
int shares = 0;
int noOfStocks = 0;
int attempts = 0;
double sharePrice = 0.0;
double stockCost = 0.0;
double commission = 0.0;
double totalCost = 0.0;
double onlineFee = 0.0;
double totalStockCost = 0.0;
double totalCommission = 0.0;
double totalOnlineFees = 0.0;
char onlineTrade = ' ';
char brokerAssisted = ' ';
char another = 'Y';
Calendar dateTime = Calendar.getInstance(); //get current date
String date = String.format("%1$tB %1$td, %1$tY", dateTime);
//print 1
System.out.printf("YEE-TRADE,INC.-The Wild West of Electronic Trading " +
"%nWelcome to Yee-Trade's purchase calculator.");
//prompt 1
System.out.printf("%nEnter your name?");
customerName = input.nextLine();
while(attempts < Attempts)
{
System.out.printf("%nEnter your log-in: ");
String login = input.nextLine();
System.out.printf("%nwhat is your password: ");
String Password = input.nextLine();
attempts++;
if(Login.equals(login) && Password.equals(password))
{
break;
}
else {
if(Attempts-attempts > 0)
System.out.printf(" Invalid log-in or password! %d attempts left",Attempts-attempts);
else
System.out.printf("%nNo more attempts left! Contact technical support at"
+"%n1-800-111-2222. ");
}
/**
* begin PA code
*/
do {
System.out.printf("%nDo you want to calculate your stock purchases? Enter 'Y' or 'N' to exit: ");
another = input.nextLine().charAt(0);
}
while (Character.toUpperCase(another) == 'Y');
{
// prompt 3
System.out.printf("%nHow many shares did you purchase?");
shares = input.nextInt();
//prompt 4
System.out.printf("%nWhat is the price per share?");
sharePrice = input.nextDouble();
input.nextLine();
// calculations 2, 3, 4
stockCost = shares * sharePrice;
totalStockCost += stockCost;
totalCost = totalCost + stockCost;
//prompt 5
System.out.printf("%nIs this an online trade? Enter 'Y' or 'N'");
onlineTrade = input.nextLine().charAt(0);
if (Character.toUpperCase(onlineTrade) == 'Y')
{
// calculations 5,6
onlineFee = 5.95;
totalOnlineFees += onlineFee;
totalCost += onlineFee;
//print 2
System.out.printf("%nYEE-TRADE,INC." +
"%nFOR %s." +
"%nAS OF %s.%n" +
"%nTOTAL STOCK COST: %.2f" +
"%nTOTAL ONLINE FEES: %.2f" +
"%nTOTAL COMMISSIONS: %.2f" +
"%nTOTAL COST: %.2f%n", customerName, date, totalStockCost, totalOnlineFees, totalCommission,
totalCost);
} // end if "onlinetrade"
else // 1st else
{
//prompt 6
System.out.printf("%nIs this a broker assisted trade? Enter 'Y' or 'N':");
brokerAssisted = input.nextLine().charAt(0);
if (Character.toUpperCase(brokerAssisted) == 'Y')
{
//calculations 7,8,9
commission = stockCost * .02;
totalCommission = totalCommission + commission;
totalCost = totalCost + commission;
// calculations 5,6
onlineFee = 0;
totalOnlineFees += onlineFee;
totalCost += onlineFee;
//print 2
System.out.printf("%nYEE-TRADE,INC." +
"%nFOR %s." +
"%nAS OF %s.%n" +
"%nTOTAL STOCK COST: %.2f" +
"%nTOTAL ONLINE FEES: %.2f" +
"%nTOTAL COMMISSIONS: %.2f" +
"%nTOTAL COST: %.2f%n", customerName, date, totalStockCost, totalOnlineFees, totalCommission,
totalCost);
} //end if "brokerAssisted"
else // 2nd else
{
//print 3
System.out.printf("%nInvalid Trade Type!");
// calculations 10, 11, 12
noOfStocks = noOfStocks - 1;
totalStockCost = totalStockCost - stockCost;
totalCost = totalCost - stockCost;
} //end 2nd else
} //end 1st else
//prompt 7
System.out.printf("%nEnter 'Y' to calculate the cost of another stock purchase or 'N' to exit:");
another = input.nextLine().charAt(0);
} //end if
} //end while attempts
System.out.printf("%nThank you for using Yee-Trade's stock purchase calculator!%n");
input.close();
System.exit(0);
} //end class
} // end main
Output:
***OUTPUT WITH 2 UNSUCCESSFUL LOG-IN ATTEMPTS***
YEE-TRADE, INC. - The Wild West of Electronic Trading
Welcome to Yee-Trade's stock purchase calculator.
What is your name? Hawkeye Pierce
Enter your log-in: Biff2008
Enter your password: Buffy2011
Invalid log-in or password! 1 attempt left.
Enter your log-in: LastChance
Enter your password: BetterWork
No more attempts left! Contact technical support at 1-800-111-2222.
Thank you for using Yee-Trade's stock purchase calculator!
***OUTPUT WITH CORRECT LOG-IN***
YEE-TRADE, INC. - The Wild West of Electronic Trading
Welcome to Yee-Trade's stock purchase calculator.
What is your name? Hawkeye Pierce
Enter your log-in: Buffett2011
Enter your password: Rank1Bill2008
Invalid log-in or password! 1 attempt left.
Enter your log-in: Buffet2011
Enter your password: Rank1Bill2008
Do you want to calculate your stock purchases? Enter 'Y' or 'N' to exit: y
How many shares did you purchase? 1000
*****SAMPLE OUTPUT*****
What is the price per share? 15
Is this an online trade? Enter 'Y' or 'N': y
Enter 'Y' to calculate the cost of another stock purchase or 'N' to exit: y
How many shares did you purchase? 500
What is the price per share? 52
Is this an online trade? Enter 'Y' or 'N': n
Is this a broker assisted trade? Enter 'Y' or 'N': y
Enter 'Y' to calculate the cost of another stock purchase or 'N' to exit: y
How many shares did you purchase? 50
What is the price per share? 52
Is this an online trade? Enter 'Y' or 'N': n
Is this a broker assisted trade? Enter 'Y' or 'N': n
INVALID TRADE TYPE!
Enter 'Y' to calculate the cost of another stock purchase or 'N' to exit: n
YEE-TRADE, INC.
TOTAL COST OF STOCK PURCHASES
FOR Hawkeye Pierce
AS OF OCTOBER 01, 2018
Total Stock Cost: $41,000.00
Total Online Fees: $5.95
Total Commissions: $520.00
TOTAL COST: $41,525.95
Thank you for using Yee-Trade's stock purchase calculator!
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started