博客主頁 小吳_小吳有想法_CSDN博客-筆記,java領域博主
歡迎關注
點贊
收藏和留言
天道酬勤,勤能補拙,和小吳一起加油吧
大一新生,水平有限,懇請各位大佬指點,不勝感激!
1.很多大一學生像我一樣都是大一上學期學習C語言,而元旦過后,懷著奮斗的激情,腦海中是否會閃過一絲彷徨?
在這里給小伙伴們一點我的建議和看法:
1.首先,基礎非常重要,如果上學期學的c語言的語法還不夠扎實,可以先不急著入門另一門語言,找一些c語言大佬的總結和筆記消化消化刷刷題鞏固一下!(可以直接在csdn上搜c語言大總結)
2.如果報了藍橋杯(java組)等知識競賽,可以先了解下java(javase),然后進行系統的演算法學習,下面是給小伙伴們的一些建議和我自己走的一些彎路的總結
目錄
1.JavaSE基礎知識
2.客戶資訊管理系統的功能介紹
1.JavaSE基礎知識
JavaSE是大部分小伙伴入門必須經歷的一個階段,我也正在努力學習它,下面是我的一些想法:
相信一些小伙伴們在搜索學習路線時大多會看到以下幾本書




1.這幾本書我剛開始都看了一段時間,我覺得Java編程思想不太適合Java零基礎的小白看,等有一定語法基礎后再看還是很有幫助的(當然,這些都需要根據個人情況哈)
2.Java核心卷寫的也非常全面和詳細,我覺得零基礎的小伙伴可以先用Java從入門到精通這本書入門并結合Java經典編程300例上面的例題去練習鞏固,學一單元就可以刷上面對應每一單元的題,再以核心卷為主去歸納總結(當然,前期主要以看視頻學習為主)
在這里推薦幾個嗶哩嗶哩上的幾個視頻1.尚硅谷尚硅谷Java入門視頻教程(在線答疑+Java面試真題)_嗶哩嗶哩_bilibili
2.黑馬程式員黑馬程式員全套Java教程_Java基礎入門視頻教程,零基礎小白自學Java必備教程_嗶哩嗶哩_bilibili 3.動力節點https://search.bilibili.com/all?keyword=%E5%8A%A8%E5%8A%9B%E8%8A%82%E7%82%B9&
小伙伴們可以根據他們的講課風格挑選自己習慣的看,對于入門,多寫多練,成千上萬行代碼很有幫助!
3.推薦小伙伴們下載typora這個軟體,用來記筆記,包括代碼塊等功能,并分類記還是挺方便的,而且每天也可以把記的筆記同步到博客里去,養成習慣

