About the Java Practice Report

Source: Internet
Author: User

on the Java Practice report, overall is not difficult, for me the biggest difficulty lies in the use of the collection, which also shows my seventh chapter and even the overall use of Java is not good, the seventh chapter because of the lack of proficiency because the code volume does not knock much, many things do not understand, The use of double-row sets and single-column collections, in general, such banking systems are definitely better with the map collection, directly set the user account as the key value, the object user is set to value, and then compare the account password directly to call, Either the ContainsKey method or the Equals keyword comparison makes the code more flexible and simpler. While the list collection can be used, it is more cumbersome to use, and does not say that when creating a collection object to create more objects, it is necessary to set more parameters when calling. When it comes to calling, I wrote three classes at the very beginning, but also at the call time I found that because I didn't understand the call of the collection object in the collection class, I finally deleted a class, put the method directly into the test class, although the call is solved, but the whole code looks bloated a lot, not concise, this is one of my flaws, Where I need to improve later. In terms of the If judgment, my judgment condition is easy to get stuck, because the multi-cycle is my weakness, but this practice report uses the multi-cycle place is very simple, later also needs to exercise more.

Import java.util.*;
Class Person
{

private String name;
private String number;
Private String ID;
private String password;
private double money;
Private String call;
Public person () {
}
Public person (String nsme,string number,string id,string call,string password,double money) {
This.name=name;
This.number=number;
This.id=id;
This.password=password;
This.money=money;
This.call=call;
}
public void SetName (String name) {
This.name=name;
}
Public String GetName () {
return name;
}
public void Setnumber (String number) {
This.number=number;
}
Public String GetNumber () {
return number;
}
public void SetID (String ID) {
This.id=id;
}
Public String GetID () {
return ID;
}
public void SetPassword (String password) {
This.password=password;
}
Public String GetPassword () {
return password;
}
public void Setmoney (double money) {
This.money=money;
}
Public double Getmoney () {
return money;
}
public void Setcall () {
This.call=call;
}
Public String Getcall () {
return call;
}
}
public class Example013
{
public static void Main (string[] args)
{
Map<string,person> map=new hashmap<string,person> ();
int a=2;
int k;
int n=0;
Scanner in= New Scanner (system.in);
Scanner input=new Scanner (system.in);
Person Person=new person ();
Person Person1=new person ("Mr.zhang", "123", "410611199512017373", "18790851234", "123456", 1000);
Person Person2=new person ("Mr.wang", "124", "410611199512017374", "18790851235", "123457", 100);
Person Person3=new person ("Mr.li", "125", "410611199512017375", "18790851236", "123458", 2000);
Person Person4=new person ("Mr.zhao", "126", "410611199512017376", "18790851237", "123459", 11000);
Person Person5=new person ("Mr.wu", "127", "410611199512017378", "18790851238", "1234560", 1000);
Map.put ("123", Person1);
Map.put ("124", Person2);
Map.put ("Person3");
Map.put ("126", person4);
Map.put ("127", person5);
Set Keyset=map.keyset ();
Iterator It=keyset.iterator ();
while (It.hasnext ()) {
String key= (String) it.next ();
Person=map.get (key);
while (n<4) {
SYSTEM.OUT.PRINTLN ("Please lose Your account:");
String Id=in.nextline ();
System.out.println ("Please enter your password:");
String Pass=in.nextline ();
if (key.equals (ID) &&pass.equals (Person.getpassword ()))
{
System.out.println ("Welcome," "+person.getname () +", please select the service);
}
Else
{
if (a>0)
{

System.out.println ("Incorrect account or password! ");
System.out.println ("We give you 3 times to enter the opportunity, you also have" +a+ "chance ^_^");
a--;
n++;
}
Else
{
System.out.println ("Sorry, we want to force you to quit the system, because you silly smacking 3 times the wrong password ^_^");
System.exit (0);
}
}
}
Do
{
System.out.println ("1, deposit \t2, withdrawal \t3, inquiry \t0, exit \ t");
K=in.nextint ();
Switch (k)
{
Case 1:
Scanner in1=new Scanner (system.in);
System.out.println ("Please enter your deposit amount:");
Double money1=in1.nextdouble ();
Person.setmoney (Person.getmoney () +money1);
System.out.println ("Deposit success! ");
Break
Case 2:
Double y;
Scanner in2=new Scanner (system.in);
System.out.println ("Please enter the withdrawal amount:");
Double money2=in2.nextdouble ();
if (Person.getmoney () <money2)
{
SYSTEM.OUT.PRINTLN ("Insufficient balance!") Please re-select the service (it is recommended that you check the balance before selecting) ");
}
else if (Person.getmoney () >=money2) {
SYSTEM.OUT.PRINTLN ("Withdrawals are successful! ");
Y=person.getmoney ()-money2;
Person.setmoney (y);
}
Break
Case 3:
System.out.println (Person.getmoney ());
Break
Case 0:
System.out.println ("Exit system, Wish you Happy");
System. Exit (0);
}

}
while (k!=0);
}
}
}

About the Java Practice Report

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.