圆JOB行为:画圆
保证数据安全性
命名:驼峰!
package com.java.two.demo; public class User { private String username; private String password; private String email; private String gender; private int age; public User() { } public User(String username, String password, String email, String gender, int age) { this.username = username; this.password = password; this.email = email; this.gender = gender; this.age = age; } /** * 获取 * @return username */ public String getUsername() { return username; } /** * 设置 * @param username */ public void setUsername(String username) { this.username = username; } /** * 获取 * @return password */ public String getPassword() { return password; } /** * 设置 * @param password */ public void setPassword(String password) { this.password = password; } /** * 获取 * @return email */ public String getEmail() { return email; } /** * 设置 * @param email */ public void setEmail(String email) { this.email = email; } /** * 获取 * @return gender */ public String getGender() { return gender; } /** * 设置 * @param gender */ public void setGender(String gender) { this.gender = gender; } /** * 获取 * @return age */ public int getAge() { return age; } /** * 设置 * @param age */ public void setAge(int age) { this.age = age; } public String toString() { return "User{username = " + username + ", password = " + password + ", email = " + email + ", gender = " + gender + ", age = " + age + "}"; }
练习,回合制
1,
package com.java.two.demo; import java.util.Random; public class Role { private String name; private int blood; public Role() { } public Role(String name, int blood) { this.name = name; this.blood = blood; } public String getName() { return name; } public void setName(String name) { this.name = name; } public int getBlood() { return blood; } public void setBlood(int blood) { this.blood = blood; } public void attack(Role role){ //随机伤害 Random r = new Random(); int hrut =r.nextInt(20)+1; int remainBlood=role.getBlood()-hrut; remainBlood=remainBlood<0?0:remainBlood; role.setBlood(remainBlood); System.out.println(this.getName()+"打了"+role.getName()+"一下,造成了"+hrut+"伤害,"+role.getName()+"还剩"+remainBlood+"点血"); } }
2,GameTest
package com.java.two.demo; public class GameTest { public static void main(String[] args) { Role r1 = new Role("张三",100); Role r2 = new Role("李四",100); //1>2 while (true) { r1.attack(r2); if (r2.getBlood()==0 || r2.getBlood() < 0){ System.out.println(r1.getName()+"ko了"+r2.getName()); break; } r2.attack(r1); if (r1.getBlood()==0 || r1.getBlood() < 0){ System.out.println(r2.getName()+"ko了"+r1.getName()); break; } } } }
数组练习
创建javabean
package Test; public class Car { private String brand; private int price; private String color; public Car() { } public Car(String brand, int price, String color) { this.brand = brand; this.price = price; this.color = color; } public String getBrand() { return brand; } public void setBrand(String brand) { this.brand = brand; } public int getPrice() { return price; } public void setPrice(int price) { this.price = price; } public String getColor() { return color; } public void setColor(String color) { this.color = color; } }
package Test; import java.util.Scanner; public class CarTest { public static void main(String[] args) { Car[] arr = new Car[3]; Scanner sc = new Scanner(System.in); for (int i = 0; i < arr.length; i++) { //创建车对象c1 Car c1 =new Car(); System.out.println("please input the brand of the car :"); String brand = sc.next(); c1.setBrand(brand); System.out.println("please input the price of the car:"); int price = sc.nextInt(); c1.setPrice(price); System.out.println("please input the color of the car :"); String color = sc.next(); c1.setColor(color); arr[i]=c1; } //遍历数组 for (int i = 0; i < arr.length; i++) { Car car =arr[i]; System.out.println(car.getBrand()+","+car.getPrice()+","+car.getColor()); } } }