導航:首頁 > 編程語言 > java聯系人

java聯系人

發布時間:2023-01-10 01:40:49

1. java如何實現手機通訊錄「添加」聯系人電話、姓名、功能

引流操作方式很簡單1養號申請2打開Excel導入電話號碼選擇本地號段,導入Excel,然後按照尾號0001開始下拉拖動將得到的號碼導入手機中。3添加好友打開

2. 編寫Java程序實現一個通訊錄

去問 JAVA 老師

3. 在Java中如何將聯系人信息寫入資料庫

首先在資料庫中定義一個聯系人的表,然後在Java中通過表單和聯系的類進行關聯,通過類與資料庫欄位的映射關系寫入表中。

4. java個人通訊錄管理系統

import java.util.Arrays;

public class AddressBook
{
private int totalContacts; // 現在通訊錄中的總數

private int maxContacts; // 通訊錄的最大值

private Contact[] contacts; // 通訊錄的array

/**
* Constructor. 設定這個通訊錄最初的大小為10人上限.
*/
public AddressBook()
{
totalContacts = 0;
maxContacts = 10;
contacts = new Contact[totalContacts];
}

/**
* 得到一個聯系通過通訊錄中的名字
*
* @param name
* 要去得到的聯系人名字
* @return 這個聯系人, 沒有的話為null
*/
public Contact getContactByName(String name)
{
for(int i = 0; i < totalContacts; i++)
{
Contact c = contacts[i];
if(name.equals(c.getName()))
{
return c;
}
}
return null;
}

/**
* 在這個contacts array的最後給這個通訊錄添加聯系人.
* 如果聯系人已經存在且號碼參數不為0的話,聯系人的號碼會更新或者地址參數不是null的話,地址會更新。.
* 如果totalContacts達到maxContacts的值的話,在新的聯系人被添加前,這個contacts
* array的size會乘以雙倍並且maxContacts也乘以雙倍。
*
* @param contact
* 要加到這個通訊錄的聯系人
* @return true 如果這個聯系人添加成功, 否則 false;
*/
public boolean addContact(Contact contact)
{
for(int i = 0; i < contacts.length; i++)
{
Contact ct = contacts[i];
if(ct.equals(contact))
{
if(ct.getNumber() != 0)
{
ct.setNumber(contact.getNumber());
}
if(null != ct.getAddress())
{
ct.setAddress(contact.getAddress());
}
return true;
}
}
if(totalContacts == maxContacts)
{
totalContacts *= 2;
maxContacts *= 2;
}
Contact[] cs = new Contact[totalContacts + 1];
System.array(contacts, 0, cs, 0, totalContacts);
cs[cs.length - 1] = contact;
contacts = cs;
totalContacts++;
return true;
}

/**
* 檢查是否聯系人已經存在
*
* @param contact
* 要去檢查的contact
* @return true 如果這個聯系人被找到,否則false
*/
public boolean contains(Contact contact)
{
for(int i = 0; i < totalContacts; i++)
{
if(contacts[i].equals(contact))
{
return true;
}
}
return false;
}

public void printAddressBook()
{
for(int i = 0; i < totalContacts; i++)
{
System.out.println(contacts[i]);
}
}

/**
* 在AddressBook中還有一個方法!
* 從通訊錄中移除一個指定的聯系人,之後把其他的入口左移,這樣在聯系人間就沒有空隙了,
* For example:
* before -> {C1, C2, C3, C4, C5, C6, C7, C8, C9, null} remove C6
* after -> {C1, C2, C3, C4, C5, C7, C8, C9, null, null}
*
* @param contact
* 要移除的聯系人,
* @return true 如果這個聯系人被成功移除了,否則false;
*/
public boolean removeContact(Contact contact)
{
if(totalContacts == 0)
{
return false;
}
for(int i = 0; i < totalContacts; i++)
{
Contact ct = contacts[i];
if(ct.equals(contact))
{
Contact[] cs = new Contact[totalContacts];
System.array(contacts, 0, cs, 0, i);
System.array(contacts, i + 1, cs, i, cs.length - i - 1);
contacts = cs;
totalContacts--;
return true;
}
}
return false;
}

@Override
public String toString()
{
return String.format("AddressBook [totalContacts=%s, maxContacts=%s, contacts=%s]", totalContacts, maxContacts,
Arrays.toString(contacts));
}
}

