⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 textphonecard.java

📁 电话卡系统
💻 JAVA
字号:
import java.io.*;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
class PhoneCard{                                      //
	private long password;
	long CardNumber;
	double balance;
	int ID;
	PhoneCard(){}                                     //
	PhoneCard(long pw,long CN,double balance){        //
		this.password=pw;
		this.CardNumber=CN;
		this.balance=balance;
	}
	long Getpassword(){                               //
		return this.password;
	}
	boolean performConnection(long CN,long pw){       //
		if(CN==this.CardNumber&&pw==Getpassword()){
			return true;
		}
		else
		    return false;
    }
    int reWritePassword()throws IOException{
    	int i;
    	BufferedReader bin=new BufferedReader(new InputStreamReader(System.in));
    	long pw,npw1,npw2;
    	for(i=1;i<5;i++){
    	    System.out.print("please input the Initpassword: ");
    	    pw=Long.parseLong(bin.readLine());
    	    if(pw==Getpassword())
    	          break;
    	    System.out.println("you Inputpassword is error.");
    	}
    	if(i==5){
    	    System.out.println("you have Input error password 5 times,the System quit");
    	    return -1;
    	}      
    	System.out.print("please input the Newpassword: ");
    	npw1=Long.parseLong(bin.readLine());
    	System.out.print("please reput the Newpassword: ");
    	npw2=Long.parseLong(bin.readLine());
    	if(npw1==npw2){
    		this.password=npw2;
    		System.out.println("reWritePassword is succeed");
    		return 1;
    	}
    	else{
    		System.out.println("two times input are different,reWritePassword is fail");
    		return 0;
    	}
    }
    
}
class PhoneCardArray{
	int number=3;
	long[] PN=new long[20];
	PhoneCard[] a=new PhoneCard[number];
	PhoneCardArray(PhoneCard[] a){
		int i;
		long k=84397672;
		for(i=0;i<20;i++){
    		PN[i]=k;
    		k+=33333;
		a[0]=new PhoneCard(6219892,456789,1.0);
		a[1]=new PhoneCard(4900369,987654,1.0);
		a[2]=new PhoneCard(4598165,875462,1.0);
		this.a=a;
		}
	}
	PhoneCardArray(int number,PhoneCard[] a)throws IOException{//构造函数
		int i,j;
		long k=84397672;
		long CardNumber,password;
		double balance;
		BufferedReader bin=new BufferedReader(new InputStreamReader(System.in));
		this.number=number;
		for(i=0;i<20;i++){
    		PN[i]=k;
    		k+=33333;
    	}
		for(i=0,j=1;i<number;i++,j++){
			a[i].ID=j;
			System.out.print("please input the "+j+" PhoneCard's CardNumber");
			CardNumber=Long.parseLong(bin.readLine());
			System.out.print("please input the "+j+" PhoneCard's password");
			password=Long.parseLong(bin.readLine());
			System.out.print("please input the "+j+" PhoneCard's balance");
			balance=Double.parseDouble(bin.readLine());
			a[i]=new PhoneCard(password,CardNumber,balance);
		}
		this.a=a;
	}
    int PhoneNumberExist(long PhoneNumber){
    	int i;
		for(i=0;i<20;i++){
    		if(PN[i]==PhoneNumber){
    			this.balance-=0.5;
    			return 1;
    		}	
    	}
    	return 0;
	}
    int performDial(long PhoneNumber){                //
    	if(this.balance==0){ 
    	        System.out.println("the Card's balance is 0\n please fill the balance ");
    	        return -1; 
    	}
    	if(!PhoneNumberExist(PhoneNumber)){
    	    System.out.println("The number you dial is not exist");
    	    return 0;
    	}
    	System.out.println("you have succeed dial the number,the PhoneCard's balance left: "+this.balance);
    	return 1;    
    }
	void print(){
		System.out.println("Now you have "+this.number+" PhoneCard can be use");
		int n;
		for(n=0;n<number;n++){
	         System.out.println("a["+n+"]:  CardNumber:"+a[n].CardNumber+"  password:"+a[n].Getpassword()+"  balance:"+a[n].balance);
	    }
	}
	int GetPhoneCard(long CN){
		int i;
		for(i=0;i<number;i++){
			if(a[i].CardNumber==CN)
			    return i;	   
		}
		return -1;
	}
	void printPhoneNumber(){	
    	int i;
    	System.out.print("The follow PhoneNumber can be connect:");
    	for(i=0;i<20;i++){
    		if(i%5==0)
    		    System.out.print("\n");
    		System.out.print(PN[i]+"   ");
    		}
	}
}
class PhoneCardArrayOperate{
	PhoneCardArrayOperate(){}
 void TextPhoneArrayCard()throws IOException{
		int i=1,k,m,n=0;
		long j=0,l=0,o;//定义变量o
		PhoneCard[] a=new PhoneCard[3];
		BufferedReader bin=new BufferedReader(new InputStreamReader(System.in));
		PhoneCardArray PCA=new PhoneCardArray(a);
		PCA.print();
		PCA.printPhoneNumber();
		System.out.print("\n");
        System.out.println("**********************************************");
		System.out.println("************** INPUT 1 TO LOGIN **************");
		System.out.println("********* INPUT 2 TO REWRITEPASSWORD *********");
		System.out.println("*********** INPUT 3 TO PERFORMDIAL ***********");
		System.out.println("*********** INPUT 4 TO QUIT ******************");
		System.out.println("**********************************************");
		System.out.println("Please Choose:");
		for(k=1;k<5;k++){
		i=Integer.parseInt(bin.readLine());
		if(i==1||i==4)
		    break;
		System.out.println("please login first.");
		System.out.println("Please Choose:");
		}
		if(i!=4){
		if(k!=5){
		T:switch(i){
			case 1:{
				    for(m=1;m<5;m++){
				        for(k=1;k<5;k++){
			                 System.out.print("please input CardNumber:");
			                 j=Long.parseLong(bin.readLine());
			                 if(PCA.GetPhoneCard(j)==-1)
			                      System.out.println("The CardNumber does not exist");
			                 else{
			                      System.out.print("please input password:");
			                      l=Long.parseLong(bin.readLine());
			                      n=PCA.GetPhoneCard(j);
			                      PCA.a[n].performConnection(j,l);
			                      break;
			                 }     
			           }
			           if(k==5){
    	                    System.out.println("you have Input not exist CardNumber 4 times,the System quit");
    	                    break T;
    	               }
    	               if(PCA.a[PCA.GetPhoneCard(j)].performConnection(j,l)==true)
    	                    break;
    	           }
    	           if(m==5){
    	                System.out.println("you have Input error password 4 times,the System quit");
    	                break T;
    	           }
    	           for(m=0;m<50;m++){    
    	                System.out.println("continue:please choose 2 to rewritepassword or choose 3 to performdial,else choose 4 to quit:");
    	                System.out.println("Please Choose:");
    	                i=Integer.parseInt(bin.readLine());
    	                switch(i){
    	              	   case 2:
    	              	   PCA.a[n].reWritePassword();
    	              	   break;
    	              	   case 3:
    	              	   System.out.print("please input the PhoneNumber:");
    	              	   o=Long.parseLong(bin.readLine());
    	              	   PCA.a[n].performDial(o);
    	              	   break;
    	              	   case 4:break T;
    	               }
    	           }
    	           break;
    	              	
		}    
		case 2:break;
		case 3:break;
		case 4:break;	
	 }
	}
	}
	System.out.println("The System quit");
	}
}
public class TextPhoneCard{
	public static void main(String[] args)throws IOException{
	PhoneCardArrayOperate PCAO=new PhoneCardArrayOperate();
	PCAO.TextPhoneArrayCard();
   }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -