java会员管理系统(对象数组的使用)

来源:互联网 发布:java软件开发课程 编辑:程序博客网 时间:2024/06/05 21:53

用户登录的界面提示,其中默认的登录名为admin密码为123

 

package view;

 

import java.util.Scanner;

 

public class Loginmenu {

Scanner s = new Scanner(System.in);

String sname = "admin";

String spass = "123";

 

publicvoid login() {

System.out.println("........欢迎光临........");

System.out.println("1.登录");

System.out.println("2.退出");

System.out.println("........ ..............");

 

int c = s.nextInt();

 

switch (c) {

case 1:

check();

break;

case 2:

System.exit(0);

break;

 

default:

break;

}

 

}

 

void check() {

boolean t = true;

 

while (t) {

 

System.out.println("請輸入用戶名");

String name = s.next();

System.out.println("請輸入密碼");

String pass = s.next();

if (name.equals(sname) && pass.equals(spass)) {

t = false;

Mainmenu m = new Mainmenu();

m.showMenu();

break;

} else {

continue;

 

}

 

}

 

}

}

功能选择模块

package view;

 

import server.Addcard;

 

import java.util.Scanner;

 

import market.dao.*;

 

public class Mainmenu {

Addcard aa = new Addcard();

Loginmenu ll = new Loginmenu();

Scanner s = new Scanner(System.in);

void showMenu(){

System.out.println("........欢迎光临........");

System.out.println("1.添加会员卡");

System.out.println("2.查看会员卡");

System.out.println("3.删除会员卡");

System.out.println("4.重置");

System.out.println("5.抽奖");

System.out.println("6.退出");

System.out.println("........ ..............");

 int i=s.nextInt();

switch (i) {

case 1:

Addcard a=new Addcard ();

a.addCard();

showMenu();

case 2:

Addcard aa = new Addcard();

aa.searchinfor();

showMenu();

break;

case 3:

Addcard dd = new Addcard();

dd.delectCust();

break;

case 4:

Addcard aa1 = new Addcard();

aa1.updateinfor();

showMenu();

break;

case 5:

Addcard aa2 = new Addcard();

aa2.reward();

showMenu();

break;

case 6:

System.out.println("欢迎下次光临,谢谢");

ll.login();

break;

   

    

}

}

 

}

定义的客户类

package enitity;

 

public class Custmor {

//会员卡号

int CustNum;

//会员名字

String name;

//会员余额

double money;

public int getCustNum() {

return CustNum;

}

public void setCustNum(int custNum) {

CustNum = custNum;

}

public String getName() {

return name;

}

public void setName(String name) {

this.name = name;

}

public double getMoney() {

return money;

}

public void setMoney(double money) {

this.money = money;

}

}

定义的对象数组,存放客户信息

package market.dao;

 

import java.util.Scanner;

 

import enitity.Custmor;

 

public class Custmordao {

Scanner in = new Scanner(System.in);

 

static  public Custmor[] cList=new Custmor[500];

 public static int index=0;

//添加

public void addCust(Custmor c){

cList[index]=c;

index++;

}

}

功能实现模块

package server;

 

import java.util.Random;

import java.util.Scanner;

 

import enitity.Custmor;

import market.dao.Custmordao;

import server.*;

public class Addcard {

 

Scanner s=new Scanner(System.in);

Custmordao c=new Custmordao();

Custmor  cc = new Custmor();

publicvoid addCard(){

        Custmor tempCust=new Custmor();

System.out.println("........欢迎光临........");

System.out.println("........1.输入卡号........");

tempCust.setCustNum(s.nextInt());

System.out.println("........2.输入名字........");

tempCust.setName(s.next());

System.out.println("........3.首次充值金额........");

tempCust.setMoney(s.nextDouble());

System.out.println("........4.确认提交........");

c.addCust(tempCust);

}

public void searchinfor()

{

for(int i=0 ;i<c.index;i++)

System.out.println("卡号++++"+i+c.cList[i].getCustNum()+"姓名"+c.cList[i].getName()+"充值金额"+c.cList[i].getMoney());

}

public void delectCust()

{

String key;

boolean ff=false;

System.out.println("输入你要删除的会员名");

key = s.nextLine();

for(int i=0;i<=Custmordao.index;i++)

{

if(Custmordao.cList[i].getName().equals(key))

{

for(int j=i;j<Custmordao.index;j++)

{

Custmordao.cList[i]=Custmordao.cList[i+1];

}

Custmordao.cList[Custmordao.index] = null;

Custmordao.index--;

ff=true;

}

}

if(ff==true)

{

System.out.println("删除成功");

}

}

public void updateinfor()

{

System.out.println("输入要更改的会员姓名");

String cardname;

cardname = s.next();

for(int i=0 ;i<c.index;i++)

{

if(c.cList[i].getName().equals(cardname))

{

System.out.println("输入卡号");

int cardno;

cardno = s.nextInt();

c.cList[i].setCustNum(cardno);

System.out.println("输入新的会员名");

String name3 = s.next();

c.cList[i].setName(name3);

System.out.println("恭喜你,修改成功");

}

else{

System.out.println("小的愚钝,没有找到你的名字");

}

}

}

public void reward()

{

Random wo = new Random(4);

if(wo.nextInt(4)==0)

{

System.out.println("sorry ,让你失望了,再玩一把吧");

}

else

System.out.println("恭喜你,你是"+wo.nextInt(4)+"等奖");

}

 

}

测试模块

import view.Loginmenu;

 

public class Test{

 

public static void main(String[] args) {

Loginmenu tt= new Loginmenu();

tt.login();

}

}

 


0 0
原创粉丝点击