Question

In: Computer Science

PROGRAM INSTRUCTIONS: 1. Code an application that asks the customer for a log-in and password. 2....

PROGRAM INSTRUCTIONS:

1. Code an application that asks the customer for a log-in and password. 2. The real log-in is "Buffet2011" and the real password is "Rank1Bill2008". 3. Allow the customer two (2) attempts to type either.

a. Each time the customer enters an invalid log-in or password issue an error message.

b. If the customer fails all two (2) log-in attempts, issue another error message and exit the program.

c. If the log-in is successful, the customer can calculate the cost of multiple trades, so there can be a combination of online and broker assisted trades.

4. Ask the customer if it's an online trade, if so charge $5.95 for the trade; otherwise, ask if it's a broker assisted trade, if so then charge a 2% brokerage fee. If not then print an error message, and let the customer try again. Keep track of the number of stocks for which trades are being made.

5. Logical Control Structures from PA1:

a. Use a while loop to process for multiple stock trades in a given transaction. Use a sentinel controlled loop variable.

b. Use if-else, nested if-else and if structures to figure out

i. whether it is an online trade or broker assisted trade;

ii. when to print the error message "INVALID TRADE TYPE!"

iii. when to print the final output with the total calculations for stock cost, online fees, commissions, and overall cost.

c. The customer can calculate for multiple stock purchases as long as the customer has more purchases to calculate. The calculated stock cost is added to a total for stock cost and the overall total (total cost); the online fee is added to a total for online fees and the overall total; and, the commission is added to a total for commissions and the overall total. Use printf() with format specifiers where needed.

d. Don’t forget to insert the exit statement at the end of main().

e. The prompts, the final output specs, and the sample output show you in what order to place your code. To return from these links press Alt then left arrow.

6. Logical Control Structures for PA2: This program is the same as PA1 EXCEPT:

a. There are additional prompts for the login and password.

b. Both the login and password must be correct to proceed.

c. You’ll use a do-while loop to control the number of attempts.

d. Use an if-else to test the attempts left, so the proper message is displayed for more than 2 attempts left, 1 attempt left and no more attempts left. Embed a switch to test for attempts less than or equal to 1.

e. There are 3 new variables.

7. Program Logic: NO plan for this PA.

a. The prompts tell you what input variables you will need.

b. The output will tell you the type of calculations you will need (if any) and whether you will need to declare additional variables.

c. The output will tell you the order of logic for your code.

8. Work and submit this program on your own (no partner). Name your program as YourLastNameFirstInitialYourSectionNoPA2.

9. Commenting Your Program:

a. In your program, YOU MUST insert a program purpose in the first comment box. The content of that first comment box was shown to you in the Anatomy of a Java Program lecture for chapter 1.

b. Use Javadoc comment boxes beginning with /** and ending with */ for your comment boxes.

c. Insert a Javadoc comment box above your methods explaining what is going on in the method that goes for the main() which is a method.

d. Line comment the import statements and the variables declared at the class level and/or in any method [including main()].

10. Formatting Rules: Refer to the Java Style Guide posted on Blackboard in IS 2033. Always test your output to validate that your program is functioning properly with the correct output and spacing (line advances and spacing after punctuation). The %n can function differently when using separate printf statements versus one printf.

PROMPTS: Code the bold from the prompts below in the printf statements that capture data into your program. Once again, the prompts tell you your input variables.

Welcome Message: Prints before prompt for customer name.

YEE-TRADE, INC. - The Wild West of Electronic Trading

Welcome to Yee-Trade's stock purchase calculator.  

1st Prompt:  

What is your name?  

2nd Prompt: Beginning with this prompt, the majority of the code will be nested in the do-while mentioned in 2c above.  

Enter your log-in:  

3rd Prompt: If the entries from the 2nd and 3rd prompts match the real log-in and password proceed to the 4th prompt else print the error message(s).  

Enter your password:  

Error Message When Log-In & Password Incorrect: One of these error messages will be displayed every time the log-in or password is incorrect. The 9 represents the number of attempts left out of two (2). You’ll accommodate in the code for the possibility of more than 2 attempts.

Invalid log-in or password! 9 attempts left. ? Use when >= 2 attempts left Invalid log-in or password! 9 attempt left. ? Use when 1 attempt left

Error Message When No More Attempts Left: This error message will be displayed when there are no more attempts left, and the program will terminate. This is NOT a forced exit. The code should automatically sequence to the exit statement at the end of main().  

