@Create object properties and methods.
package xt; import java.util.Scanner; public class Website { //Create operator class static String WebsiteName; //Name of operator private String name; //User name private String password ; //Password private double balance ; //Account balance private double turnover ; //A turnover private boolean authenticated; //Boolean validation //Welcome statement static void welcome() { System.out.println ("----------" + "Welcome to" +WebsiteName + "-----------"); } public Website(String name,String password,double turnover) { // TODO Auto-generated method stub this.name = name; this.password = password; this.turnover = turnover; this.balance = turnover - 10; this.authenticated = false; System.out.println (name+"Account opened successfully, account balance is"+balance) ; } public boolean getAuthenticated() { return this.authenticated; } public boolean authenticate(String pwd) { if (pwd.equals(this.password)) { this.authenticated = true; } return this.authenticated; } public void deposit (double turnover) { Scanner sc=new Scanner(System.in); System.out.println("Please enter:"); turnover=sc.nextDouble(); System.out.println(turnover); balance = balance + turnover; System.out.println(name+ "Hello, your account has been deposited"+turnover+"Yuan," + "Current balance "+balance+ " element"); } public void withdrawal (double turnover) { if (!this.getAuthenticated()) { // System.out.println("the password you entered is wrong! ""; System.out.println("Unauthorised operation!"); // Could throw an exception here return; } //Judge balance if (balance - turnover > 0 ) { this.balance =balance- turnover; System.out.println(name+"Hello, you have successfully handled the broadband Internet service for half a year. Thank you for your use. The service has been consumed through your account"+turnover+"Yuan, "+ "Current balance "+balance+" element"+ "\n Welcome to China Unicom, thank you for your strong support, we will be better for your service!") ; }else { System.out.println( name+"Hello, you have successfully handled the broadband Internet service for half a year. Thank you for your use. The service has been consumed through your account"+turnover+"Yuan, "+ "The current balance is "+balance +" Your call fee will be insufficient soon. In order not to affect your communication, please pay the call fee in time"+"\n Welcome to China Unicom, thank you for your strong support, we will be better for your service!") ; } } static void welcomeNext() { System.out.println("---------- "+ "Please take your belongings with you. Welcome to visit next time" +WebsiteName+" ------------"); } }
@Using class name access, create objects and assign values.
package xt; import java.util.Scanner; public class text01 { public static void main(String[] args) { // TODO Auto-generated method stub Website.WebsiteName = "China Unicom"; //Define an operator Website.welcome(); //Call welcome Website website= new Website("Chen Yihan my goddess","654321", 200.0); //Construct method for user operation website.deposit(500.0); //Deposit operation Scanner s = new Scanner(System.in); int counter = 0; while (counter < 3 && !website.getAuthenticated()) { System.out.println("Please input the password for online business Please input your password."); if (website.authenticate(s.nextLine())) { break; } ++ counter; System.out.println("\t Incorrect password \n Incorrect password."); } if (!website.getAuthenticated()) { System.out.println("Login failed " + "Failed to login!" + "\n close program"); return; } //Wrong password, failed to enter website.withdrawal(200.0); //Sorry, your credit is running low, // website.withdrawal(100.0); / / the password is correct and the balance is sufficient website.welcomeNext(); } }
Realization effect
It uses this keyword call, if else, while If... Password loop.
The first time I worked on a system project, there were many projects that were done by my predecessors. This time I want to do a different one. Now this project is not complete, some modules are not perfect, use this learning to verify their own gains. There is still a lot of grammar to learn.