把test.java救回来了
This commit is contained in:
+14
-14
@@ -1,14 +1,14 @@
|
||||
//Animal.java
|
||||
package Task1;
|
||||
|
||||
public class Animal {
|
||||
String name;
|
||||
|
||||
public Animal() {
|
||||
System.out.println("super");
|
||||
}
|
||||
|
||||
public void shout() {
|
||||
System.out.println(String.format("%s发出叫声", this.name));
|
||||
}
|
||||
}
|
||||
//Animal.java
|
||||
package Task1;
|
||||
|
||||
public class Animal {
|
||||
String name;
|
||||
|
||||
public Animal() {
|
||||
System.out.println("super");
|
||||
}
|
||||
|
||||
public void shout() {
|
||||
System.out.println(String.format("%s发出叫声", this.name));
|
||||
}
|
||||
}
|
||||
|
||||
+16
-16
@@ -1,16 +1,16 @@
|
||||
//Dog.java
|
||||
package Task1;
|
||||
|
||||
public class Dog extends Animal {
|
||||
public Dog() {
|
||||
super();
|
||||
}
|
||||
|
||||
public void shout() {
|
||||
System.out.println(String.format("%s发出汪汪叫", this.name));
|
||||
}
|
||||
|
||||
public void superShout() {
|
||||
super.shout();
|
||||
}
|
||||
}
|
||||
//Dog.java
|
||||
package Task1;
|
||||
|
||||
public class Dog extends Animal {
|
||||
public Dog() {
|
||||
super();
|
||||
}
|
||||
|
||||
public void shout() {
|
||||
System.out.println(String.format("%s发出汪汪叫", this.name));
|
||||
}
|
||||
|
||||
public void superShout() {
|
||||
super.shout();
|
||||
}
|
||||
}
|
||||
|
||||
+11
-11
@@ -1,11 +1,11 @@
|
||||
//Test.java
|
||||
package Task1;
|
||||
|
||||
public class Test {
|
||||
public static void main(String[] args) {
|
||||
Dog lucky = new Dog();
|
||||
lucky.name = "lucky";
|
||||
lucky.shout();
|
||||
lucky.superShout();
|
||||
}
|
||||
}
|
||||
//Test.java
|
||||
package Task1;
|
||||
|
||||
public class Test {
|
||||
public static void main(String[] args) {
|
||||
Dog lucky = new Dog();
|
||||
lucky.name = "lucky";
|
||||
lucky.shout();
|
||||
lucky.superShout();
|
||||
}
|
||||
}
|
||||
|
||||
+13
-13
@@ -1,13 +1,13 @@
|
||||
//Person.java
|
||||
package Task2;
|
||||
|
||||
public abstract class Person {
|
||||
String name;
|
||||
int age;
|
||||
|
||||
public Person() {
|
||||
System.out.println("super");
|
||||
}
|
||||
|
||||
public abstract void sayHello();
|
||||
}
|
||||
//Person.java
|
||||
package Task2;
|
||||
|
||||
public abstract class Person {
|
||||
String name;
|
||||
int age;
|
||||
|
||||
public Person() {
|
||||
System.out.println("super");
|
||||
}
|
||||
|
||||
public abstract void sayHello();
|
||||
}
|
||||
|
||||
+19
-19
@@ -1,19 +1,19 @@
|
||||
//Student.java
|
||||
package Task2;
|
||||
|
||||
public class Student extends Person {
|
||||
public Student() {
|
||||
super();
|
||||
}
|
||||
|
||||
public void sayHello() {
|
||||
System.out.println(String.format("大家好,我叫%s,今年%d岁,很高兴认识大家", this.name, this.age));
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
Student s1 = new Student();
|
||||
s1.name = "Jack";
|
||||
s1.age = 18;
|
||||
s1.sayHello();
|
||||
}
|
||||
}
|
||||
//Student.java
|
||||
package Task2;
|
||||
|
||||
public class Student extends Person {
|
||||
public Student() {
|
||||
super();
|
||||
}
|
||||
|
||||
public void sayHello() {
|
||||
System.out.println(String.format("大家好,我叫%s,今年%d岁,很高兴认识大家", this.name, this.age));
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
Student s1 = new Student();
|
||||
s1.name = "Jack";
|
||||
s1.age = 18;
|
||||
s1.sayHello();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,24 +1,24 @@
|
||||
//Rectangle.java
|
||||
package Task4;
|
||||
|
||||
public class Rectangle {
|
||||
public interface AreaRectangle {
|
||||
|
||||
}
|
||||
|
||||
private double x;
|
||||
private double y;
|
||||
|
||||
public Rectangle(double x, double y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
public double area() {
|
||||
return x * y;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "该长方形面积为" + this.area();
|
||||
}
|
||||
//Rectangle.java
|
||||
package Task4;
|
||||
|
||||
public class Rectangle {
|
||||
public interface AreaRectangle {
|
||||
|
||||
}
|
||||
|
||||
private double x;
|
||||
private double y;
|
||||
|
||||
public Rectangle(double x, double y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
public double area() {
|
||||
return x * y;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "该长方形面积为" + this.area();
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,9 @@
|
||||
//TestArea.java
|
||||
package Task4;
|
||||
|
||||
public class TestArea {
|
||||
public static void main(String[] args) {
|
||||
Rectangle r1 = new Rectangle(10.0, 20.0);
|
||||
System.out.println(r1.toString());
|
||||
}
|
||||
}
|
||||
//TestArea.java
|
||||
package Task4;
|
||||
|
||||
public class TestArea {
|
||||
public static void main(String[] args) {
|
||||
Rectangle r1 = new Rectangle(10.0, 20.0);
|
||||
System.out.println(r1.toString());
|
||||
}
|
||||
}
|
||||
|
||||
+10
-10
@@ -1,10 +1,10 @@
|
||||
//Person.java
|
||||
package Task5;
|
||||
|
||||
public abstract class Person {
|
||||
String name;
|
||||
String gender;
|
||||
String birthday;
|
||||
|
||||
public abstract void printInfo();
|
||||
}
|
||||
//Person.java
|
||||
package Task5;
|
||||
|
||||
public abstract class Person {
|
||||
String name;
|
||||
String gender;
|
||||
String birthday;
|
||||
|
||||
public abstract void printInfo();
|
||||
}
|
||||
|
||||
+17
-17
@@ -1,17 +1,17 @@
|
||||
//Student.java
|
||||
package Task5;
|
||||
|
||||
public class Student extends Person {
|
||||
String school;
|
||||
String id;
|
||||
String grade;
|
||||
|
||||
public void printInfo() {
|
||||
System.out.println("name:\t" + this.name);
|
||||
System.out.println("gender:\t" + this.gender);
|
||||
System.out.println("birthday:\t" + this.birthday);
|
||||
System.out.println("school:\t" + this.school);
|
||||
System.out.println("id:\t" + this.id);
|
||||
System.out.println("grade\t" + this.grade);
|
||||
}
|
||||
}
|
||||
//Student.java
|
||||
package Task5;
|
||||
|
||||
public class Student extends Person {
|
||||
String school;
|
||||
String id;
|
||||
String grade;
|
||||
|
||||
public void printInfo() {
|
||||
System.out.println("name:\t" + this.name);
|
||||
System.out.println("gender:\t" + this.gender);
|
||||
System.out.println("birthday:\t" + this.birthday);
|
||||
System.out.println("school:\t" + this.school);
|
||||
System.out.println("id:\t" + this.id);
|
||||
System.out.println("grade\t" + this.grade);
|
||||
}
|
||||
}
|
||||
|
||||
+15
-15
@@ -1,15 +1,15 @@
|
||||
//Teacher.java
|
||||
package Task5;
|
||||
|
||||
public class Teacher extends Person {
|
||||
String school;
|
||||
String id;
|
||||
|
||||
public void printInfo() {
|
||||
System.out.println("name:\t" + this.name);
|
||||
System.out.println("gender:\t" + this.gender);
|
||||
System.out.println("birthday:\t" + this.birthday);
|
||||
System.out.println("school:\t" + this.school);
|
||||
System.out.println("id:\t" + this.id);
|
||||
}
|
||||
}
|
||||
//Teacher.java
|
||||
package Task5;
|
||||
|
||||
public class Teacher extends Person {
|
||||
String school;
|
||||
String id;
|
||||
|
||||
public void printInfo() {
|
||||
System.out.println("name:\t" + this.name);
|
||||
System.out.println("gender:\t" + this.gender);
|
||||
System.out.println("birthday:\t" + this.birthday);
|
||||
System.out.println("school:\t" + this.school);
|
||||
System.out.println("id:\t" + this.id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,22 +1,22 @@
|
||||
//TestPerson.java
|
||||
package Task5;
|
||||
|
||||
public class TestPerson {
|
||||
public static void main(String[] args) {
|
||||
Student s1 = new Student();
|
||||
s1.name = "Jason Fate Chen";
|
||||
s1.gender = "male";
|
||||
s1.birthday = "May.5th.2005";
|
||||
s1.school = "XJIT";
|
||||
s1.id = "202301130071";
|
||||
s1.grade = "1";
|
||||
s1.printInfo();
|
||||
Teacher t1 = new Teacher();
|
||||
t1.name = "White";
|
||||
t1.gender = "female";
|
||||
t1.birthday = "Mar.7th.1993";
|
||||
t1.school = "Tsinghua";
|
||||
t1.id = "199303071145";
|
||||
t1.printInfo();
|
||||
}
|
||||
}
|
||||
//TestPerson.java
|
||||
package Task5;
|
||||
|
||||
public class TestPerson {
|
||||
public static void main(String[] args) {
|
||||
Student s1 = new Student();
|
||||
s1.name = "Jason Fate Chen";
|
||||
s1.gender = "male";
|
||||
s1.birthday = "May.5th.2005";
|
||||
s1.school = "XJIT";
|
||||
s1.id = "202301130071";
|
||||
s1.grade = "1";
|
||||
s1.printInfo();
|
||||
Teacher t1 = new Teacher();
|
||||
t1.name = "White";
|
||||
t1.gender = "female";
|
||||
t1.birthday = "Mar.7th.1993";
|
||||
t1.school = "Tsinghua";
|
||||
t1.id = "199303071145";
|
||||
t1.printInfo();
|
||||
}
|
||||
}
|
||||
|
||||
+128
-128
@@ -1,129 +1,129 @@
|
||||
package case1;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
public class Task1 {
|
||||
public static void main(String[] args) {
|
||||
Scanner sc = new Scanner(System.in);
|
||||
String dogName = sc.next();
|
||||
String dogSex = sc.next();
|
||||
String dogColor = sc.next();
|
||||
String catName = sc.next();
|
||||
String catSex = sc.next();
|
||||
double catWeight = sc.nextDouble();
|
||||
// 通过有参构造函数实例化Dog类对象dog
|
||||
// dog调用talk()方法
|
||||
// dog调用eat()方法
|
||||
/********* begin *********/
|
||||
Dog lucky = new Dog(dogName, dogSex, dogColor);
|
||||
lucky.talk();
|
||||
lucky.eat();
|
||||
/********* end *********/
|
||||
// 通过有参构造函数实例化Cat类对象cat
|
||||
// cat调用talk()方法
|
||||
// cat调用eat()方法
|
||||
/********* begin *********/
|
||||
Cat 哈基米 = new Cat(catName, catSex, catWeight);
|
||||
哈基米.talk();
|
||||
哈基米.eat();
|
||||
/********* end *********/
|
||||
}
|
||||
}
|
||||
|
||||
// 抽象类Pet 封装属性name和sex
|
||||
// 构造函数初始化name和sex
|
||||
// 声明抽象方法talk()
|
||||
// 声明抽象方法eat()
|
||||
abstract class Pet {
|
||||
/********* begin *********/
|
||||
protected String name;
|
||||
protected String sex;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getSex() {
|
||||
return sex;
|
||||
}
|
||||
|
||||
public void setSex(String sex) {
|
||||
this.sex = sex;
|
||||
}
|
||||
|
||||
public abstract void talk();
|
||||
|
||||
public abstract void eat();
|
||||
/********* end *********/
|
||||
}
|
||||
|
||||
// Dog类继承自Pet类 封装属性color
|
||||
// 构造函数初始化name、sex和color
|
||||
// 实现自己的talk()方法和eat()方法
|
||||
// talk()输出'名称:name,性别:sex,颜色:color,汪汪叫'
|
||||
// eat()输出'name吃骨头'
|
||||
class Dog extends Pet {
|
||||
/********* begin *********/
|
||||
private String color;
|
||||
|
||||
public String getColor() {
|
||||
return color;
|
||||
}
|
||||
|
||||
public void setColor(String color) {
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
public Dog(String name, String sex, String color) {
|
||||
this.name = name;
|
||||
this.sex = sex;
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
public void talk() {
|
||||
System.out.println("名称:" + this.name + ",性别:" + this.sex + ",颜色:" + this.color + ",汪汪叫");
|
||||
}
|
||||
|
||||
public void eat() {
|
||||
System.out.println(this.name + "吃骨头");
|
||||
}
|
||||
/********* end *********/
|
||||
}
|
||||
|
||||
// Cat类继承自Pet类 封装属性weight
|
||||
// 构造函数初始化name、sex和weight
|
||||
// 实现自己的talk()方法和eat()方法
|
||||
// talk()输出'名称:name,性别:sex,体重:weight kg,喵喵叫'
|
||||
// eat()输出'name吃鱼'
|
||||
class Cat extends Pet {
|
||||
/********* begin *********/
|
||||
private double weight;
|
||||
|
||||
public double getWeight() {
|
||||
return weight;
|
||||
}
|
||||
|
||||
public void setWeight(double weight) {
|
||||
this.weight = weight;
|
||||
}
|
||||
|
||||
public Cat(String name, String sex, double weight) {
|
||||
this.name = name;
|
||||
this.sex = sex;
|
||||
this.weight = weight;
|
||||
}
|
||||
|
||||
public void talk() {
|
||||
System.out.println("名称:" + this.name + ",性别:" + this.sex + ",体重:" + this.weight + " kg,喵喵叫");
|
||||
}
|
||||
|
||||
public void eat() {
|
||||
System.out.println(this.name + "吃鱼");
|
||||
}
|
||||
/********* end *********/
|
||||
|
||||
package case1;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
public class Task1 {
|
||||
public static void main(String[] args) {
|
||||
Scanner sc = new Scanner(System.in);
|
||||
String dogName = sc.next();
|
||||
String dogSex = sc.next();
|
||||
String dogColor = sc.next();
|
||||
String catName = sc.next();
|
||||
String catSex = sc.next();
|
||||
double catWeight = sc.nextDouble();
|
||||
// 通过有参构造函数实例化Dog类对象dog
|
||||
// dog调用talk()方法
|
||||
// dog调用eat()方法
|
||||
/********* begin *********/
|
||||
Dog lucky = new Dog(dogName, dogSex, dogColor);
|
||||
lucky.talk();
|
||||
lucky.eat();
|
||||
/********* end *********/
|
||||
// 通过有参构造函数实例化Cat类对象cat
|
||||
// cat调用talk()方法
|
||||
// cat调用eat()方法
|
||||
/********* begin *********/
|
||||
Cat 哈基米 = new Cat(catName, catSex, catWeight);
|
||||
哈基米.talk();
|
||||
哈基米.eat();
|
||||
/********* end *********/
|
||||
}
|
||||
}
|
||||
|
||||
// 抽象类Pet 封装属性name和sex
|
||||
// 构造函数初始化name和sex
|
||||
// 声明抽象方法talk()
|
||||
// 声明抽象方法eat()
|
||||
abstract class Pet {
|
||||
/********* begin *********/
|
||||
protected String name;
|
||||
protected String sex;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getSex() {
|
||||
return sex;
|
||||
}
|
||||
|
||||
public void setSex(String sex) {
|
||||
this.sex = sex;
|
||||
}
|
||||
|
||||
public abstract void talk();
|
||||
|
||||
public abstract void eat();
|
||||
/********* end *********/
|
||||
}
|
||||
|
||||
// Dog类继承自Pet类 封装属性color
|
||||
// 构造函数初始化name、sex和color
|
||||
// 实现自己的talk()方法和eat()方法
|
||||
// talk()输出'名称:name,性别:sex,颜色:color,汪汪叫'
|
||||
// eat()输出'name吃骨头'
|
||||
class Dog extends Pet {
|
||||
/********* begin *********/
|
||||
private String color;
|
||||
|
||||
public String getColor() {
|
||||
return color;
|
||||
}
|
||||
|
||||
public void setColor(String color) {
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
public Dog(String name, String sex, String color) {
|
||||
this.name = name;
|
||||
this.sex = sex;
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
public void talk() {
|
||||
System.out.println("名称:" + this.name + ",性别:" + this.sex + ",颜色:" + this.color + ",汪汪叫");
|
||||
}
|
||||
|
||||
public void eat() {
|
||||
System.out.println(this.name + "吃骨头");
|
||||
}
|
||||
/********* end *********/
|
||||
}
|
||||
|
||||
// Cat类继承自Pet类 封装属性weight
|
||||
// 构造函数初始化name、sex和weight
|
||||
// 实现自己的talk()方法和eat()方法
|
||||
// talk()输出'名称:name,性别:sex,体重:weight kg,喵喵叫'
|
||||
// eat()输出'name吃鱼'
|
||||
class Cat extends Pet {
|
||||
/********* begin *********/
|
||||
private double weight;
|
||||
|
||||
public double getWeight() {
|
||||
return weight;
|
||||
}
|
||||
|
||||
public void setWeight(double weight) {
|
||||
this.weight = weight;
|
||||
}
|
||||
|
||||
public Cat(String name, String sex, double weight) {
|
||||
this.name = name;
|
||||
this.sex = sex;
|
||||
this.weight = weight;
|
||||
}
|
||||
|
||||
public void talk() {
|
||||
System.out.println("名称:" + this.name + ",性别:" + this.sex + ",体重:" + this.weight + " kg,喵喵叫");
|
||||
}
|
||||
|
||||
public void eat() {
|
||||
System.out.println(this.name + "吃鱼");
|
||||
}
|
||||
/********* end *********/
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user