柚子快報邀請碼778899分享:算法 1.24實(shí)訓(xùn)`
柚子快報邀請碼778899分享:算法 1.24實(shí)訓(xùn)`
一維數(shù)組
概念:再java程序中,當(dāng)需要存儲多個數(shù)據(jù)類型相同的內(nèi)容時,則需聲明一個數(shù)組,聲明數(shù)組的本質(zhì),就是在內(nèi)存中申請一段連續(xù)的存儲單元。
聲明變量?
數(shù)組類型 變量名 = 初始值; 數(shù)組名:數(shù)組中變量的名稱; 數(shù)組的長度:數(shù)組名.length 數(shù)組中的元素:數(shù)組當(dāng)中值 數(shù)組角標(biāo)(下標(biāo)):從0開始
聲明數(shù)組的格式: 數(shù)組類型【】 數(shù)組名 = new 數(shù)據(jù)類型【數(shù)組的長度】;//動態(tài)聲明的方式,推薦
數(shù)組的初始化; 如果不給數(shù)組直接賦值,那么整數(shù)默認(rèn)為0,浮點(diǎn)數(shù)默認(rèn)為0.0,布爾類型默認(rèn)false;
數(shù)值的遍歷 使用for循環(huán) for(int i = 0;i public class Array { ? ? public static void main(String[] args) { ? ? ? ? //聲明數(shù)組 ? ? ? ? int[] arr = new int[5]; ? ? ? ? System.out.println(arr[0]); ? ? ? ? ? boolean[] ar = new boolean[2]; ? ? ? ? System.out.println(ar[0]); ? ? ? ? ? char[] cr = new char[4]; ? ? ? ? System.out.println(cr[1]); ? ? ? ? if(cr[0] == 0){ ? ? ? ? ? ? System.out.println("char數(shù)組的默認(rèn)值為0"); ? ? ? ? } ? ? ? } } public class Array01 { ? ? public static void main(String[] args) { ? ? ? ? int a[] = new int[5]; ? ? ? ? for(int i = 0;i } 面向?qū)ο蠛兔嫦蜻^程的區(qū)別 將大象裝冰箱需要幾步 面向過程:打開冰箱,放入大象,放入冰箱(3步) 面向?qū)ο螅赫胰朔胚M(jìn)去(1步) 面向?qū)ο?/p> 類,對象,引用 對象: 在java中,對象是指客觀存在的實(shí)體 語法格式: new 引用數(shù)據(jù)類型(); eg: new Person()://表示創(chuàng)建一個Person類型的對象 public class Person { ? ? String name; ? ? int age; ? ? public void show(){ ? ? ? ? System.out.println("姓名是"+name+",年齡為"+age); ? ? } ? ? public static void main(String[] args) { ? ? ? ? Person p =new Person(); ? ? ? ? p.age = 30; ? ? ? ? p.name = "zhangfei"; ? ? ? ? p.show(); ? ? } } public class Phone { ? ? String name; ? ? double money; ? ? public void show(){ ? ? ? ? System.out.println("品牌是"+name+",價格為:"+money); ? ? } ? ? public static void main(String[] args) { ? ? ? ? Phone p =new Phone(); ? ? ? ? p.name = "諾基亞"; ? ? ? ? p.money = 598.5; ? ? ? ? p.show(); ? ? } } public class Point { ? ? int x; ? ? int y; ? ? ? public static void main(String[] args) { ? ? ? ? //創(chuàng)建一個Point類型的引用p,指向Point類型的對象 ? ? ? ? Point p = new Point(); ? ? ? ? System.out.println("x = "+p.x+",y = "+p.y); ? ? ? ? //修改坐標(biāo)值 ? ? ? ? p.x = 3; ? ? ? ? p.y = 4; ? ? ? ? System.out.println("x = "+p.x+",y = "+p.y); ? ? } } public class Girl { ? ? String name; ? ? int age; ? ? boolean you; ? ? public void show(){ ? ? ? ? System.out.println("名字是"+name+",年齡"+age+",是否有男朋友"+you); ? ? } ? ? ? public static void main(String[] args) { ? ? ? ? Girl g = new Girl(); ? ? ? ? g.age=18; ? ? ? ? g.name = "貂蟬"; ? ? ? ? g.you = true; ? ? ? ? g.show(); ? ? } } 類: 簡單來說就是分類,具有相同特征和行為的多個事物共性的抽象,在java表現(xiàn)為一種引用數(shù)據(jù)類型,其中包含描述特征的成員變量和描述行為的成員方法; 語法格式: 【權(quán)限修飾符】 class 類名{ ? ? 類體 } 類名首字母大寫 UpperCameCase(大駝峰命名法) 成員變量 語法格式: 【權(quán)限修飾符】數(shù)據(jù)類型 成員變量名 = 成員變量值: 成員變量名首字母小寫,由多個單詞構(gòu)成時,從第二個開始,首字母大寫 LowerCameCase(小駝峰命名法) 成員方法(行為): 語法格式: 【權(quán)限修飾符】返回值類型 成員方法名(形參數(shù)據(jù)類型1 形參變量名1){ ? ? 方法體; } public class Point01 { ? ? int x; ? ? int y; ? ? Point01(){} ? ? Point01(int x,int y){ ? ? ? ? this.x = x; ? ? ? ? this.y = y; ? ? } ? ? public void add(int x,int y){ ? ? ? ? x = x + 1; ? ? } ? ? public String show(){ ? ? ? ? return "[橫坐標(biāo)為:"+ x +",縱坐標(biāo)為:"+ y +"]"; ? ? } ? ? public static void main(String[] args) { ? ? ? ? Point01 p = new Point01(); ? ? ? ? System.out.println(p.show()); ? ? ? ? Point01 p1 = new Point01(1,2); ? ? ? ? System.out.println(p1.show()); ? ? ? ? p.add(p.x,p.y); ? ? ? ? System.out.println(p.show()); ? ? } } public class Circle { ? ? double r; ? ? public double Area(double r){ ? ? ? ? return Math.PI*r*r; ? ? } ? ? public double Long(double r){ ? ? ? ? return Math.PI*r*2; ? ? } ? ? public static void main(String[] args) { ? ? ? ? Circle c = new Circle(); ? ? ? ? c.r = 5; ? ? ? ? System.out.println("圓的面積為"+c.Area(c.r)+",周長為"+c.Long(c.r)); ? ? } } import java.util.Random; ? public class Rectangle { ? ? int length; ? ? int width; ? ? public void Rectangle(int width,int length){ ? ? ? ? this.width = width; ? ? ? ? this.length = length; ? ? } ? ? ? public int getArea(){ ? ? ? ? return length * width; ? ? } ? ? public int getPer(){ ? ? ? ? return 2 * (length + width); ? ? } ? ? public void show(){ ? ? ? ? System.out.println("長為"+ length+",寬為"+width+",面積為"+getArea()+",周長為"+getPer()); ? ? } ? ? ? public static void main(String[] args) { ? ? ? ? Rectangle re = new Rectangle(); ? ? ? ? re.Rectangle(2,4); ? ? ? ? re.show(); ? ? } } public class Vehicle { ? ? double speed; ? ? String type; ? ? ? public double getSpeed() { ? ? ? ? return speed; ? ? } ? ? ? public String getType() { ? ? ? ? return type; ? ? } ? ? ? public void setType(String type) { ? ? ? ? this.type = type; ? ? } ? ? ? public void move(){ ? ? ? } ? ? ? public void setSpeed(double speed) { ? ? ? ? this.speed = speed; ? ? } ? ? public void speedUp(double s){ ? ? ? ? speed+=s; ? ? } ? ? public void speedDown(double s){ ? ? ? ? speed-=s; ? ? } ? ? ? public static void main(String[] args) { ? ? ? ? Vehicle v = new Vehicle(); ? ? ? ? v.setType("黑色捷達(dá)"); ? ? ? ? v.setSpeed(5); ? ? ? ? System.out.println("一輛"+v.getType()+"正以每小時"+v.getSpeed()+"千米速度過來"); ? ? ? ? v.speedUp(5); ? ? ? ? System.out.println("一輛"+v.getType()+"正以每小時"+v.getSpeed()+"千米速度過來"); ? ? ? ? v.speedDown(8); ? ? ? ? System.out.println("一輛"+v.getType()+"正以每小時"+v.getSpeed()+"千米速度過來"); ? ? } } 返回值類型: 返回值:只是從方法體內(nèi)向方法體外返回的數(shù)據(jù)內(nèi)容 返回值類型:返回值的數(shù)據(jù)類型 要返回數(shù)據(jù)內(nèi)容,可以使用”return“關(guān)鍵字,將其返回并結(jié)束 形參列表: 形式參數(shù):是指從方法體外向內(nèi)傳遞數(shù)據(jù)內(nèi)容 形參列表:形式參數(shù)可以有多個 alt + insert快捷鍵定義方法 Random import java.util.Random 用法與Scanner相似 //創(chuàng)建一個隨機(jī)數(shù)對象 Random ra = new Random(); ra.nextInt(17)://0-16的隨機(jī)數(shù) import java.util.Random; ? public class DoubleColorBall { ? ? public static void main(String[] args) { ? ? ? ? //聲明一個int類型長度為7的一維數(shù)組,并且使用動態(tài)方式聲明 ? ? ? ? int[] arr = new int[7]; ? ? ? ? //創(chuàng)建一個隨機(jī)數(shù)對象 ? ? ? ? Random ra = new Random(); ? ? ? ? //開始搖號(向數(shù)組元素中添加值),需要先搖6個紅球,范圍1-33 ? ? ? ? for(int i = 0; i < 6; i++){ ? ? ? ? ? ? //搖紅球 ? ? ? ? ? ? arr[i] = ra.nextInt(33) + 1; ? ? ? ? ? ? ? for(int j = i-1;j >= 0;j--){ ? ? ? ? ? ? ? ? if(arr[i] == arr[j]){ ? ? ? ? ? ? ? ? ? ? i--; ? ? ? ? ? ? ? ? ? ? break; ? ? ? ? ? ? ? ? } ? ? ? ? ? ? } ? ? ? ? } ? ? ? ? //藍(lán)色球 ? ? ? ? arr[arr.length-1] =ra.nextInt(17) + 1; ? ? ? ? //遍歷數(shù)組 ? ? ? ? System.out.println("本期中獎結(jié)果:"); ? ? ? ? for(int i=0;i this關(guān)鍵字(原理、理解) 基本概念 在構(gòu)造方法中和成員方法中訪問成員變量時,編譯器會加上this.的前綴,而this.相當(dāng)于漢語中"我的",當(dāng)不同的對象調(diào)用同一個方法時,由于調(diào)用方法的對象不同導(dǎo)致this關(guān)鍵字不同,從而this.方式訪問的結(jié)果也就隨之不同。 使用方式 (1)當(dāng)形參變量名與成員變量名相同時,在方法體中會優(yōu)先使用形參變量(就近原則),若希望使用 成員變量,則需要在成員變量的前面加上this.的前綴,明確要求該變量是成員變量。 (2)在構(gòu)造方法的第一行可以使用this()的方式來調(diào)用本類中的其它構(gòu)造方法(了解)。 public class Girl01 { ? ? String name; ? ? int age; ? ? boolean have; ? ? public void setnah(String name,int age,boolean have){ ? ? ? ? this.name = name; ? ? ? ? this.age = age; ? ? ? ? this.have = have; ? ? } ? ? public String show(){ ? ? ? ? return "姓名"+name+",年齡"+age+",是否有男朋友:"+have; ? ? } ? ? ? public static void main(String[] args) { ? ? ? ? Girl01 g = new Girl01(); ? ? ? ? g.setnah("zh",18,true); ? ? ? ? System.out.println(g.show()); ? ? } } 封裝 基本概念 通常情況下可以在測試類給成員變量賦值一些合法但不合理的數(shù)值,無論是編譯階段還是運(yùn)行階段都不會報錯或者給出提示,此時與現(xiàn)實(shí)生活不符。為了避免上述錯誤的發(fā)生,就需要對成員變量進(jìn)行密封包裝處理,來隱藏成員變量的細(xì)節(jié)以及保證成員變量數(shù)值的合理性,該機(jī)制就叫做封裝。 實(shí)現(xiàn)流程 (1)私有化成員變量,使用private關(guān)鍵字修飾; (2)提供公有的get和set方法,并在方法體中進(jìn)行合理值的判斷; (3)在構(gòu)造方法中調(diào)用set方法進(jìn)行合理值的判斷; 實(shí)體類的封裝: ? 在項(xiàng)目開發(fā)中,通常com.XXXX.bean;com.XXXX.domain;com.XXXX.entity;com.XXXX.pojo 這些包當(dāng)中通常情況下存放的都是實(shí)體類。 ? 實(shí)體類封裝的步驟: ? 1、私有化成員變量; ? 2、提供公有的get/set方法 ? 3、提供無參/有參/全參的構(gòu)造方法 ? 4、重寫toString()、equals和hashCode() import java.util.Objects; ? public class Edu { ? ? public int getId() { ? ? ? ? return id; ? ? } ? ? ? public void setId(int id) { ? ? ? ? this.id = id; ? ? } ? ? ? public int getUserId() { ? ? ? ? return userId; ? ? } ? ? ? public void setUserId(int userId) { ? ? ? ? this.userId = userId; ? ? } ? ? ? public String getStart() { ? ? ? ? return start; ? ? } ? ? ? public void setStart(String start) { ? ? ? ? this.start = start; ? ? } ? ? ? public String getEnd() { ? ? ? ? return end; ? ? } ? ? ? public void setEnd(String end) { ? ? ? ? this.end = end; ? ? } ? ? ? public String getSchool() { ? ? ? ? return school; ? ? } ? ? ? public void setSchool(String school) { ? ? ? ? this.school = school; ? ? } ? ? ? public String getStudy() { ? ? ? ? return study; ? ? } ? ? ? public void setStudy(String study) { ? ? ? ? this.study = study; ? ? } ? ? ? public String getDescription() { ? ? ? ? return description; ? ? } ? ? ? public void setDescription(String description) { ? ? ? ? this.description = description; ? ? } ? ? ? public Edu getNext() { ? ? ? ? return next; ? ? } ? ? ? public void setNext(Edu next) { ? ? ? ? this.next = next; ? ? } ? ? ? private int id; ? ? private int userId; ? ? private String start; ? ? private String end; ? ? private String school; ? ? private String study; ? ? private String description; ? ? private Edu next; ? ? ? public Edu(int userId, String start, String end, String school, String study, String description) { ? ? ? ? this.userId = userId; ? ? ? ? this.start = start; ? ? ? ? this.end = end; ? ? ? ? this.school = school; ? ? ? ? this.study = study; ? ? ? ? this.description = description; ? ? } ? ? ? @Override ? ? public boolean equals(Object o) { ? ? ? ? if (this == o) return true; ? ? ? ? if (o == null || getClass() != o.getClass()) return false; ? ? ? ? Edu edu = (Edu) o; ? ? ? ? return id == edu.id && ? ? ? ? ? ? ? ? userId == edu.userId && ? ? ? ? ? ? ? ? Objects.equals(start, edu.start) && ? ? ? ? ? ? ? ? Objects.equals(end, edu.end) && ? ? ? ? ? ? ? ? Objects.equals(school, edu.school) && ? ? ? ? ? ? ? ? Objects.equals(study, edu.study) && ? ? ? ? ? ? ? ? Objects.equals(description, edu.description) && ? ? ? ? ? ? ? ? Objects.equals(next, edu.next); ? ? } ? ? ? @Override ? ? public int hashCode() { ? ? ? ? return Objects.hash(id, userId, start, end, school, study, description, next); ? ? } ? ? ? @Override ? ? public String toString() { ? ? ? ? return "Edu{" + ? ? ? ? ? ? ? ? "id=" + id + ? ? ? ? ? ? ? ? ", userId=" + userId + ? ? ? ? ? ? ? ? ", start='" + start + '\'' + ? ? ? ? ? ? ? ? ", end='" + end + '\'' + ? ? ? ? ? ? ? ? ", school='" + school + '\'' + ? ? ? ? ? ? ? ? ", study='" + study + '\'' + ? ? ? ? ? ? ? ? ", description='" + description + '\'' + ? ? ? ? ? ? ? ? ", next=" + next + ? ? ? ? ? ? ? ? '}'; ? ? } ? ? ? public Edu(int id, int userId, String start, String end, String school, String study, String description, Edu next) { ? ? ? ? this.id = id; ? ? ? ? this.userId = userId; ? ? ? ? this.start = start; ? ? ? ? this.end = end; ? ? ? ? this.school = school; ? ? ? ? this.study = study; ? ? ? ? this.description = description; ? ? ? ? this.next = next; ? ? } ? ? ? public Edu() { ? ? } ? ? ? public static void main(String[] args) { ? ? ? ? Edu edu = new Edu(1,"","","","",""); ? ? ? ? Edu edu1 = new Edu(1,2,"","","","","",edu); ? ? ? ? System.out.println(edu1.toString()); ? ? } } import java.util.Objects; ? public class Work { ? ? ? private int id; ? ? private int userId; ? ? private String start; ? ? private String end; ? ? private String company; ? ? private String job; ? ? private String description; ? ? Work next; ? ? ? public Work(int userId, String start, String end, String company, String job, String description) { ? ? ? ? this.userId = userId; ? ? ? ? this.start = start; ? ? ? ? this.end = end; ? ? ? ? this.company = company; ? ? ? ? this.job = job; ? ? ? ? this.description = description; ? ? } ? ? ? public int getId() { ? ? ? ? return id; ? ? } ? ? ? public void setId(int id) { ? ? ? ? this.id = id; ? ? } ? ? ? public int getUserId() { ? ? ? ? return userId; ? ? } ? ? ? public void setUserId(int userId) { ? ? ? ? this.userId = userId; ? ? } ? ? ? public String getStart() { ? ? ? ? return start; ? ? } ? ? ? public void setStart(String start) { ? ? ? ? this.start = start; ? ? } ? ? ? public String getEnd() { ? ? ? ? return end; ? ? } ? ? ? public void setEnd(String end) { ? ? ? ? this.end = end; ? ? } ? ? ? public String getCompany() { ? ? ? ? return company; ? ? } ? ? ? public void setCompany(String company) { ? ? ? ? this.company = company; ? ? } ? ? ? public String getJob() { ? ? ? ? return job; ? ? } ? ? ? public void setJob(String job) { ? ? ? ? this.job = job; ? ? } ? ? ? public String getDescription() { ? ? ? ? return description; ? ? } ? ? ? public void setDescription(String description) { ? ? ? ? this.description = description; ? ? } ? ? ? public Work getNext() { ? ? ? ? return next; ? ? } ? ? ? public void setNext(Work next) { ? ? ? ? this.next = next; ? ? } ? ? ? ? ? @Override ? ? public boolean equals(Object o) { ? ? ? ? if (this == o) return true; ? ? ? ? if (o == null || getClass() != o.getClass()) return false; ? ? ? ? Work work = (Work) o; ? ? ? ? return id == work.id && ? ? ? ? ? ? ? ? userId == work.userId && ? ? ? ? ? ? ? ? Objects.equals(start, work.start) && ? ? ? ? ? ? ? ? Objects.equals(end, work.end) && ? ? ? ? ? ? ? ? Objects.equals(company, work.company) && ? ? ? ? ? ? ? ? Objects.equals(job, work.job) && ? ? ? ? ? ? ? ? Objects.equals(description, work.description) && ? ? ? ? ? ? ? ? Objects.equals(next, work.next); ? ? } ? ? ? @Override ? ? public int hashCode() { ? ? ? ? return Objects.hash(id, userId, start, end, company, job, description, next); ? ? } ? ? ? @Override ? ? public String toString() { ? ? ? ? return "Work{" + ? ? ? ? ? ? ? ? "id=" + id + ? ? ? ? ? ? ? ? ", userId=" + userId + ? ? ? ? ? ? ? ? ", start='" + start + '\'' + ? ? ? ? ? ? ? ? ", end='" + end + '\'' + ? ? ? ? ? ? ? ? ", company='" + company + '\'' + ? ? ? ? ? ? ? ? ", job='" + job + '\'' + ? ? ? ? ? ? ? ? ", description='" + description + '\'' + ? ? ? ? ? ? ? ? ", next=" + next + ? ? ? ? ? ? ? ? '}'; ? ? } ? ? ? public Work(int id, int userId, String start, String end, String company, String job, String description, Work next) { ? ? ? ? this.id = id; ? ? ? ? this.userId = userId; ? ? ? ? this.start = start; ? ? ? ? this.end = end; ? ? ? ? this.company = company; ? ? ? ? this.job = job; ? ? ? ? this.description = description; ? ? ? ? this.next = next; ? ? } ? ? ? public Work() { ? ? } ? ? ? public static void main(String[] args) { ? ? ? ? Work work = new Work(); ? ? ? ? Work work1 = new Work(1,2,"","","","","",work); ? ? ? ? System.out.println(work1.toString()); ? ? } } import java.util.Objects; ? public class User { ? ? ? public void setId(int id) { ? ? ? ? this.id = id; ? ? } ? ? ? public void setName(String name) { ? ? ? ? this.name = name; ? ? } ? ? ? public void setAge(int age) { ? ? ? ? this.age = age; ? ? } ? ? ? public void setCity(String city) { ? ? ? ? this.city = city; ? ? } ? ? ? public void setAddress(String address) { ? ? ? ? this.address = address; ? ? } ? ? ? public void setEmail(String email) { ? ? ? ? this.email = email; ? ? } ? ? ? public void setPhone(String phone) { ? ? ? ? this.phone = phone; ? ? } ? ? ? public void setWeixin(String weixin) { ? ? ? ? this.weixin = weixin; ? ? } ? ? ? public void setQq(String qq) { ? ? ? ? this.qq = qq; ? ? } ? ? ? public void setWeibo(String weibo) { ? ? ? ? this.weibo = weibo; ? ? } ? ? ? public void setSex(String sex) { ? ? ? ? this.sex = sex; ? ? } ? ? ? public void setDescription(String description) { ? ? ? ? this.description = description; ? ? } ? ? ? //用戶編號 ? ? private int id; ? ? //用戶姓名 ? ? private String name; ? ? //年齡 ? ? private int age; ? ? //城市 ? ? private String city; ? ? //詳細(xì)住址 ? ? private String address; ? ? //郵箱 ? ? private String email; ? ? //電話 ? ? private String phone; ? ? //微信 ? ? private String weixin; ? ? //qq ? ? private String qq; ? ? //微博 ? ? private String weibo; ? ? //性別 ? ? private String sex; ? ? //簡介 ? ? private String description; ? ? ? public User(String name, int age, String city, String address, String email, String phone, String weixin, String qq, String weibo, String sex, String description) { ? ? ? ? this.name = name; ? ? ? ? this.age = age; ? ? ? ? this.city = city; ? ? ? ? this.address = address; ? ? ? ? this.email = email; ? ? ? ? this.phone = phone; ? ? ? ? this.weixin = weixin; ? ? ? ? this.qq = qq; ? ? ? ? this.weibo = weibo; ? ? ? ? this.sex = sex; ? ? ? ? this.description = description; ? ? } ? ? ? public int getId() { ? ? ? ? return id; ? ? } ? ? ? public String getName() { ? ? ? ? return name; ? ? } ? ? ? public int getAge() { ? ? ? ? return age; ? ? } ? ? ? public String getCity() { ? ? ? ? return city; ? ? } ? ? ? public String getAddress() { ? ? ? ? return address; ? ? } ? ? ? public String getEmail() { ? ? ? ? return email; ? ? } ? ? ? public String getPhone() { ? ? ? ? return phone; ? ? } ? ? ? public String getWeixin() { ? ? ? ? return weixin; ? ? } ? ? ? public String getQq() { ? ? ? ? return qq; ? ? } ? ? ? public String getWeibo() { ? ? ? ? return weibo; ? ? } ? ? ? public String getSex() { ? ? ? ? return sex; ? ? } ? ? ? public String getDescription() { ? ? ? ? return description; ? ? } ? ? ? @Override ? ? public boolean equals(Object o) { ? ? ? ? if (this == o) return true; ? ? ? ? if (o == null || getClass() != o.getClass()) return false; ? ? ? ? User user = (User) o; ? ? ? ? return id == user.id && ? ? ? ? ? ? ? ? age == user.age && ? ? ? ? ? ? ? ? Objects.equals(name, user.name) && ? ? ? ? ? ? ? ? Objects.equals(city, user.city) && ? ? ? ? ? ? ? ? Objects.equals(address, user.address) && ? ? ? ? ? ? ? ? Objects.equals(email, user.email) && ? ? ? ? ? ? ? ? Objects.equals(phone, user.phone) && ? ? ? ? ? ? ? ? Objects.equals(weixin, user.weixin) && ? ? ? ? ? ? ? ? Objects.equals(qq, user.qq) && ? ? ? ? ? ? ? ? Objects.equals(weibo, user.weibo) && ? ? ? ? ? ? ? ? Objects.equals(sex, user.sex) && ? ? ? ? ? ? ? ? Objects.equals(description, user.description); ? ? } ? ? ? @Override ? ? public int hashCode() { ? ? ? ? return Objects.hash(id, name, age, city, address, email, phone, weixin, qq, weibo, sex, description); ? ? } ? ? ? @Override ? ? public String toString() { ? ? ? ? return "User{" + ? ? ? ? ? ? ? ? "id=" + id + ? ? ? ? ? ? ? ? ", name='" + name + '\'' + ? ? ? ? ? ? ? ? ", age=" + age + ? ? ? ? ? ? ? ? ", city='" + city + '\'' + ? ? ? ? ? ? ? ? ", address='" + address + '\'' + ? ? ? ? ? ? ? ? ", email='" + email + '\'' + ? ? ? ? ? ? ? ? ", phone='" + phone + '\'' + ? ? ? ? ? ? ? ? ", weixin='" + weixin + '\'' + ? ? ? ? ? ? ? ? ", qq='" + qq + '\'' + ? ? ? ? ? ? ? ? ", weibo='" + weibo + '\'' + ? ? ? ? ? ? ? ? ", sex='" + sex + '\'' + ? ? ? ? ? ? ? ? ", description='" + description + '\'' + ? ? ? ? ? ? ? ? '}'; ? ? } ? ? ? public User() { ? ? } ? ? ? public User(int id, String name, int age, String city, String address, String email, String phone, String weixin, String qq, String weibo, String sex, String description) { ? ? ? ? this.id = id; ? ? ? ? this.name = name; ? ? ? ? this.age = age; ? ? ? ? this.city = city; ? ? ? ? this.address = address; ? ? ? ? this.email = email; ? ? ? ? this.phone = phone; ? ? ? ? this.weixin = weixin; ? ? ? ? this.qq = qq; ? ? ? ? this.weibo = weibo; ? ? ? ? this.sex = sex; ? ? ? ? this.description = description; ? ? } ? ? ? ? ? public static void main(String[] args) { ? ? ? ? User user = new User(1,"",20,"山西","太原","","","","","","",""); ? ? ? ? System.out.println(user.toString()); ? ? } ? ? } import java.util.Objects; ? public class Specialty { ? ? private int id; ? ? private int userId; ? ? private String name; ? ? private String description; ? ? private Specialty next; ? ? ? public Specialty(int id, int userId, String name, String description) { ? ? ? ? this.id = id; ? ? ? ? this.userId = userId; ? ? ? ? this.name = name; ? ? ? ? this.description = description; ? ? } ? ? ? public Specialty(int userId, String name, String description) { ? ? ? ? this.userId = userId; ? ? ? ? this.name = name; ? ? ? ? this.description = description; ? ? } ? ? ? @Override ? ? public String toString() { ? ? ? ? return "Specialty{" + ? ? ? ? ? ? ? ? "id=" + id + ? ? ? ? ? ? ? ? ", userId=" + userId + ? ? ? ? ? ? ? ? ", name='" + name + '\'' + ? ? ? ? ? ? ? ? ", description='" + description + '\'' + ? ? ? ? ? ? ? ? ", next=" + next + ? ? ? ? ? ? ? ? '}'; ? ? } ? ? ? @Override ? ? public boolean equals(Object o) { ? ? ? ? if (this == o) return true; ? ? ? ? if (o == null || getClass() != o.getClass()) return false; ? ? ? ? Specialty specialty = (Specialty) o; ? ? ? ? return id == specialty.id && ? ? ? ? ? ? ? ? userId == specialty.userId && ? ? ? ? ? ? ? ? Objects.equals(name, specialty.name) && ? ? ? ? ? ? ? ? Objects.equals(description, specialty.description) && ? ? ? ? ? ? ? ? Objects.equals(next, specialty.next); ? ? } ? ? ? @Override ? ? public int hashCode() { ? ? ? ? return Objects.hash(id, userId, name, description, next); ? ? } ? ? ? public Specialty(int id, int userId, String name, String description, Specialty next) { ? ? ? ? this.id = id; ? ? ? ? this.userId = userId; ? ? ? ? this.name = name; ? ? ? ? this.description = description; ? ? ? ? this.next = next; ? ? } ? ? ? public int getId() { ? ? ? ? return id; ? ? } ? ? ? public void setId(int id) { ? ? ? ? this.id = id; ? ? } ? ? ? public int getUserId() { ? ? ? ? return userId; ? ? } ? ? ? public void setUserId(int userId) { ? ? ? ? this.userId = userId; ? ? } ? ? ? public String getName() { ? ? ? ? return name; ? ? } ? ? ? public void setName(String name) { ? ? ? ? this.name = name; ? ? } ? ? ? public String getDescription() { ? ? ? ? return description; ? ? } ? ? ? public void setDescription(String description) { ? ? ? ? this.description = description; ? ? } ? ? ? public Specialty getNext() { ? ? ? ? return next; ? ? } ? ? ? public void setNext(Specialty next) { ? ? ? ? this.next = next; ? ? } ? ? ? public Specialty() { ? ? } ? ? ? public static void main(String[] args) { ? ? ? ? Specialty sp = new Specialty(1,2,"",""); ? ? ? ? Specialty sp1 = new Specialty(2,3,"","",sp); ? ? ? ? System.out.println(sp1.toString()); ? ? } } import java.util.Objects; ? public class Skill { ? ? ? private int id; ? ? private int userId; ? ? private String keyWords; ? ? ? public int getId() { ? ? ? ? return id; ? ? } ? ? ? public void setId(int id) { ? ? ? ? this.id = id; ? ? } ? ? ? public int getUserId() { ? ? ? ? return userId; ? ? } ? ? ? public void setUserId(int userId) { ? ? ? ? this.userId = userId; ? ? } ? ? ? public String getKeyWords() { ? ? ? ? return keyWords; ? ? } ? ? ? public void setKeyWords(String keyWords) { ? ? ? ? this.keyWords = keyWords; ? ? } ? ? ? @Override ? ? public boolean equals(Object o) { ? ? ? ? if (this == o) return true; ? ? ? ? if (o == null || getClass() != o.getClass()) return false; ? ? ? ? Skill skill = (Skill) o; ? ? ? ? return id == skill.id && ? ? ? ? ? ? ? ? userId == skill.userId && ? ? ? ? ? ? ? ? Objects.equals(keyWords, skill.keyWords); ? ? } ? ? ? @Override ? ? public int hashCode() { ? ? ? ? return Objects.hash(id, userId, keyWords); ? ? } ? ? ? @Override ? ? public String toString() { ? ? ? ? return "Skill{" + ? ? ? ? ? ? ? ? "id=" + id + ? ? ? ? ? ? ? ? ", userId=" + userId + ? ? ? ? ? ? ? ? ", keyWords='" + keyWords + '\'' + ? ? ? ? ? ? ? ? '}'; ? ? } ? ? ? public Skill(int userId, String keyWords) { ? ? ? ? this.userId = userId; ? ? ? ? this.keyWords = keyWords; ? ? } ? ? ? public Skill(int id, int userId, String keyWords) { ? ? ? ? this.id = id; ? ? ? ? this.userId = userId; ? ? ? ? this.keyWords = keyWords; ? ? } ? ? ? public Skill() { ? ? } ? ? ? public static void main(String[] args) { ? ? ? ? Skill skill = new Skill(1,2,""); ? ? ? ? System.out.println(skill.toString()); ? ? } } import java.util.Objects; ? public class Info { ? ? private User user; ? ? private Edu edu; ? ? private Skill skill; ? ? private Work work; ? ? private Specialty specialty; ? ? ? @Override ? ? public boolean equals(Object o) { ? ? ? ? if (this == o) return true; ? ? ? ? if (o == null || getClass() != o.getClass()) return false; ? ? ? ? Info info = (Info) o; ? ? ? ? return Objects.equals(user, info.user) && ? ? ? ? ? ? ? ? Objects.equals(edu, info.edu) && ? ? ? ? ? ? ? ? Objects.equals(skill, info.skill) && ? ? ? ? ? ? ? ? Objects.equals(work, info.work) && ? ? ? ? ? ? ? ? Objects.equals(specialty, info.specialty); ? ? } ? ? ? @Override ? ? public int hashCode() { ? ? ? ? return Objects.hash(user, edu, skill, work, specialty); ? ? } ? ? ? @Override ? ? public String toString() { ? ? ? ? return "Info{" + ? ? ? ? ? ? ? ? "user=" + user + ? ? ? ? ? ? ? ? ", edu=" + edu + ? ? ? ? ? ? ? ? ", skill=" + skill + ? ? ? ? ? ? ? ? ", work=" + work + ? ? ? ? ? ? ? ? ", specialty=" + specialty + ? ? ? ? ? ? ? ? '}'; ? ? } ? ? ? public Info(User user, Edu edu, Skill skill, Work work, Specialty specialty) { ? ? ? ? this.user = user; ? ? ? ? this.edu = edu; ? ? ? ? this.skill = skill; ? ? ? ? this.work = work; ? ? ? ? this.specialty = specialty; ? ? } ? ? ? public Info() { ? ? } ? ? ? public static void main(String[] args) { ? ? ? ? User user = new User(); ? ? ? ? Edu edu = new Edu(); ? ? ? ? Skill skill = new Skill(); ? ? ? ? Work work = new Work(); ? ? ? ? Specialty specialty = new Specialty(); ? ? ? ? Info info = new Info(user,edu,skill,work,specialty); ? ? ? ? System.out.println(info.toString()); ? ? ? } } import jdk.nashorn.internal.runtime.JSONFunctions; ? import java.util.Objects; ? public class Result { ? ? ? ? ? private int status; ? ? private String msg; ? ? private Object data; ? ? ? public Result(int status, String msg) { ? ? ? ? this.status = status; ? ? ? ? this.msg = msg; ? ? } ? ? ? @Override ? ? public boolean equals(Object o) { ? ? ? ? if (this == o) return true; ? ? ? ? if (o == null || getClass() != o.getClass()) return false; ? ? ? ? Result result = (Result) o; ? ? ? ? return status == result.status && ? ? ? ? ? ? ? ? Objects.equals(msg, result.msg) && ? ? ? ? ? ? ? ? Objects.equals(data, result.data); ? ? } ? ? ? @Override ? ? public int hashCode() { ? ? ? ? return Objects.hash(status, msg, data); ? ? } ? ? ? public Result(int status, String msg, Object data) { ? ? ? ? this.status = status; ? ? ? ? this.msg = msg; ? ? ? ? this.data = data; ? ? } ? ? ? public Result() { ? ? } ? ? ? public int getStatus() { ? ? ? ? return status; ? ? } ? ? ? public void setStatus(int status) { ? ? ? ? this.status = status; ? ? } ? ? ? public String getMsg() { ? ? ? ? return msg; ? ? } ? ? ? public void setMsg(String msg) { ? ? ? ? this.msg = msg; ? ? } ? ? ? public Object getData() { ? ? ? ? return data; ? ? } ? ? ? public void setData(Object data) { ? ? ? ? this.data = data; ? ? } ? ? ? ? public static void main(String[] args) { ? ? ? ? Result re = new Result(1,"", 1); ? ? ? ? System.out.println(re.toString()); ? ? } } 柚子快報邀請碼778899分享:算法 1.24實(shí)訓(xùn)` 參考閱讀
本文內(nèi)容根據(jù)網(wǎng)絡(luò)資料整理,出于傳遞更多信息之目的,不代表金鑰匙跨境贊同其觀點(diǎn)和立場。
轉(zhuǎn)載請注明,如有侵權(quán),聯(lián)系刪除。