上传了实验四,已确认无敏感信息

This commit is contained in:
2024-06-10 16:42:32 +08:00
parent 2da90eeebf
commit c9d2aa581b
16 changed files with 324 additions and 0 deletions
+7
View File
@@ -0,0 +1,7 @@
{
"java.project.sourcePaths": ["src"],
"java.project.outputPath": "bin",
"java.project.referencedLibraries": [
"lib/**/*.jar"
]
}
+18
View File
@@ -0,0 +1,18 @@
## Getting Started
Welcome to the VS Code Java world. Here is a guideline to help you get started to write Java code in Visual Studio Code.
## Folder Structure
The workspace contains two folders by default, where:
- `src`: the folder to maintain sources
- `lib`: the folder to maintain dependencies
Meanwhile, the compiled output files will be generated in the `bin` folder by default.
> If you want to customize the folder structure, open `.vscode/settings.json` and update the related settings there.
## Dependency Management
The `JAVA PROJECTS` view allows you to manage your dependencies. More details can be found [here](https://github.com/microsoft/vscode-java-dependency#manage-dependencies).
View File
+14
View File
@@ -0,0 +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));
}
}
+16
View File
@@ -0,0 +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();
}
}
+11
View File
@@ -0,0 +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();
}
}
+13
View File
@@ -0,0 +1,13 @@
//Person.java
package Task2;
public abstract class Person {
String name;
int age;
public Person() {
System.out.println("super");
}
public abstract void sayHello();
}
+19
View File
@@ -0,0 +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();
}
}
+24
View File
@@ -0,0 +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();
}
}
+9
View File
@@ -0,0 +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());
}
}
+10
View File
@@ -0,0 +1,10 @@
//Person.java
package Task5;
public abstract class Person {
String name;
String gender;
String birthday;
public abstract void printInfo();
}
+17
View File
@@ -0,0 +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);
}
}
+15
View File
@@ -0,0 +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);
}
}
+22
View File
@@ -0,0 +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();
}
}
+129
View File
@@ -0,0 +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 *********/
}
View File