Simulating supermarket locker cases using the Java language

Source: Internet
Author: User
Tags first row

Requirements: There are two kinds of operation of storage and package. System initialization has a series of storage, the packet action to give birth to a password, and occupy a storage space, when the bag to verify the input storage number and password, the correct empty storage grid.

Import Java.util.Random;

Import Java.util.Scanner;
	public class Supermarketstorebox {public static int[] Boxex = new INT[24];

	Static Scanner scan = new Scanner (system.in);

	public static void Main (string[] args) {welcome (); /** * Defines a way to draw a box/public static void Drawboxex () {for (int i = 0; i < i++) {//traverse the first row of 12 boxes if (box 
			Ex[i] = = 0) {//Judge whether there is anything in the box System.out.print ("-");//Print Empty box} else {//box has something System.out.print (");/Print Solid box
		} System.out.println ();
		for (int j = 1; J <=-J) {System.out.printf ("%2d", j);//number of first 12 boxes} System.out.println ();
			for (int x = x < boxex.length/x + +) {//Print 12 boxes if (boxex[x] = = 0) {//judge whether there is something in the box System.out.print ("-");
			else {//There is something System.out.print in the box ("");
		} System.out.println ();
	for (int y = y <= y++) {System.out.printf ("%2d", y);//give the latter 12 boxes number} System.out.println (); /** * Storage Package Method: To determine whether the box has stored things, if there is no deposit, prompts the user box can be used and generate a password, * There's something left, keep looking for empty box, if not found empty box, * Prompt user box is full, please later.
		* */** * Defines a method for saving a package/public static void put () {Random rd = new Random (); for (int i = 0; I <= i++) {if (boxex[i) = = 0) {//box is empty boxex[i] = Rd.nextint (8999) + 1000;//generate password Syst
				Em.out.println ((i + 1) + "No box can be used");
				System.out.println ("This Is your password:" + boxex[i] + ", do not tell others ~");
			Break if (i = =) {System.out.println ("the box is full, please later.")
			"); /** * Defines a method for fetching a packet/public static void Get () {int count = 0;//counter, recording password error times System.out.println ("Please enter the box number:"
		);
		int i = Scan.nextint ()-1;
		if (i >) {System.out.println ("The storage box does not exist"); else {if (boxex[i] = = 0) {System.out.println ("There is nothing in the box.")
			");
					else {while (true) {System.out.println ("Please enter the box password:");
					int pwd = Scan.nextint (); if (boxex[i] = = pwd) {System.out.println ((i + 1) + "box open, please take away your valuables."
						");
						Boxex[i] = 0;
					Break
						else {count++; SYSTEM.OUT.PRINTLN (password error, please re-enter.)
				");		if (Count >= 3) {System.out.println ("password is wrong 3 times, the locker is locked, please contact the front desk staff to resolve it.")
							");
						Return /** * Welcome interface/public static void Welcome () {System.out.println ("T------------storage Box Management system
		------------\ n ');
		System.out.println ("\t╱╲╱╲╰★╮" Storage "╭★╯╱╲╱╲\n");
		System.out.println ("\t╲ Huan ╲╱╰☆╮" Things "╭☆╯╲╱ Huan ╱\n");
		System.out.println ("\t╱╲ Ying ╲╰★╮" tube "╭★╯╱ ying ╱╲\n");
		System.out.println ("\t╱╲╱╲╰☆╮" rationale "╭☆╯╱╲╱╲\n\n");
	Operate ();
			/** * Action method/public static void operate () {while (true) {Drawboxex ();
			System.out.println ("\ t--------------------------------------\ n");
			System.out.println ("\ t 1, Save Pack 2, take 0, exit");
			SYSTEM.OUT.PRINTLN ("Please select Action:");
			int select = Scan.nextint ();
				Switch (SELECT) {case 1:put ();
			Break
				Case 2:get ();
			Break
				Case 0:exit ();
			Break
				DEFAULT:SYSTEM.OUT.PRINTLN ("input error");
			Break }}/** * Exit method */public static void exIt () {System.out.println ("Welcome next time, Bye Bye!!!");

	System.exit (0);
 }

}


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.