上传了实验三,已确认无敏感信息
This commit is contained in:
Executable
+18
@@ -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).
|
||||||
Executable
+21
@@ -0,0 +1,21 @@
|
|||||||
|
//Student.java
|
||||||
|
package test1;
|
||||||
|
|
||||||
|
public class Student {
|
||||||
|
int id;
|
||||||
|
int age;
|
||||||
|
int grade;
|
||||||
|
|
||||||
|
public void study() {
|
||||||
|
System.err.println("学号为" + id + "的学生正在学习");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void examination() {
|
||||||
|
System.err.println(id + "年级正在考试");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void tell() {
|
||||||
|
System.out.print("正在讲话的是一个" + age + "岁的学生");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Executable
+14
@@ -0,0 +1,14 @@
|
|||||||
|
//test.java
|
||||||
|
package test1;
|
||||||
|
|
||||||
|
public class test {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
Student s1 = new Student();
|
||||||
|
s1.id = 001;
|
||||||
|
s1.age = 18;
|
||||||
|
s1.grade = 1;
|
||||||
|
s1.study();
|
||||||
|
s1.examination();
|
||||||
|
s1.tell();
|
||||||
|
}
|
||||||
|
}
|
||||||
Executable
+16
@@ -0,0 +1,16 @@
|
|||||||
|
//Circle.java
|
||||||
|
package test2;
|
||||||
|
|
||||||
|
public class Circle {
|
||||||
|
double radius;
|
||||||
|
double area;
|
||||||
|
|
||||||
|
public void set(double radius) {
|
||||||
|
this.radius = radius;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void disaplay() {
|
||||||
|
area = radius * radius * 3.14;
|
||||||
|
System.err.println("This circle's radius is " + radius + ", area is " + area);
|
||||||
|
}
|
||||||
|
}
|
||||||
Executable
+21
@@ -0,0 +1,21 @@
|
|||||||
|
//Cone.java
|
||||||
|
package test2;
|
||||||
|
|
||||||
|
public class Cone {
|
||||||
|
double buttom;
|
||||||
|
double height;
|
||||||
|
|
||||||
|
public void set(double buttom, double height) {
|
||||||
|
this.buttom = buttom;
|
||||||
|
this.height = height;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Cone() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public void disaplay() {
|
||||||
|
System.out.println(
|
||||||
|
"This cone's buttom area is " + buttom + ", height is " + height + ", volume is "
|
||||||
|
+ buttom * height / 3);
|
||||||
|
}
|
||||||
|
}
|
||||||
Executable
+14
@@ -0,0 +1,14 @@
|
|||||||
|
//test.java
|
||||||
|
package test2;
|
||||||
|
|
||||||
|
public class test {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
Circle r1 = new Circle();
|
||||||
|
r1.set(3);
|
||||||
|
r1.disaplay();
|
||||||
|
Cone c1 = new Cone();
|
||||||
|
c1.set(28.26, 5);
|
||||||
|
c1.disaplay();
|
||||||
|
}
|
||||||
|
}
|
||||||
Executable
+33
@@ -0,0 +1,33 @@
|
|||||||
|
//Student.java
|
||||||
|
package test3;
|
||||||
|
|
||||||
|
public class Student {
|
||||||
|
private int age;
|
||||||
|
private String sex;
|
||||||
|
|
||||||
|
// setters
|
||||||
|
public void setAge(int age) {
|
||||||
|
if (age >= 0 & age <= 120) {
|
||||||
|
this.age = age;
|
||||||
|
} else {
|
||||||
|
this.age = 18;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSex(String sex) {
|
||||||
|
if ("男".equals(sex) || "女".equals(sex)) {
|
||||||
|
this.sex = sex;
|
||||||
|
} else {
|
||||||
|
this.sex = "保密";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// getters
|
||||||
|
public int getAge() {
|
||||||
|
return age;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSex() {
|
||||||
|
return sex;
|
||||||
|
}
|
||||||
|
}
|
||||||
Executable
+14
@@ -0,0 +1,14 @@
|
|||||||
|
//test.java
|
||||||
|
package test3;
|
||||||
|
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
public class test {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
Scanner input = new Scanner(System.in);
|
||||||
|
Student s1 = new Student();
|
||||||
|
s1.setAge(input.nextInt());
|
||||||
|
s1.setSex(input.next());
|
||||||
|
System.out.println("This student's age is " + s1.getAge() + ", gender is " + s1.getSex());
|
||||||
|
}
|
||||||
|
}
|
||||||
Executable
+20
@@ -0,0 +1,20 @@
|
|||||||
|
//Yard.java
|
||||||
|
package test4;
|
||||||
|
|
||||||
|
public class Yard {
|
||||||
|
double length;
|
||||||
|
double width;
|
||||||
|
|
||||||
|
public Yard(double length, double width) {
|
||||||
|
this.length = length;
|
||||||
|
this.width = width;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getPerimeter() {
|
||||||
|
return (length + width) * 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getAcreage() {
|
||||||
|
return length * width;
|
||||||
|
}
|
||||||
|
}
|
||||||
Executable
+12
@@ -0,0 +1,12 @@
|
|||||||
|
//test.java
|
||||||
|
package test4;
|
||||||
|
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
public class test {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
Scanner input = new Scanner(System.in);
|
||||||
|
Yard y1 = new Yard(input.nextDouble(), input.nextDouble());
|
||||||
|
System.err.println(y1.getPerimeter()+" "+y1.getAcreage());
|
||||||
|
}
|
||||||
|
}
|
||||||
Executable
+25
@@ -0,0 +1,25 @@
|
|||||||
|
//Employee.java
|
||||||
|
package test5;
|
||||||
|
|
||||||
|
public class Employee {
|
||||||
|
String name;
|
||||||
|
int age;
|
||||||
|
String dept;
|
||||||
|
static String company;
|
||||||
|
|
||||||
|
public void showInfos() {
|
||||||
|
System.out.println("name\t" + name);
|
||||||
|
System.out.println("age\t" + age);
|
||||||
|
System.out.println("dept\t" + dept);
|
||||||
|
System.out.println("company\t" + company);
|
||||||
|
System.out.println();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int compareAge(int age1, int age2) {
|
||||||
|
if (age1 > age2) {
|
||||||
|
return age1;
|
||||||
|
} else {
|
||||||
|
return age2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Executable
+19
@@ -0,0 +1,19 @@
|
|||||||
|
//test.java
|
||||||
|
package test5;
|
||||||
|
|
||||||
|
public class test {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
Employee e1 = new Employee();
|
||||||
|
e1.name = "Jack";
|
||||||
|
e1.age = 30;
|
||||||
|
e1.dept = "Software";
|
||||||
|
Employee.company = "XJIT.inc";
|
||||||
|
e1.showInfos();
|
||||||
|
Employee e2 = new Employee();
|
||||||
|
e2.name = "Mike";
|
||||||
|
e2.age = 45;
|
||||||
|
e2.dept = "Hardware";
|
||||||
|
e2.showInfos();
|
||||||
|
System.out.println("2个人中最大年龄是" + Employee.compareAge(e1.age, e2.age) + "岁。");
|
||||||
|
}
|
||||||
|
}
|
||||||
+7
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"java.project.sourcePaths": ["src"],
|
||||||
|
"java.project.outputPath": "bin",
|
||||||
|
"java.project.referencedLibraries": [
|
||||||
|
"lib/**/*.jar"
|
||||||
|
]
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user