No more attempts left! Contact tech nical support at 1-800-111-2222.  

4th Prompt: This prompt will display after the customer enters the correct log-in and password within the allotted 2 attempts. The value captured from this prompt is the loop-control variable for the sentinel-while loop mentioned in 1a of the Program Instructions section above.  

Do you want to calculate your stock purchases? Enter 'Y' or 'N' to exit: If the answer is anything other than ‘Y’, the while loop is by-passed and this message is displayed: Thank you for using Yee-Trade's stock purchase calculator!

5th Prompt: Prompts 5 through 9 will be in a sentinel-controlled while loop.  

How many shares did you purchase?  

6th Prompt:  

What is the price per share?  

7th Prompt: If the answer to this prompt is 'Y' add a 5.95 online trading fee to the stock cost then go to the 9th prompt, else go to the 8th prompt. Also, refer to 1c for additional calculation instructions.

Is this an online trade? Enter 'Y' or 'N':  

8th Prompt: This prompt will display only when the answer to the 7th prompt is 'N'. If the answer to this prompt is 'Y', calculate the commission by assessing a 2% brokerage fee on the stock cost then go to the 9th prompt, else proceed to the error message.  

Is this a broker assisted trade? Enter 'Y' or 'N':

Error Message When Trade is Neither Online or Broker Assisted: If the answer is 'N', print this error message then proceed to the 9th prompt.

"INVALID TRADE TYPE!"  

9th Prompt: If the answer is 'Y' then you'll go back to the 5th prompt. This is the same loop-control variable in prompt 4.

Enter 'Y' to calculate the cost of another stock purchase or ‘N’ to exit:  

If the answer is anything other than ‘Y’, the while loop is exited, the final output is displayed along with this message:

Thank you for using Yee-Trade's stock purchase calculator!

Original Code:

/**
* @(#)004PA1.java
* @author
* version 1.00 2020/09/23
*
* PROGRAM PURPOSE: This program controls whether
* a customer can calculate the cost of
* their stock purchase
*/
import java.util.Scanner;
import java.util.Calendar;

public class 004PA1
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
Calendar dateTime = Calendar.getInstance();
String date = String.format("%1$TB %1$TD, %1$TY", dateTime);
  
String customerName = null;
int shares = 0, noOfStocks = 0;
double sharePrice = 0.0,
stockCost = 0.0,
commission = 0.0,
totalCost = 0.0,
onlineFee = 0.0,
totalStockCost = 0.0,
totalCommissions = 0.0,
totalOnlineFees = 0.0;
char onlineTrade = ' ',
brokerAssisted = ' ',
another = 'N';
  
System.out.printf("%nYEE-TRADE, INC. - The Wild West of Electronic Trading%n"
+ "%nWelcome to Yee-Trade\'s stock purchase calculator. %n");
System.out.printf("%nWhat is your name? ");
customerName = input.nextLine();
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')
{
noOfStocks = noOfStocks + 1;
  
System.out.printf("%nHow many shares did you purchase? ");
shares = input.nextInt();
  
System.out.printf("%nWhat is the price per share? ");
sharePrice = input.nextDouble();
stockCost = shares * sharePrice;
totalStockCost += stockCost;
totalCost += stockCost;
  
input.nextLine();
  
System.out.printf("%nIs this an online trade? "
+ "Enter \'Y\' or \'N\': ");
onlineTrade = input.nextLine().charAt(0);
  
if(Character.toUpperCase(onlineTrade) == 'Y')
{
onlineFee = 5.95;
totalOnlineFees += onlineFee;
totalCost += onlineFee;
}
else
{
System.out.printf("%nIs this a broker assisted trade? "
+ "Enter \'Y\' or \'N\': ");
brokerAssisted = input.nextLine().charAt(0);
  
if(Character.toUpperCase(brokerAssisted) == 'Y')
{
commission = stockCost * .02;
totalCommissions = totalCommissions + commission;
totalCost = totalCost + commission;
}
else
{
System.out.printf("%nINVALID TRADE TYPE!");

noOfStocks = noOfStocks - 1;
totalStockCost = totalStockCost - stockCost;
totalCost = totalCost - stockCost;   
}   
}
System.out.printf("%nEnter 'Y' to calculate the cost of another stock purchase "
+ "or 'N' to exit: ");
another = input.nextLine().charAt(0);
}
if (noOfStocks > 0)
{
System.out.printf("%nYEE-TRADE,INC."
+ "%nTOTAL COST OF STOCK PURCHASES "
+ "%nFOR " + customerName
+ "%nAS OF " + date
+ "%nTotal Stock Cost: $" + totalStockCost
+ "%nTotal Online Fees: $" + totalOnlineFees
+ "%nTotal Commissions: $" +totalCommissions
+ "%nTOTAL COST: $" + totalCost);
}
System.out.printf("%nThank you for using Yee-Trade's stock purchase calculator!");
noOfStocks = 0;
  