//--------------------------------------------------

public class Contact
{
private String name;

private long number;

private String address;

public String getName()
{
return name;
}

public void setName(String name)
{
this.name = name;
}

public long getNumber()
{
return number;
}

public void setNumber(long number)
{
this.number = number;
}

public String getAddress()
{
return address;
}

public void setAddress(String address)
{
this.address = address;
}

@Override
public boolean equals(Object obj)
{
if(!(obj instanceof Contact))
{
return false;
}
Contact contact = (Contact) obj;
if(this.getName().equals(contact.getName())
&&
this.getAddress().equals(contact.getAddress())
&&
this.getNumber() == contact.getNumber())
{
return true;
}
return false;
}

@Override
public String toString()
{
return String.format("Contact [name=%s, number=%s, address=%s]", name, number, address);
}
}

//---------------------------------------------

public class Test
{
public static void main(String[] args)
{
AddressBook ab = new AddressBook();
for(int i = 0; i < 10; i++)
{
Contact contact = new Contact();
int x = i + 1;
contact.setName("C" + x);
contact.setAddress("china");
contact.setNumber(x);
ab.addContact(contact);
}
System.out.println(ab);
Contact c = new Contact();
c.setName("C6");
c.setAddress("china");
c.setNumber(6);
ab.removeContact(c);
System.out.println(ab);
}
}

5. JAVA通訊錄 求一個JAVA編寫的通訊錄,基本的就可以。

具體方法如下:

1、定義封裝一條記錄的實體類

7、全部代碼:

import java.util.Scanner;


class Contact {

String cellPhone;

String name;

}


public class Main {

private static void menu () {

System.out.println("************** 菜單 ******"

+ "************");

System.out.println(" 1.顯示全部通訊錄");

System.out.println(" 2.增加一條記錄");

System.out.println(" 3.刪除一條記錄");

System.out.println(" 4.修改一條記錄");

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

}

public static void main(String[] args) {

Scanner scn = new Scanner(System.in);

Contact[] contacts = new Contact[200];

int size = 0;


String cmd = "";


do {

menu();

System.out.print("請輸入你得選擇:(0-4)");

cmd = scn.nextLine();


if (cmd.equals("1")) {

if (size == 0)

System.out.println("系統當前無記錄!");

else

for (int i = 0; i < size; i++) {

System.out.println(contacts[i].name + ":"

+ contacts[i].cellPhone);

}

} else if (cmd.equals("2")) {

System.out.print("請輸入手機號:");

String cellphone = scn.nextLine();

System.out.print("請輸入姓名:");

String name = scn.nextLine();

Contact contact = new Contact();

contact.cellPhone = cellphone;

contact.name = name;

if (size < contacts.length) {

contacts[size++] = contact;

System.out.println("添加成功!");

} else {

System.out.println("你最多隻能添加" +

contacts.length + "條記錄");

}


} else if (cmd.equals("3")) {

System.out.print("請輸入要刪除的手機號:");

String cellphone = scn.nextLine();

int index = -1;

for (int i = 0; i < size && i < contacts.length;

i++) {

if (contacts[i].cellPhone.equals(cellphone)) {

index = i;

break;

}

}


if (index == -1) {

System.out.println("該記錄不存在!");

} else {

for (int i = index; i < size; i++) {

contacts[index] = contacts[index + 1];

}

contacts[size - 1] = null;

size--;

System.out.println("刪除成功!");

}

} else if (cmd.equals("4")) {

System.out.print("請輸入要修改的手機號:");

String cellphone = scn.nextLine();

int index = -1;

for (int i = 0; i < size && i < contacts.length;

i++) {

if (contacts[i].cellPhone.equals(cellphone)) {

index = i;

break;

}

}


if (index == -1) {

System.out.println("該記錄不存在!");

} else {

System.out.print("請輸入姓名:");

String name = scn.nextLine();

contacts[index].name = name;

}

}

} while (!cmd.equals("0"));


System.out.println("退出成功!");

scn.close();

System.exit(0);

}

}

6. 求解java,想點擊table的某一行後,然後點擊「查看聯系人」按鈕,彈出顯示聯系人的框子,代碼如下

