Jerry Education 5

Source: Internet
Author: User

Analog banking system withdrawals

System.out.println ("Please enter password:");

for (int i = 1; I <= 4; i++) {

if (i = = 4) {

SYSTEM.OUT.PRINTLN ("The password is wrong, please take the card!" ");

Return

}

int password = Reader.nextint ();

if (password = = 111111) {

System.out.println ("Please enter Amount:");

Break

} else {

System.out.println ("Please enter password:");

}

}

int amount = Reader.nextint ();

while (true) {

if (amount% = = 0 && amount > 0 && Amount < 1000) {

SYSTEM.OUT.PRINTLN ("You have taken out:" + amount + "Yuan");

SYSTEM.OUT.PRINTLN ("Transaction completed, please collect card!") ");

Break

} else {

SYSTEM.OUT.PRINTLN ("The amount you entered is not legal, please re-enter:");

Amount = Reader.nextint ();

Continue

}

}

Find the lowest mobile price in 4 stores

System.out.println ("The price of the first store:");

int a = Reader.nextint ();

System.out.println ("The price of the second store:");

int b = Reader.nextint ();

System.out.println ("The price of the third store:");

int c = Reader.nextint ();

System.out.println ("The price of the fourth store:");

int d = Reader.nextint ();

int min = A;

if (b < min) {

min = b;

}

if (c < min) {

min = c;

}

if (d < min) {

min = D;

}

System.out.println (min);

System.out.println ("Please enter the price of 4 stores");

int Minmoney = 0;

for (int i = 1; i < 5; i++) {

System.out.println ("No." + i + "Home Shop price:");

int money = Reader.nextint ();

if (Money <= 0) {

SYSTEM.OUT.PRINTLN ("Input is not legal, please re-enter!") ");

i--;

Continue

}

if (i = = 1 | | Money < Minmoney) {

Minmoney = money;

}

}

SYSTEM.OUT.PRINTLN ("Lowest price is:" + Minmoney);

Classical Questions: Rabbits (Fibonacci series)

int i;

int m[] = new INT[24];

M[0] = m[1] = 1;

for (i = 0; i < i++) {

if (i = = 0 | | i = = 1) {

System.out.println ("No." + (i + 1) + "Rabbit number of months: 2");

} else {

M[i] = M[i-1] + m[i-2];

System.out.println ("First" + (i + 1) + "Rabbit number of months:" + 2 * m[i] + "only");

}

}

Enter any one by one positive integers less than 10 to find its factorial and output it in a sentence.

int jie = 1;

System.out.println ("Please enter a positive integer:");

int num = Reader.nextint ();

while (num < 0) {

System.out.println ("You are not entering a positive integer, please re-enter!") ");

num = Reader.nextint ();

}

for (int i = 1; I <= num; i++) {

Jie *= i;

}

System.out.println ("factorial is:" + Jie);

Enter any one by one positive integers less than 10 to find out its factorial and output with a single word.

int jie = 1;

int sum = 0;

System.out.println ("Please enter a positive integer:");

int num = Reader.nextint ();

while (num < 0) {

System.out.println ("You are not entering a positive integer, please re-enter!") ");

num = Reader.nextint ();

}

for (int i = 1; I <= num; i++) {

Jie *= i;

sum + = Jie;

}

System.out.println ("factorial is:" + Jie + "factorial and is:" + sum);

Requirement Description: Suppose a simple ATM's withdrawal process is: first prompt the user to enter the password (password), assuming the default password is 111111, the maximum can be entered 3 times, more than 3 times prompt the user "password error, please take the card", close the transaction.

If the user password is correct, then prompt the user to select the amount (amount), "Please enter 0 to 6 any number to select the corresponding amount of money: 0 Manual input amounts, 1 100 yuan, 2 300 yuan, 3 500 yuan, 4 1000 yuan, 5 3000 yuan, 6 5000 yuan".

Enter the number if the error, prompt "Input error, whether continue y/n", select Y re-prompt input money number, select the N hint "input error, please pick up the card!" ”。 Select a number from 1 to 6 to print the corresponding amount,

and prompt "The transaction completes, please collect the card". Select Digital 0,ATM machine can only output 100 yuan banknotes, custom money requirements of the minimum is 100 yuan, up to 1000 yuan. If the amount entered by the user conforms to the above requirements, the output of the user's money will be printed, and the "withdrawal is completed, whether continue to y/n"; otherwise output a sentence "amount error, whether continue y/n", if the user enters Y, prompts the user to re-select the withdrawal amount, if the user enters N, prints "The transaction cancels, please ”

PS: After successful withdrawal, the user should be prompted whether to continue, the total withdrawal amount can not exceed 20,000

    1. Verify the password.

① The password is correct, continue with the following operation.

② password Error 3 times, return.

    1. Withdrawal operations. All contained within the while loop.

① prompt to select a number.

② assigns money to money according to the number. Implemented with the switch structure.

1~6: Assigns a fixed value directly to money.

0: Manual assignment operation.

③ Verify that the withdrawals were successful. Money represents the amount of this withdrawal, moneysum represents the total amount before this withdrawal. Judge whether the Moneysum+money is >20000,3: If more than 20000, means that the withdrawal of excess, but before the moneysum and less than 20000, continue the next cycle, if equal to 20000, take the money, just complete, Money can be added to Moneysum, and then return, if less than 20000, after the money, still not reach the upper limit, money can be added to the moneysum, continue the next cycle.

④ verify whether to continue. WHILE-IF structure implementation, there are 3 kinds of situations: y/y, will be small loop break, continue to perform the withdrawal of large cycle. n/n, return directly, stop all operations. Other symbols: Continue, continue to perform small loops, and repeat the input y/n.

Scanner in = new Scanner (system.in);

SYSTEM.OUT.PRINTLN ("*********** Welcome ATM Withdrawal Business **********");

Verify Password

int i = 1;

for (; I <= 3; i++) {

System.out.print ("Please enter password:");

int pwd = In.nextint ();

if (pwd = = 111111) {

SYSTEM.OUT.PRINTLN ("Password entered correctly!") ");

Break

}

}

if (i>3) {

If I is greater than 3, it means that 3 times the password is all wrong.

SYSTEM.OUT.PRINTLN ("Password error 3 times! Please pick up the card! ");

Return

}

System.out.println ("************ please withdraw ************ according to the serial number");

Withdrawal operations

int moneysum = 0;//Total withdrawal amount

int money = 0;//This withdrawal amount

while (true) {

System.out.println ("0-Enter the amount manually");

System.out.println ("1-100 yuan \t\t2-300 yuan \t\t3-500 yuan");

System.out.println ("4-1000 yuan \t\t5-3000 yuan \t\t6-5000 yuan");

System.out.print ("Please select:");

int choosenum = In.nextint ();

Switch (choosenum) {

Case 1:

Money = 100;

Break

Case 2:

Money = 300;

Break

Case 3:

Money = 500;

Break

Case 4:

Money = 1000;

Break

Case 5:

Money = 3000;

Break

Case 6:

Money = 5000;

Break

Case 0:

while (true) {

System.out.print ("Please enter the withdrawal amount:");

Money = In.nextint ();

if (money>=100&&money<=1000&&money%100==0) {

Break

}else{

System.out.print ("The amount you entered is not legal,");

Continue

}

}

Break

Default

SYSTEM.OUT.PRINTLN ("Serial number selection Error!");

Break

}

Verify that the total withdrawal amount is more than 20000

if (moneysum+money<20000) {

System.out.print ("Withdrawal success, this withdrawal" +money+ "Yuan,");

Moneysum + = money;

SYSTEM.OUT.PRINTLN ("Total withdrawals" +moneysum+ "Yuan");

}else if (Moneysum+money = = 20000) {

System.out.print ("Withdrawal success, this withdrawal" +money+ "Yuan,");

Moneysum + = money;

SYSTEM.OUT.PRINTLN ("Total withdrawals" +moneysum+ "Yuan");

System.out.print ("Withdrawal has reached the limit today, the card!" ");

Break

}else{

System.out.println ("Withdrawal failed! Daily withdrawal limit of 20000 yuan, you have taken "

+moneysum+ "Yuan, also desirable" + (20000-moneysum) + "Yuan");

}

Verify that you continue

while (true) {

System.out.print ("\ n whether to continue (y/n):");

Char Isgoon = In.next (). charAt (0);

if (isgoon== ' Y ' | | isgoon== ' Y ') {

Break

}else if (isgoon== ' n ' | | isgoon== ' N ') {

Return

}else{

System.out.print ("Input error, please select Y-continuation, N-Exit,");

}

}

}

SYSTEM.OUT.PRINTLN ("Thank you for your use!") ");

Jerry Education 5

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.