好啦,下面的客戶資訊管理系統算是我對前面所學的一些語法知識的鞏固和總結
2.客戶資訊管理軟體的功能介紹
一些小知識點:
1.charAt(int index)方法是一個能夠用來檢索特定索引下的字符的String實體的方法,charAt()方法回傳指定索引位置的char值,索引范圍是0~length()-1.
2.equals()比較的是同一個型別的兩個不同物件里的屬性們是否都相等,相等則回傳true,否則回傳false,
3.Integer.parselent(String)的作用是將String字符型別資料轉換為Integer整型資料,
4.try..catch是用于防止程式出現崩潰而不能處理的時,try catch用于例外捕獲,try分支陳述句執行出現例外被catch捕捉后會執行catch分支陳述句,
在寫客戶資訊管理系統的時候分4個板塊
1.最容易上手的Customer類
package ak;
public class Customer {
private String name;
private char gender;
private int age;
private String phone;
private String email;
public Customer()
{
}
public Customer(String name,char gender,int age,String phone,String email)
{
this.name=name;//姓名name
this.gender=gender;//性別gender
this.age=age;//年齡age
this.phone=phone;//電話phone
this.email=email;//郵箱email
}
public String getName()//獲得姓名
{
return name;
}
public void setName(String name)//修改姓名,下面的屬性皆一樣
{
this.name=name;
}
public char getGender()
{
return gender;
}
public void setGender(char gender)
{
this.gender=gender;
}
public int getAge()
{
return age;
}
public void setAge(int age)
{
this.age=age;
}
public String getPhone()
{
return phone;
}
public void setPhone(String phone)
{
this.phone=phone;
}
public String getEmail()
{
return email;
}
public void setEmail(String email)
{
this.email=email;
}
}
2.緊接著處理CustomerList類
package ak;
import ak.Customer;//呼叫Customer類
public class CustomerList {
private Customer [] customers;//創立物件陣列(如果不是很容易接受,可以看下尚硅谷老師講物件陣列那幾節課)
private int total=0;//代表客戶數量
public CustomerList(int totalCustomer)
{
customers=new Customer[totalCustomer];//設定構造器處理陣列長度
}
public int getTotal()
{
return total;
}
public boolean addCustomer(Customer customer)//增刪改查第一步,添加物件=客戶
{
if(total<customers.length)
{
customers[total++]=customer;
return true;
}else
return false;
}
public boolean replaceCustomer(int index,Customer customer)//改動物件=客戶
{
if(index>=0&&index<total)
{
customers[index]=customer;
return true;
}
else
return false;
}
public boolean deleteCustomer(int index)//洗掉,將指定要洗掉的索引位置元素前移
{
if(index>=0&&index<total)
{
for(int i=index;i<total-1;i++)
{
customers[i]=customers[i+1];
}
customers[total-1]=null;
total--;
return true;
}else
return false;
}
public Customer[] getALLCustomers()//查,像c語言的指標函式一樣,回傳的是地址
{
Customer[] a=new Customer[total];
for(int i=0;i<total;i++)
{
a[i]=customers[i];
}
return customers;
}
public Customer getCustomer(int index)//查找指定位置的客戶=物件
{
if(index>=0&&index<total)
{
return customers[index];
}else
return null;
}
}
3.CMUtility類——處理客戶資訊(性別,電話,郵箱)的細節等
package ak;
import java.util.*;
public class CMUtility {
private static Scanner m=new Scanner(System.in);
private static String readKeyBoard(int limit,boolean bank)//處理資訊的,下面很多都要用到
{
for(; ;)
{
String str=m.nextLine();
if(str.length()>=0&&str.length()<=limit)//這個獲取字串的長度不要與獲取陣列的長度搞混
{
return str;
}
else if(bank)
{
return str;
}
else
System.out.print("請輸入長度不超過"+limit+"的字串");
}
}
public static char readMenuSelection()//用于處理我們要操作的選項,增刪改查的哪一種
{
char n;
for(;;)
{
String str=readKeyBoard(1,false);
n=str.charAt(0);
if(n=='1'||n=='2'||n=='3'||n=='4'||n=='5')
{
return n;
}
else
{
System.out.println("選擇錯誤,請重新輸入");
}
}
}
public static char readChar()//獲取性別,下面利用方法多載來解決當我們修改客戶的資訊,但是不修改性別時該怎樣實作
{
String str=readKeyBoard(1,false);
return str.charAt(0);
}
public static char readChar(char defaultValue)
{
String str=readKeyBoard(1,true);//這里用true,這樣我們只有用回車跳過才可以達到我們所需,嘿嘿,到時候我們只需要讓引數是本來的數即可
return (str.length()==0)?defaultValue:str.charAt(0);
}
public static int readInt()//獲取年齡
{
int s;
for(; ;)
{
String str=readKeyBoard(2,false);
try {
s = Integer.parseInt(str);
return s;
}catch (NumberFormatException e) {
System.out.println("數字輸入錯誤,請重新輸入,");
}
}
}
public static int readInt(int defaultValue)//修改年齡,當然也可能不需要改,這時候與上面修改性別的函式有著異曲同工之妙
{
int s;
for(; ;)
{
String str=readKeyBoard(2,true);
if (str.equals(""))//注意這里與修改性別又不想修改時的區別
{
return defaultValue;
}
try {
s= Integer.parseInt(str);
return s;
}
catch (NumberFormatException e) {
System.out.println("數字輸入錯誤,請重新輸入,");
}
}
}
public static String readString(int limit)//姓名,電話,郵箱一塊搞
{
return readKeyBoard(limit,false);
}
public static String readString(int limit,String defaultValue)//修改姓名,電話,郵箱,不輸入資訊直接回車咯!
{
String str=readKeyBoard(limit,true);
return str.equals("")?defaultValue:str;
}
public static char readConfirmSelection()//選單的洗掉物件=客戶的操作,會顯示是否確認洗掉
{
for(; ;)
{
String str=readKeyBoard(1,false).toUpperCase();
char m=str.charAt(0);
if(m=='Y'||m=='N')
{
return m;
}
else
{
System.out.println("選擇錯誤,請重新輸入");
}
}
}
}
4.CustomerView類,主類!
package ak;
import ak.Customer;
import ak.CustomerList;
import ak.CMUtility;
public class CustomerView {
private CustomerList customerList=new CustomerList(10);//設定物件陣列長度
public CustomerView()//先搞一下客戶資訊做對照
{
Customer customer=new Customer("傳龍",'男',19,"219043","433@qq.com");//注意,年齡19那里只需要寫數字就行,不要加“ ”或者’ ‘
customerList.addCustomer(customer);
}
public void enterMainmenu()//來啦來啦,主界面安排上!
{
boolean a=true;
while(a)
{
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(" 請選擇(1-5): ");
char select=CMUtility.readMenuSelection();
switch(select)
{//注意,這里要用'1',而不是1,嗚嗚我剛開始就忘記了
case '1':
addNewCustomer();
break;
case '2':
modifyCustomer();
break;
case '3':
deleteCustomer();
break;
case '4':
listALLCustomers();
break;
case '5':
System.out.println("是否確認退出(Y/N)?");
char c=CMUtility.readConfirmSelection();
if(c=='Y')
{
a=false;
}
}
}
}
public void addNewCustomer()//添加客戶
{
int total=customerList.getTotal();
if(total<customerList.getALLCustomers().length)
{
System.out.println("客戶姓名:");
String name=CMUtility.readString(10);
System.out.println("客戶性別:");
char gender=CMUtility.readChar();
System.out.println("客戶年齡:");
int age=CMUtility.readInt();
System.out.println("客戶電話:");
String tel=CMUtility.readString(13);
System.out.println("客戶郵箱");
String email=CMUtility.readString(15);
Customer cust=new Customer(name,gender,age,tel,email);
customerList.addCustomer(cust);
System.out.println("-----------------添加成功-----------------\t");
}else{
System.out.println("-----------客戶串列已滿,添加失敗-------------\t");
}
}
public void modifyCustomer()//修改客戶
{
System.out.println("-----------------修改客戶-----------------");
int index;
Customer cust;
for(; ;)
{
System.out.println("請輸入要修改的客戶序號(-1)退出");
index=CMUtility.readInt();
if(index==-1)
{
return ;//注意,這里如果用break只是會退出for回圈,不會退出修改客戶這個方法
}
index--;//雖然我們選中比如說是修改客戶4,但是陣列是從0開始儲存的,所以這時候把序號-1即為元素位置!
cust=customerList.getCustomer(index);
if(cust==null)
{
System.out.println("無法找到客戶");
}
else
{
break;
}
}
System.out.println("姓名("+cust.getName()+"):");
String name=CMUtility.readString(10,cust.getName());
System.out.println("性別("+cust.getGender()+"):");
char gender=CMUtility.readChar(cust.getGender());
System.out.println("年齡("+cust.getAge()+"):");
int age=CMUtility.readInt(cust.getAge());
System.out.println("電話("+cust.getPhone()+"):");
String phone=CMUtility.readString(13,cust.getPhone());
System.out.println("郵箱("+cust.getEmail()+"):");
String email=CMUtility.readString(15,cust.getEmail());
Customer newcust=new Customer(name,gender,age,phone,email);
boolean ss=customerList.replaceCustomer(index,newcust);
if(ss)
{
System.out.println("-----------------修 改 成 功-----------------\\t");
}
else
{
System.out.println("-----------------修 改 失 敗-----------------\t");
}
}
public void deleteCustomer()//洗掉客戶
{
System.out.println("-----------------洗掉客戶-----------------");
Customer cust;
int index;
for (;;) {
System.out.println("請輸入要洗掉的客戶序號(輸入-1退出)");
index = CMUtility.readInt();
if (index == -1) {
return;
}
index--;
cust = customerList.getCustomer(index);
if (cust == null) {
System.out.println("無法找到客戶!");
} else {
break;
}
}
System.out.println("是否確認洗掉?(Y/N)");
char r=CMUtility.readConfirmSelection();
if(r=='Y')
{
boolean rr=customerList.deleteCustomer(index);
if(rr)
{
System.out.println("-----------------刪 除 成 功-----------------\\t");
}
else
{
System.out.println("洗掉失敗,請輸入正確序號:1->\"+customerList.getTotal()");
}
}
}
public void listALLCustomers()//查找客戶
{
System.out.println("-------------------客 戶 列 表------------------\n");
int total=customerList.getTotal();
if(total==0)
{
System.out.println("沒有客戶記錄!");
}
else
{
System.out.println("編號\t姓名\t性別\t年齡\t電話\t\t郵箱");//這里有2個\t的是因為在實際運行中我們發現電話太長啦,和上面不對照!
Customer[] custList=customerList.getALLCustomers();//把所有客戶(物件)都搞過來!
for(int i=0;i<total;i++)
{ //注意這里序號是i+1,因為陣列下標是從0開始遍歷哈!
System.out.println(i+1 + "\t" + custList[i].getName() + "\t" + custList[i].getGender() + "\t"+
custList[i].getAge() + "\t" + custList[i].getPhone() + "\t\t" + custList[i].getEmail() + "\t");
}
}
System.out.println("-----------------客戶串列完成-----------------\n");
}
public static void main(String[] args)
{
CustomerView jie=new CustomerView();
jie.enterMainmenu();
}
}
下面是我隨便輸入的幾個資訊演示:
如果有需要《java從入門到精通》,《Java編程思想》,《java核心卷》,《深入理解jvm虛擬機》等電子書可以私聊我哈!加油!
天道酬勤,勤能補拙,和小吳一起加油吧!
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/401630.html
標籤:java