selectRow 看一下這個值是不是-1 如果是-1 那就說明回去行的時候出錯

7. java中做一個簡單的通訊錄包含名字年齡性別電話類別

將 java的欄位 名字 年齡 性別 等等 放在一個javabean裡面,自動生成get set 方法(假設是person類)
然後在你想顯示的頁面,用List<person> ,將你的聯系人信息 add到集合中,最後在你要顯示的界面把集合的數據取出來 放進布局就可以了。

8. 實現一個小型通訊錄。Java

Friend類:public class Friend {
/*
* 姓名
*/
private String name;
/*
* 電話
*/
private String telephone;
/*
* 郵箱
*/
private String email;
/*
* 公司
*/
private String company; public String getName() {
return name;
} public void setName(String name) {
this.name = name;
} public String getTelephone() {
return telephone;
} public void setTelephone(String telephone) {
this.telephone = telephone;
} public String getEmail() {
return email;
} public void setEmail(String email) {
this.email = email;
} public String getCompany() {
return company;
} public void setCompany(String company) {
this.company = company;
} public String toString() {
StringBuffer str = new StringBuffer(); str.append("姓名:" + name).append("\n");
str.append("電話:" + telephone).append("\n");
str.append("郵箱:" + email).append("\n");
str.append("公司:" + company).append("\n");
str.append("-----------------------------------------\n");
return str.toString();
}
}AddFriend類:public class AddFriend { /**
* 主方法 程序的入口
*/
public static void main(String[] args) {
List<Friend> friendList = new ArrayList<Friend>();
char isGo = 'Y';
int i = 0;
do {
Friend friend = new Friend();
System.out.println("請輸入第" + (i + 1) + "位朋友的姓名:");
InputStreamReader reader = new InputStreamReader(System.in);
String str = "";
try {
str = (new BufferedReader(reader)).readLine();
} catch (IOException e) {
e.printStackTrace();
}
friend.setName(str); System.out.println("請輸入第" + (i + 1) + "位朋友的電話:"); try {
str = (new BufferedReader(reader)).readLine();
} catch (IOException e) {
e.printStackTrace();
}
if (str.matches("\\d*") && str.length() == 11) {// 判斷用戶輸入的電話是否符合標准
friend.setTelephone(str);
} else {
System.out.println("電話號碼輸入有誤,請重新輸入!");
continue;
} System.out.println("請輸入第" + (i + 1) + "位朋友的郵箱:"); try {
str = (new BufferedReader(reader)).readLine();
} catch (IOException e) {
e.printStackTrace();
}
friend.setEmail(str); System.out.println("請輸入第" + (i + 1) + "位朋友的公司:"); try {
str = (new BufferedReader(reader)).readLine();
} catch (IOException e) {
e.printStackTrace();
}
friend.setCompany(str); friendList.add(friend); i++; System.out.println("是否繼續添加?(Y/N):");
String go = "";
try {
go = (new BufferedReader(reader)).readLine();
} catch (IOException e) {
e.printStackTrace();
}
isGo = go.charAt(0);
} while (isGo == 'Y' || isGo == 'y'); for (int j = 0; j < friendList.size(); j++) {
System.out.println(friendList.get(j).toString());
}
}
}

閱讀全文

與java聯系人相關的資料

熱點內容
上門正骨用什麼app 瀏覽:756
安卓為什麼免費使用 瀏覽:397
加密貨幣都有哪些平台 瀏覽:625
python和matlab難度 瀏覽:388
python爬蟲很難學么 瀏覽:572
小米解壓積木可以組成什麼呢 瀏覽:816
為什麼滴滴出行app還能用 瀏覽:564
怎麼升級手機android 瀏覽:922
php權威編程pdf 瀏覽:994
扣扣加密技巧 瀏覽:720
蘋果如何創建伺服器錯誤 瀏覽:495
軟考初級程序員大題分值 瀏覽:474
js壓縮視頻文件 瀏覽:578
linux如何通過命令創建文件 瀏覽:991
應用加密app還能訪問應用嘛 瀏覽:434
安卓怎麼用支付寶交違章罰款 瀏覽:666
php面向對象的程序設計 瀏覽:505
數據挖掘演算法書籍推薦 瀏覽:895
投訴聯通用什麼app 瀏覽:152
web伺服器變更ip地址 瀏覽:956