System.exit(0);

}
}

Solutions

Expert Solution

Here you go:

/**

* @(#)004PA1.java

* @author

* version 1.00 2020/09/23

*

* PROGRAM PURPOSE: This program controls whether

* a customer can calculate the cost of

* their stock purchase

*/

import java.util.Scanner;

import java.util.Calendar;

public class Main

{

public static void main(String[] args)

{

Scanner input = new Scanner(System.in);

Calendar dateTime = Calendar.getInstance();

String date = String.format("%1$TB %1$TD, %1$TY", dateTime);

String customerName = null;

int shares = 0, noOfStocks = 0;

double sharePrice = 0.0,

stockCost = 0.0,

commission = 0.0,

totalCost = 0.0,

onlineFee = 0.0,

totalStockCost = 0.0,

totalCommissions = 0.0,

totalOnlineFees = 0.0;

char onlineTrade = ' ',

brokerAssisted = ' ',

another = 'N';

System.out.printf("%nYEE-TRADE, INC. - The Wild West of Electronic Trading%n"

+ "%nWelcome to Yee-Trade\'s stock purchase calculator. %n");

System.out.printf("%nWhat is your name? ");

customerName = input.nextLine();

int count=0, limit=2;

boolean valid=false;

do{

int rem=limit-count;

String newlog=null;

String newpass=null;

String login="Buffet2011";

String password="Rank1Bill2008";

System.out.println("Enter your log-in: ");

newlog = input.nextLine();

System.out.println("Enter your password: ");

newpass = input.nextLine();

if((newlog.equals(login)) && newpass.equals(password)){

valid=false;

break;

}

else if(count==2){

System.out.println("No more attempts left! Contact tech nical support at 1-800-111-2222.");

return;

}

else {

valid=true;

System.out.println("Invalid log-in or password! "+rem+" attempts left");

}

count++;

}

while(valid);

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')

{

noOfStocks = noOfStocks + 1;

System.out.printf("%nHow many shares did you purchase? ");

shares = input.nextInt();

System.out.printf("%nWhat is the price per share? ");

sharePrice = input.nextDouble();

stockCost = shares * sharePrice;

totalStockCost += stockCost;

totalCost += stockCost;

input.nextLine();

System.out.printf("%nIs this an online trade? "

+ "Enter \'Y\' or \'N\': ");

onlineTrade = input.nextLine().charAt(0);

if(Character.toUpperCase(onlineTrade) == 'Y')

{

onlineFee = 5.95;

totalOnlineFees += onlineFee;

totalCost += onlineFee;

}

else{

{

System.out.printf("%nIs this a broker assisted trade? "

+ "Enter \'Y\' or \'N\': ");

brokerAssisted = input.nextLine().charAt(0);

}

if(Character.toUpperCase(brokerAssisted) == 'Y')

{

commission = stockCost * .02;

totalCommissions = totalCommissions + commission;

totalCost = totalCost + commission;

}

else

{

System.out.printf("%nINVALID TRADE TYPE!");

noOfStocks = noOfStocks - 1;

totalStockCost = totalStockCost - stockCost;

totalCost = totalCost - stockCost;

}

}

System.out.printf("%nEnter 'Y' to calculate the cost of another stock purchase "

+ "or 'N' to exit: ");

another = input.nextLine().charAt(0);

}

if (noOfStocks > 0)

{

System.out.printf("%nYEE-TRADE,INC."

+ "%nTOTAL COST OF STOCK PURCHASES "

+ "%nFOR " + customerName

+ "%nAS OF " + date

+ "%nTotal Stock Cost: $" + totalStockCost

+ "%nTotal Online Fees: $" + totalOnlineFees

+ "%nTotal Commissions: $" +totalCommissions

+ "%nTOTAL COST: $" + totalCost);

}

System.out.printf("%nThank you for using Yee-Trade's stock purchase calculator!");

noOfStocks = 0;

System.exit(0);

}

}

