How to realize simple Shopping system with Java
This article mainly introduces the relevant knowledge of Java how to achieve a simple shopping system, the content is detailed and easy to understand, the operation is simple and fast, and has a certain reference value. I believe you will gain something after reading this Java article on how to achieve a simple shopping system. Let's take a look at it.
Use basic sentences to implement a shopping system
Package cn.ybk; import java.util.Scanner; / * simple shopping system * * 1. Main interface (select) * 2. User login interface (verify user information) * 3. Log in to the shopping interface (product selection) * * / public class ShoppingSystem {public static void main (String [] args) {String choose3; do {Scanner input = new Scanner (System.in); / / 1. Main interface System.out.println ("="); System.out.println ("= 1. Login = "); System.out.println (" = 2. Exit = "); System.out.println (" = = "); System.out.println (" Please enter options (1 or 2) "); int choose1 = input.nextInt (); if (choose1 = = 1) {/ / enter the login interface System.out.println (" = Please login = ") System.out.println ("Please enter user name:"); / / enter user name String username = input.next (); System.out.println ("Please enter password:"); / / enter password String password = input.next () / / Log in to if ("yangbenkun" .equals (username) & & "123456" .equals (password)) {System.out.println ("Welcome users:" + username); System.out.println ("- > enter the shopping system") / / print merchandise menu System.out.println ("item number\ t trade name\ t\ t unit price"); System.out.println ("1\ t\ t\ tJava basic grammar\ t\ t35.4"); System.out.println ("2\ t\ t\ tJava object oriented\ t\ T87") System.out.println ("3\ t\ t\ tJava actual combat project\ t\ T76"); the shopping cart unit price of double money1=0;//1 double money2 = 0; the shopping cart unit price of double money1=0;//1 2 is double money3 = 0; the shopping cart unit price of 3 is double money = 0 / / Total amount / / do...while cycle to achieve multiple purchases of String choose2; do {System.out.println ("Please enter the item number you want to purchase:"); int no = input.nextInt () If (no = = 1) {System.out.println ("Please enter the quantity you want to buy:"); int sum1 = input.nextInt (); money1 = 35.4; money1 * = sum1 System.out.println (the amount of "1 is:" + money1);} else if (no = = 2) {System.out.println ("Please enter the quantity you want to buy:"); int sum2 = input.nextInt (); money2 = 87.0 Money2 * = sum2; System.out.println (the amount of "2 is:" + money2);} else if (no = = 3) {System.out.println ("Please enter the quantity you want to buy:"); int sum3 = input.nextInt () Money3 = 76.0; money3 * = sum3; System.out.println (the amount of "3 is:" + money3);} else {System.out.println ("Please re-enter the wrong choice") } / / calculate the total amount money = money1 + money2 + money3; System.out.println ("total amount is:" + money); System.out.println ("whether to continue to buy (ngamy)") Choose2 = input.next ();} while ("y" .equals (choose2)); if (money > = 300) {System.out.println ("25% discount over 300"); money*=0.75 } int iPlacement / do {System.out.println ("Please enter your balance") of the loop variable of the control loop; double usermoney = input.nextDouble (); I = 1; if (usermoney