private?int?balance?=?0;
在衛(wèi)輝等地區(qū),都構(gòu)建了全面的區(qū)域性戰(zhàn)略布局,加強發(fā)展的系統(tǒng)性、市場前瞻性、產(chǎn)品創(chuàng)新能力,以專注、極致的服務(wù)理念,為客戶提供做網(wǎng)站、網(wǎng)站設(shè)計 網(wǎng)站設(shè)計制作按需策劃設(shè)計,公司網(wǎng)站建設(shè),企業(yè)網(wǎng)站建設(shè),高端網(wǎng)站設(shè)計,成都全網(wǎng)營銷推廣,外貿(mào)營銷網(wǎng)站建設(shè),衛(wèi)輝網(wǎng)站建設(shè)費用合理。
private??String?username?=?"A";
private??String?password?=?"B";
public?void?bank()?{
Scanner?scan?=?new?Scanner(System.in);
String??temp;
while?(true)?{
System.out.println("輸入賬號:");
if?(scan.hasNext())?{
temp?=?scan.next();
if?(temp.equals(username))?{
break;
}?else?{
System.out.println("輸入錯誤");
}
}
}
while?(true)?{
System.out.println("輸入密碼:");
if?(scan.hasNext())?{
temp?=?scan.next();
if?(temp.equals(password))?{
break;
}?else?{
System.out.println("輸入錯誤");
}
}
}
System.out.println("登錄成功");
while?(true)?{
System.out.println("輸入操作:");
if?(scan.hasNext())?{
temp?=?scan.next();
switch?(temp)?{
case?"存款":
int?x?=?0;
while?(true)?{
System.out.println("輸入存款金額:");
if?(scan.hasNextInt())?{
x?=?scan.nextInt();
break;
}?else?{
System.out.println("輸入錯誤");
scan.next();
}
}
balance?+=?x;
break;
case?"取款":
int?y?=?0;
while?(true)?{
System.out.println("輸入取款金額:");
if?(scan.hasNextInt())?{
y?=?scan.nextInt();
if?(balance??y)?{
System.out.println("余額不足");
continue;
}
break;
}?else?{
System.out.println("輸入錯誤");
scan.next();
}
}
balance?-=?y;
break;
case?"余額":
System.out.println("余額:"?+?balance);
break;
case?"終止":
System.exit(0);
default:
System.out.println("未知操作");
}
}
}
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class BankWaiting extends JFrame implements ActionListener {
int total = 0, now = 0;
boolean is1Ready = false, is2Ready = false, is3Ready = false;
int call1, call2, call3;
JFrame jf;
JLabel jr, jl, jl1, j2, jl2, j3, jl3;
JTextField jr4;
JButton jb, jb1, jb2, j1;
JButton workBut1, workBut2, workBut3;
JPanel jp, jp1, jp2;
public BankWaiting() {
setLayout(null);
jf = new JFrame("銀行叫號程序");// 窗體
jr = new JLabel("請**號到*號窗口辦理業(yè)務(wù)");
jr.setBounds(300, 10, 800, 50);
jr.setForeground(Color.red);
j1 = new JButton("取號");
j1.addActionListener(this);
jr4 = new JTextField("歡迎");
jr4.setEditable(false);
ButtonGroup bg = new ButtonGroup();
bg.add(j1);
jp = new JPanel();
jl = new JLabel("一號窗口");
jl1 = new JLabel("一號窗口,歡迎你!");
jb = new JButton("下一位");
workBut1 = new JButton("開始辦理");
workBut1.addActionListener(this);
jb.addActionListener(this);
jp.setBackground(Color.pink);
jp.setSize(200, 80);// 大小
jp.setLocation(20, 120); // 位置
jf.setLayout(null);
jp1 = new JPanel();
j2 = new JLabel("二號窗口");
jl2 = new JLabel("二號窗口,歡迎你!");
jb1 = new JButton("下一位");
workBut2 = new JButton("開始辦理");
jb1.addActionListener(this);
workBut2.addActionListener(this);
jp1.setBackground(Color.pink);
jp1.setSize(200, 80);// 大小
jp1.setLocation(250, 120); // 位置
jf.setLayout(null);
jp2 = new JPanel();
j3 = new JLabel("三號窗口");
jl3 = new JLabel("三號窗口,歡迎你!");
jb2 = new JButton("下一位");
workBut3 = new JButton("開始辦理");
workBut3.addActionListener(this);
jb2.addActionListener(this);
jp2.setBackground(Color.pink);
jp2.setSize(200, 80);// 大小
jp2.setLocation(500, 120); // 位置
jf.setLayout(null);
jf.add(jp);
jf.add(jp1);
jf.add(jp2);
jf.add(jr);
jp.add(jl);
jp.add(jl1);
jp.add(jb);
jp.add(workBut1);
jp1.add(j2);
jp1.add(jl2);
jp1.add(jb1);
jp1.add(workBut2);
jp2.add(j3);
jp2.add(jl3);
jp2.add(jb2);
jp2.add(workBut3);
jf.add(j1);
jf.add(jr4);
j1.setBounds(550, 300, 60, 30);
jr4.setBounds(300, 300, 200, 40);
jf.setSize(800, 600);
jf.setVisible(true);
jf.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
}
public void actionPerformed(ActionEvent e) {
String s = "";
if (e.getSource() == j1) {
s = "第" + (++total) + "號,前面還有" + (total - now - 1) + "位顧客!";
jr4.setText(s);
}
if (e.getSource() == jb) {
if (this.hasCustomers()) {
s = "請" + (++now) + "號顧客到一號窗口辦理";
call1 = now;
jl1.setText(s);
jr.setText(s);
is1Ready = true;
} else {
s = "當前已經(jīng)沒有顧客了";
jl1.setText(s);
is1Ready = false;
}
} else if (e.getSource() == jb1) {
if (this.hasCustomers()) {
s = "請" + (++now) + "號顧客到二號窗口辦理";
call2 = now;
jl2.setText(s);
jr.setText(s);
is2Ready = true;
} else {
s = "當前已經(jīng)沒有顧客了";
jl2.setText(s);
is2Ready = false;
}
} else if (e.getSource() == jb2) {
if (this.hasCustomers()) {
s = "請" + (++now) + "號顧客到三號窗口辦理";
call3 = now;
jl3.setText(s);
jr.setText(s);
is3Ready = true;
} else {
s = "當前已經(jīng)沒有顧客了";
jl3.setText(s);
is3Ready = false;
}
}
if (e.getSource() == workBut1) {
if (is1Ready) {
s = call1 + "號顧客正在辦理業(yè)務(wù)。。。";
jl1.setText(s);
is1Ready = false;
}
} else if (e.getSource() == workBut2) {
if (is2Ready) {
s = call2 + "號顧客正在辦理業(yè)務(wù)。。。";
jl2.setText(s);
is2Ready = false;
}
} else if (e.getSource() == workBut3) {
if (is3Ready) {
s = call3 + "號顧客正在辦理業(yè)務(wù)。。。";
jl3.setText(s);
is3Ready = false;
}
}
}
public boolean hasCustomers() {
if (now total) {
return true;
} else {
return false;
}
}
public static void main(String[] args) {
new BankWaiting();
}
}
java編寫這個通訊錄管理系統(tǒng)
java編寫這個通訊錄管理系統(tǒng)_Java如何實現(xiàn)通訊錄管理系統(tǒng)
咕嚕嚕在芬蘭
原創(chuàng)
關(guān)注
3點贊·2305人閱讀
Java如何實現(xiàn)通訊錄管理系統(tǒng)
發(fā)布時間:2020-07-28 09:39:42
來源:億速云
閱讀:65
作者:Leah
這篇文章將為大家詳細講解有關(guān)Java如何實現(xiàn)通訊錄管理系統(tǒng),文章內(nèi)容質(zhì)量較高,因此小編分享給大家做個參考,希望大家閱讀完這篇文章后對相關(guān)知識有一定的了解。
本文實例為大家分享了java實現(xiàn)通訊錄管理系統(tǒng)的具體代碼,供大家參考,具體內(nèi)容如下
完成項目的流程:
1.根據(jù)需求,確定大體方向
2.功能模塊分析
3.界面實現(xiàn)
4.功能模塊設(shè)計
5.coding
6.代碼測試
下面是源代碼:import java.awt.Container;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Scanner;
import java.util.concurrent.SynchronousQueue;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.WindowConstants;
import javax.swing.text.html.HTMLDocument.Iterator;
class Infro{
public String id;
public String name;
public String sex;
public String address;
public String e_mail;
public String phoneNumber;
static int index = 0;
static ArrayList list = new ArrayList();
static int len = list.size();
//構(gòu)造函數(shù)
public Infro(String id,String name,String sex,String address,String e_mail,String phoneNumber){
this.id = id;
this.name = name;
this.sex = sex;
this.address = address;
this.e_mail = e_mail;
this.phoneNumber = phoneNumber;
}
public String toString(){
return "編號:"+id+" 姓名:"+name+" 性別:"+sex+" 通訊地址:"+address+" 郵箱地址:"+e_mail+" 電話:"+phoneNumber;
}
/**
* 添加功能
**/
public static void addFunction(){//添加功能
Infro infro = new Infro("","","","","","");
System.out.println("請輸入添加的數(shù)據(jù):");
Scanner in = new Scanner(System.in);
System.out.println("輸入編號:");
infro.id = in.next();
System.out.println("輸入姓名:");
infro.name = in.next();
System.out.println("輸入性別:");
infro.sex = in.next();
System.out.println("輸入通訊地址:");
infro.address = in.next();
System.
out.println("輸入郵箱地址:");
infro.e_mail = in.next();
System.out.println("輸入電話:");
infro.phoneNumber = in.next();
list.add(index,infro);
index++;
if(list.isEmpty()){
System.out.println("數(shù)據(jù)添加失敗啦");
}else{
System.out.println("數(shù)據(jù)添加成功啦");
len++;//list集合長度加一
// System.out.println(list.get(0).toString());
}
}
// public static void deleteFunction(){//刪除功能
// System.out.println("輸入要刪除的聯(lián)系人的編號");
// Scanner in_2 = new Scanner(System.in);
// String d1 = in_2.nextLine();
// for(int a= 0; a
// if(d1.equals(list.get(a).id)){
// list.remove(list.get(a));
// len --;
// }
// }
// }
/**
* 刪除功能
**/
public static void deleteFunction(){
System.out.println("輸入要刪除的聯(lián)系人的編號");
Scanner in_2 = new Scanner(System.in);
String d1 = in_2.nextLine();
java.util.Iterator it = list.iterator();
while (it.hasNext()){
Infro infro = it.next();
if (infro.id.equals(d1)){
it.remove();
--index;//一定要加這個,否則當做了刪除操作再做添加操作的時候會出現(xiàn)異常(類似于指針,棧)
System.out.println("刪除完畢"+"此時通訊錄記錄條數(shù)為:" + --len);
}
}
}
/**
* 修改功能
**/
public static void reditFunction(){
System.out.println("輸入要修改的通訊錄的Id");
Scanner in_r = new Scanner(System.in);
String r1 = in_r.nextLine();
for(int a = 0; a len;a++){
if(r1.equals(list.get(a).id)){
System.out.println("輸入修改后的姓名:");
String name_1 = in_r.next();
list.get(a).name = name_1;
System.out.println("輸入修改后的性別:");
String sex_1 = in_r.next();
list.get(a).sex = sex_1;
System.out.println("輸入修改后的通訊地址:");
String address_1 = in_r.next();
list.get(a).address = address_1;
System.out.println("輸入修改后的郵箱地址:");
String e_mail_1 = in_r.next();
list.get(a).e_mail = e_mail_1;
System.out.println("輸入修改后的電話:");
String phoneNumber_1 = in_r.next();
list.get(a).phoneNumber = phoneNumber_1;
System.out.println("數(shù)據(jù)修改完畢");
}
}
}
/**
* 查詢功能
**/
public static void searchFunction() throws Exception{//查詢功能
System.out.println("請輸入要查詢的姓名:");
Scanner in_1 = new Scanner(System.in);
String s1=in_1.nextLine();
for(int a= 0; a
if(s1.equals(list.get(a).name)){
System.out.println(list.get(a).toString());
}
}
}
/**
* 顯示功能
**/
public static void showFunction(){
for(int i = 0 ;i
System.out.println(list.get(i).toString());
}
}
/**
* 保存功能
**/
public static void writeFunction() throws IOException{
FileWriter writer = new FileWriter("通訊錄管理.txt");
for(int i = 0 ;i
String []strwriter = new String[len];
strwriter[i]=list.get(i).toString();
writer.write(strwriter[i]);
writer.write("\r\n");
System.out.println("成功寫入一行數(shù)據(jù)到 通訊錄管理.txt 中");
}
writer.close();//關(guān)閉寫入流,釋放資源
}
/**
* 讀取功能
**/
public static void readFunction() throws IOException{
FileReader reader = new FileReader("通訊錄管理.txt");
BufferedReader br = new BufferedReader(reader);
String str;
while((str = br.readLine()) != null){//每次讀取一行文本,判斷是否到達文件尾
System.out.println(str);
}
br.close();
}
}
public class Demo extends JFrame {
/**
* 界面設(shè)計
**/
public Demo(){
Container c = getContentPane(); //定義一個頂級容器c
JPanel jp = new JPanel(); //新建JPanel面板--jp
JButton button1 = new JButton("新建聯(lián)系人");
JButton button2 = new JButton("刪除聯(lián)系人");
JButton button3 = new JButton("編輯聯(lián)系人");
JButton button4 = new JButton("查找聯(lián)系人");
JButton button5 = new JButton("顯示所有聯(lián)系人");
JButton button6 = new JButton("保存聯(lián)系人到本地");
JButton button7 = new JButton("讀取本地聯(lián)系人");
jp.setLayout(new GridLayout(2,4,5,5));//新建網(wǎng)格布局管理器(行數(shù),列數(shù),組件間的水平垂直間距)
jp.add(button1);
jp.add(button2);
jp.add(button3);
jp.add(button4);
jp.add(button5);
jp.add(button6);
jp.add(button7);
c.add(jp);//將JPanel面板jp添加到頂級容器c中
setSize(600,500);
setTitle("*通 訊 錄 管 理 系 統(tǒng)*");
setVisible(true);
setResizable(false);//窗體大小由程序員決定,用戶不能自由改變大小
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
/**
*按鍵響應(yīng)
*
**/
button1.addActionListener(new ActionListener(){//添加功能實現(xiàn)
public void actionPerformed(ActionEvent arg0){
Infro.addFunction();
}
});
button2.addActionListener(new ActionListener(){//刪除功能實現(xiàn)
public void actionPerformed(ActionEvent arg0){
Infro.deleteFunction();
}
});
button3.addActionListener(new ActionListener(){//修改功能實現(xiàn)
public void actionPerformed(ActionEvent arg0){
Infro.reditFunction();
}
});
button4.addActionListener(new ActionListener(){//查詢功能實現(xiàn)
public void actionPerformed(ActionEvent arg0){
try {
Infro.searchFunction();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
button5.addActionListener(new ActionListener(){//顯示功能實現(xiàn)
public void actionPerformed(ActionEvent arg0){
Infro.showFunction();
}
});
button6.addActionListener(new ActionListener(){//保存功能實現(xiàn)
public void actionPerformed(ActionEvent arg0){
try {
Infro.writeFunction();
} catch (IOException e) {
e.printStackTrace();
}
}
});
button7.addActionListener(new ActionListener(){//讀取功能實現(xiàn)
public void actionPerformed(ActionEvent arg0){
try {
Infro.readFunction();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
}
public static void main(String[] args) {
// TODO Auto-generated method stub
new Demo();
Infro a = new Infro("", "", "", "", "", "");
}
}
關(guān)于Java如何實現(xiàn)通訊錄管理系統(tǒng)就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,可以學(xué)到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。
import?java.util.ArrayList;
import?java.util.Collections;
import?java.util.Comparator;
import?java.util.List;
public?class?Sort?{
public?static?void?main(String[]?args)?{
Student?p1?=?new?Student(1001,?"小明",?20);
Student?p2?=?new?Student(1002,?"小紅",?21);
Student?p3?=?new?Student(1003,?"小黑",?19);
ListStudent?list?=?new?ArrayListStudent();
list.add(p1);
list.add(p2);
list.add(p3);
Collections.sort(list,?new?ComparatorStudent()?{
/*
?*?int?compare(Student?o1,?Student?o2)?返回一個基本類型的整型,?返回負數(shù)表示:o1?小于o2,
?*?返回0?表示:o1和o2相等,?返回正數(shù)表示:o1大于o2。
?*/
public?int?compare(Student?o1,?Student?o2)?{
//?按照學(xué)生的學(xué)號進行升序排列
if?(o1.getId()??o2.getId())?{
return?1;
}
if?(o1.getId()?==?o2.getId())?{
return?0;
}
return?-1;
}
});
write(list);
System.out.println("---------------------");
Collections.sort(list,?new?ComparatorStudent()?{
/*
?*?int?compare(Student?o1,?Student?o2)?返回一個基本類型的整型,?返回負數(shù)表示:o1?小于o2,
?*?返回0?表示:o1和o2相等,?返回正數(shù)表示:o1大于o2。
?*/
public?int?compare(Student?o1,?Student?o2)?{
//?按照學(xué)生的年齡進行升序排列
if?(o1.getAge()??o2.getAge())?{
return?1;
}
if?(o1.getAge()?==?o2.getAge())?{
return?0;
}
return?-1;
}
});
write(list);
}
public?static?void?write(ListStudent?list)?{
for?(Student?s?:?list)?{
System.out.println(s.getId()?+?"\t"?+?s.getName()?+?"\t"
+?s.getAge());
}
}
}
public?class?Student?{
private?int?id?;
private?String?name;
private?int?age;
//構(gòu)造方法
public?Student(int?id,String?name,int?age){
this.id?=?id;
this.name?=?name;
this.age?=?age;
}
public?int?getId()?{
return?id;
}
public?void?setId(int?id)?{
this.id?=?id;
}
public?String?getName()?{
return?name;
}
public?void?setName(String?name)?{
this.name?=?name;
}
public?int?getAge()?{
return?age;
}
public?void?setAge(int?age)?{
this.age?=?age;
}
}
package pack.money.persistent;import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;import pack.money.entity.Client;
import pack.money.entity.ClientMessage;
public class ClientPersistent {
//private static int a=0;
private static String t,b;//t是password b是clinetname
private static ClientPersistent sp;
public static ClientPersistent getClientPersistent() {
if (sp == null) {
sp = new ClientPersistent();
}
return sp;
}
private ClientMessage getClientMessage(ResultSet rs) throws Exception{
ClientMessage student=new ClientMessage();
student.setMoney(rs.getFloat("money"));
student.setType(rs.getString("type"));
student.setClientName(rs.getString("ClientName"));
student.setTransactionID(rs.getInt("TransactionID"));
return student;
}
public Client login(Connection con,String ClientName,String password) throws Exception{
String sql="select balance,password,ClientName from Client where ClientName=? and password=?";
PreparedStatement ps=con.prepareStatement(sql);
ps.setString(1, ClientName);
ps.setString(2, password);
ResultSet rs=ps.executeQuery();
t=password;
b=ClientName;
System.out.println(t);
System.out.println(b);
if(rs.next()){
Client client=new Client();
client.setClientName(rs.getString("ClientName"));
client.setPassword(rs.getString("password"));
return client; }
throw new Exception("Can not login, the accountID or password has error. ");
} public void save(Connection con ,String money)throws Exception
{ // a++;
String s="save";
float g=Float.parseFloat(money);
String sql="update Client set balance=balance+? where ClientName=?";
String sql1="insert into ATMTransaction(ClientName,Type,money) values(?,?,?) ";
PreparedStatement ps=con.prepareStatement(sql);
PreparedStatement ps1=con.prepareStatement(sql1);
ps.setFloat(1, g);
ps.setString(2,b);
//ps1.setInt(1,a);
ps1.setString(1,b);
ps1.setString(2,s);
ps1.setFloat(3,g);
ps.executeUpdate();
ps1.executeUpdate();
}
public void withDraw (Connection con ,String money)throws Exception
{ //a++;
String s="WithDraw";
float x=Float.parseFloat(money);
String sql="update Client set balance=balance-? where ClientName=?";
String sql1="insert into ATMTransaction(ClientName,Type,money) values(?,?,?)";
PreparedStatement ps=con.prepareStatement(sql);
PreparedStatement ps1=con.prepareStatement(sql1);
ps.setFloat(1, x);
ps.setString(2,b);
//ps1.setInt(1,a);
ps1.setString(1,b);
ps1.setString(2,s);
ps1.setFloat(3,x);
ps.executeUpdate();
ps1.executeUpdate();
}
public String changePassword(Connection con, String OldPassWord,String newPassWord1,String newPassWord2)
throws Exception
{
if(t.equals(OldPassWord))
{
if(newPassWord1.equals(newPassWord2))
{
String sql="update Client set password=? where ClientName=?";
PreparedStatement ps=con.prepareStatement(sql);
ps.setString(1, newPassWord1);
ps.setString(2,b);
ps.executeUpdate();
String j="dsfasdf";
return j;
}
else
{System.out.print("確認密碼錯誤!");br return null;}
}
else
{ return null;
}
}
public ArrayListClientMessage disPlayAll(Connection con ) throws Exception
{
String sql="select * from ATMTransaction where ClientName=? ";
PreparedStatement ps=con.prepareStatement(sql);
ps.setString(1,b);
System.out.println(b+"****b****");
ResultSet rs=ps.executeQuery();
ArrayListClientMessage message=new ArrayListClientMessage();
while(rs.next()){
message.add(this.getClientMessage(rs));
}
return message;
}
public float showBalance(Connection con ) throws Exception
{
String sql="select balance from Client where ClientName=?";
PreparedStatement ps=con.prepareStatement(sql);
ps.setString(1, b);
ResultSet rs=ps.executeQuery();
if(rs.next())
{
float s;
s=rs.getFloat("balance");
return s;
}
else return 0 ;
}
}
本文名稱:java叫號系統(tǒng)代碼 叫號排隊系統(tǒng)java
鏈接URL:http://www.muchs.cn/article18/hphggp.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供外貿(mào)建站、網(wǎng)站收錄、全網(wǎng)營銷推廣、網(wǎng)站制作、外貿(mào)網(wǎng)站建設(shè)、Google
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)