Check the image below for code structure and output:

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

A sign of thumbs up would be appreciated.


Related Solutions

Create a Java application called ValidatePassword to validate a user’s password. Write a program that asks...
Create a Java application called ValidatePassword to validate a user’s password. Write a program that asks for a password, then asks again to confirm it. If the passwords don’t match or the rules are not fulfilled, prompt again. Your program should include a method that checks whether a password is valid. From that method, call a different method to validate the uppercase, lowercase, and digit requirements for a valid password. Your program should contain at least four methods in addition...
C# Create an application that asks the user to enter their new password. The password must...
C# Create an application that asks the user to enter their new password. The password must be at least 6 characters long. Develop a custom exception handling case that checks for the password length. (hint: use " .Length " built-in method). If the new password is less than 6 characters long the custom exception should output an error message.
CODE IN PYTHON 1. Write a program that asks the user for the number of slices...
CODE IN PYTHON 1. Write a program that asks the user for the number of slices of pizza they want to order and displays the total number of dollar bills they owe given pizza costs 3 dollars a slice.  Note: You may print the value an integer value. 2. Assume that y, a and b have already been defined, display the value of x: x =   ya+b    3. The variable start_tees refers to the number of UD T-shirts at the start...
Instructions Write a Java program that asks the user t enter five test scores. The program...
Instructions Write a Java program that asks the user t enter five test scores. The program should display a letter grade for each score and the average test score. Write the following methods in the program: * calcAverage -- This method should accept five test scores as arguments and return the average of the scores. * determineGrade -- This method should accept a test score as an argument and return a letter grade for the score, based on the following...
Q-1) a client wants to log into a server by using username and password first name...
Q-1) a client wants to log into a server by using username and password first name a suitable http mechanism like cookie or session to make it happen and then make a signal flow diagram to show that how does it happen
Class Instructions You will create a password verification program using C-strings and character testing. The user...
Class Instructions You will create a password verification program using C-strings and character testing. The user will enter a password as a C-string. (Character array). You must test that the password contains at least: One lowercase letter One uppercase letter One number (0-9) The password can contain no spaces You are to add one more requirement to the password. I need help in setting this program up. #include <iostream> #include <cctype> using namespace std; int main() { char input; cout...
I need to complete this C++ program. The instructions are in the comments inside the code...
I need to complete this C++ program. The instructions are in the comments inside the code below: ------------------------------------------------------------------------- Original string is: this is a secret! Encypted string is: uijt!jt!b!tfdsfu" Decrypted string is: this is a secret! //Encoding program //Pre-_____? //other necessary stuff here int main() { //create a string to encrypt using a char array cout<< "Original string is: "<<string<<endl; encrypt(string); cout<< "Encrypted string is: "<<string<<endl; decrypt(string); cout<<"Decrypted string is: "<<string<<endl; return 0; } void encrypt(char e[]) { //Write implementation...
2. Write a Java program to read a string (a password)from the user and then   check...
2. Write a Java program to read a string (a password)from the user and then   check that the password conforms to the corporate password policy.   The policy is:   1) the password must be at least 8 characters   2) the password must contain at least two upper case letters   3) the password must contain at least one digit   4) the password cannot begin with a digit   Use a for loop to step through the string.   Output “Password OK” if the password...
Write a Java program which asks customer name, id, address and other personal information, there are...
Write a Java program which asks customer name, id, address and other personal information, there are two types of customers, walk-in and credit card. The rates of items are different for both type of customers. System also asks for customer type. Depending upon customer type, it calculates total payment. A credit-card customer will pay 5 % extra the actual price. Use object-oriented concepts to solve the problem. Define as many items and prices as you want. Example Output: Enter Name...
---- Python CIMP 8A Code Lab 4 Write a program that asks the user to enter...
---- Python CIMP 8A Code Lab 4 Write a program that asks the user to enter 5 test scores. The program will display a letter grade for each test score and an average grade for the test scores entered. The program will write the student name and average test score to a text file (“studentgrades.txt”). Three functions are needed for this program. def letter_grade( test_score) Test Score Letter Grade 90-100 A 80-89 B 70-79 C 60-69 D Below 60 F...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT