public class Car {
String brand;
String color;
double price;
public Car() {
}
public Car(String brand, String color, double price) {
this.brand = brand;
this.color = color;
this.price = price;
}
@Override
public String toString() {
return "Car{" +
"brand='" + brand + '\'' +
", color='" + color + '\'' +
", price=" + price +
'}';
}
public static void main(String[] args) {
Car car=new Car();
car.toString();
Car car1=new Car("大众","白色",20);
car1.toString();
}
}
public class Car {
String brand;
String color;
double price;
public Car() {
}
public Car(String brand, String color, double price) {
this.brand = brand;
this.color = color;
this.price = price;
}
@Override
public String toString() {
return "Car{" +
"brand='" + brand + '\'' +
", color='" + color + '\'' +
", price=" + price +
'}';
}
public static void main(String[] args) {
Car car=new Car();
car.toString();
Car car1=new Car("大众","白色",20);
car1.toString();
}
}
package day03;
import java.util.Random;
public class DoubleColorBall {
public static void main(String[] args) {
int[] arr=new int[7];
Random random=new Random();
for (int i = 0; i < arr.length-1; i++) {
arr[i]=random.nextInt(33)+1;
for (int j = i-1; j >=0 ; j--) {
if (arr[i]==arr[j]){
i--;
break;
}
}
}
}
}
package day03;
import java.util.Objects;
public class Edu {
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() {
}
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;
}
public Edu(int id, int userId, String start, String end, String school, String study, String description) {
this.id = id;
this.userId = userId;
this.start = start;
this.end = end;
this.school = school;
this.study = study;
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 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;
}
@Override
public String toString() {
return "Edu{" +
"id=" + id +
", userId=" + userId +
", start='" + start + '\'' +
", end='" + end + '\'' +
", school='" + school + '\'' +
", study='" + study + '\'' +
", description='" + description + '\'' +
", next=" + next +
'}';
}
@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);
}
}
package day03;
public class Girl {
String name;
double age;
boolean bf;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getAge() {
return age;
}
public void setAge(double age) {
this.age = age;
}
public boolean isBf() {
return bf;
}
public void setBf(boolean bf) {
this.bf = bf;
}
public void show(){
System.out.println("姓名:"+name+",年龄:"+age+",是否有男朋友:"+bf);
}
public static void main(String[] args) {
Girl girl=new Girl();
girl.show();
girl.name="貂蝉";
girl.age=18;
girl.bf=true;
girl.show();;
}
}
package day03;
public class Info {
static User user;
static Edu edu;
static Skill skill;
static Work work;
static Specialty specialty;
public Info() {
}
public static User getUser() {
return user;
}
public static void setUser(User user) {
Info.user = user;
}
public static Edu getEdu() {
return edu;
}
public static void setEdu(Edu edu) {
Info.edu = edu;
}
public static Skill getSkill() {
return skill;
}
public static void setSkill(Skill skill) {
Info.skill = skill;
}
public static Work getWork() {
return work;
}
public static void setWork(Work work) {
Info.work = work;
}
public static Specialty getSpecialty() {
return specialty;
}
public static void setSpecialty(Specialty specialty) {
Info.specialty = specialty;
}
@Override
public String toString() {
return "Info{}";
}
}
package day03;
public class Method {
public int add(int a,int b){
return a+b;
}
public static void main(String[] args) {
Method m=new Method();
int sum=m.add(1,2);
System.out.println("sum="+sum);
}
}
package day03;
public class Person {
private String name;
private double age;
public Person() {}
public Person(String name, double age) {
this.name = name;
this.age = age;
}
public void show(){
System.out.println("姓名:"+name+",年龄:"+age);
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getAge() {
return age;
}
public void setAge(double age) {
if(age>0&&age<150){
this.age = age;
}else{
this.age =18;
System.out.println("你输入的年龄有误");
}
}
}
package day03;
//Ctrl+shift+t JUnit4
import org.junit.Test;
public class PersonTest {
@Test
public void test01(){
Person person=new Person();
person.show();
person.setName("张飞");
person.setAge(-1);
person.show();
Person person1=new Person("嫦娥",-1);
person1.show();
}
@Test
public void test02(){
Phone phone=new Phone();
phone.show();
}
}
package day03;
public class Phone {
String brand;
double price;
public void show(){
System.out.println("品牌:"+brand+",价格:"+price);
}
public Phone(){}
public Phone(String brand, double price) {
this.brand = brand;
this.price = price;
}
public static void main(String[] args) {
Phone p=new Phone();
p.show();
p.brand="Nokia";
p.price=598.5;
p.show();;
}
}
package day03;
public class Point {
int x;
int y;
public Point() {}
public Point(int x, int y) {
this.x = x;
this.y = y;
}
@Override
public String toString() {
return "Point{" +
"x=" + x +
", y=" + y +
'}';
}
public void add(){
x=x+1;
}
public void add(int t){
y=y+t;
}
public static void main(String[] args) {
Point point1=new Point();
Point point=new Point(1,2);
point.toString();
System.out.println("x="+point.x);
System.out.println("y="+point.y);
point.x=3;
point.y=4;
System.out.println("x="+point.x);
System.out.println("y="+point.y);
}
}
package day03;
public class Rectangle {
double length;
double width;
public double getArea(){
return length*width;
}
public double getPer(){
return 2*(length+width);
}
public String showAll() {
return "Rectangle{" +
"length=" + length +
", width=" + width +
'}';
}
public Rectangle(double length,double width) {
this.length = length;
this.width = width;
}
public static void main(String[] args) {
Rectangle rectangle=new Rectangle(2,1);
rectangle.showAll();
}
}
package day03;
import java.util.Objects;
public class Result {
private int status;
private String msg;
private Object data;
public Result() {
}
public Result(int status, String msg, Object data) {
this.status = status;
this.msg = msg;
this.data = data;
}
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;
}
@Override
public String toString() {
return "Result{" +
"status=" + status +
", msg='" + msg + '\'' +
", data=" + data +
'}';
}
@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);
}
}
package day03;
import java.util.Objects;
public class Skill {
private int id;
private int userId;
private String keyWords;
public Skill() {
}
public Skill(int id, String keyWords) {
this.id = id;
this.keyWords = 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 String toString() {
return "Skill{" +
"id=" + id +
", userId=" + userId +
", 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);
}
}
package day03;
import java.util.Objects;
public class Specialty {
private int id;
private int userId;
private String name;
private String description;
private Specialty next;
public Specialty() {
}
public Specialty(int userId, String name, String description) {
this.userId = userId;
this.name = name;
this.description = description;
}
public Specialty(int id, int userId, String name, String description) {
this.id = id;
this.userId = userId;
this.name = name;
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 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;
}
@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);
}
}
package day03;
import java.util.Objects;
public class User {
private int id;
//用户姓名
private String name;
//年龄
private int age;
//城市
private String city;
//详细住址
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() {
}
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 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 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;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getWeixin() {
return weixin;
}
public void setWeixin(String weixin) {
this.weixin = weixin;
}
public String getQq() {
return qq;
}
public void setQq(String qq) {
this.qq = qq;
}
public String getWeibo() {
return weibo;
}
public void setWeibo(String weibo) {
this.weibo = weibo;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = 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 + '\'' +
'}';
}
@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);
}
}
package day03;
public class Vehicle {
double speed;
String type;
public Vehicle(double speed, String type) {
this.speed = speed;
this.type = type;
}
public void move(){
}
public void setSpeed(double s){
}
public void speedUp(double s){
}
public void speedDown(double s){
}
@Override
public String toString() {
return "Vehicle{" +
"speed=" + speed +
", type='" + type + '\'' +
'}';
}
public static void main(String[] args) {
Vehicle v=new Vehicle(50,"大众");
v.toString();
}
}
package day03;
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;
private Work next;
public Work() {
}
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 String toString() {
return "Work{" +
"id=" + id +
", userId=" + userId +
", start='" + start + '\'' +
", end='" + end + '\'' +
", company='" + company + '\'' +
", job='" + job + '\'' +
", description='" + description + '\'' +
", 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);
}
}
java实训第三天
最新推荐文章于 2024-09-10 10:21:38 发布