把test.java救回来了
This commit is contained in:
+26
-26
@@ -1,27 +1,27 @@
|
|||||||
判断题
|
判断题
|
||||||
错 错 对 对 错
|
错 错 对 对 错
|
||||||
错 对 对 对 错
|
错 对 对 对 错
|
||||||
错 错 对 错 对
|
错 错 对 错 对
|
||||||
对 错 对 对 对
|
对 错 对 对 对
|
||||||
填空题
|
填空题
|
||||||
21.
|
21.
|
||||||
if(x>0)
|
if(x>0)
|
||||||
y=1;
|
y=1;
|
||||||
22.
|
22.
|
||||||
public void main(String args[]){}
|
public void main(String args[]){}
|
||||||
23.
|
23.
|
||||||
PI=3.1415
|
PI=3.1415
|
||||||
24.
|
24.
|
||||||
finally
|
finally
|
||||||
25.
|
25.
|
||||||
numbers[numbers.lenth-1]=8.88
|
numbers[numbers.lenth-1]=8.88
|
||||||
26.
|
26.
|
||||||
Object
|
Object
|
||||||
27.
|
27.
|
||||||
私有方法
|
私有方法
|
||||||
28.
|
28.
|
||||||
类型安全
|
类型安全
|
||||||
29.
|
29.
|
||||||
JFrame
|
JFrame
|
||||||
30.
|
30.
|
||||||
传统的 for 循环
|
传统的 for 循环
|
||||||
@@ -1,21 +1,21 @@
|
|||||||
MIT License
|
MIT License
|
||||||
|
|
||||||
Copyright (c) 2024 msksbr
|
Copyright (c) 2024 msksbr
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
in the Software without restriction, including without limitation the rights
|
in the Software without restriction, including without limitation the rights
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
furnished to do so, subject to the following conditions:
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
The above copyright notice and this permission notice shall be included in all
|
||||||
copies or substantial portions of the Software.
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
SOFTWARE.
|
SOFTWARE.
|
||||||
|
|||||||
@@ -1,16 +1,16 @@
|
|||||||
# Java作业存放处
|
# Java作业存放处
|
||||||
|
|
||||||
这是一个专门拿来存放java课时作业的地方
|
这是一个专门拿来存放java课时作业的地方
|
||||||
|
|
||||||
不会用git的,想直接看代码
|
不会用git的,想直接看代码
|
||||||
[点这里](https://gitee.com/msksbr/java-homework/tree/master/)
|
[点这里](https://gitee.com/msksbr/java-homework/tree/master/)
|
||||||
|
|
||||||
以后我的代码都会放到这里,和我要代码的直接来仓库里找,会更新
|
以后我的代码都会放到这里,和我要代码的直接来仓库里找,会更新
|
||||||
|
|
||||||
帮忙点个免费的star呗
|
帮忙点个免费的star呗
|
||||||
|
|
||||||
😃☕
|
😃☕
|
||||||
|
|
||||||
[放个B站主页试试看](https://space.bilibili.com/521936200)
|
[放个B站主页试试看](https://space.bilibili.com/521936200)
|
||||||
|
|
||||||

|

|
||||||
|
|||||||
+16
-16
@@ -1,17 +1,17 @@
|
|||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
|
||||||
public class task1 {
|
public class task1 {
|
||||||
public static void main(String args[]) {
|
public static void main(String args[]) {
|
||||||
Scanner input = new Scanner(System.in);
|
Scanner input = new Scanner(System.in);
|
||||||
System.out.println("请输入第一个整数:");
|
System.out.println("请输入第一个整数:");
|
||||||
int a = input.nextInt();
|
int a = input.nextInt();
|
||||||
System.out.println("请输入第二个整数:");
|
System.out.println("请输入第二个整数:");
|
||||||
int b = input.nextInt();
|
int b = input.nextInt();
|
||||||
System.out.println("两数相加的结果为:" + (a + b));
|
System.out.println("两数相加的结果为:" + (a + b));
|
||||||
System.out.println("两数相减的结果为:" + (a - b));
|
System.out.println("两数相减的结果为:" + (a - b));
|
||||||
System.out.println("两数相乘的结果为:" + (a * b));
|
System.out.println("两数相乘的结果为:" + (a * b));
|
||||||
System.out.println("两数相除的结果为:" + (a / b));
|
System.out.println("两数相除的结果为:" + (a / b));
|
||||||
System.out.println("两数取余数的结果为:" + (a % b));
|
System.out.println("两数取余数的结果为:" + (a % b));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
+17
-17
@@ -1,17 +1,17 @@
|
|||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
|
||||||
public class task2 {
|
public class task2 {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
Scanner input = new Scanner(System.in);
|
Scanner input = new Scanner(System.in);
|
||||||
System.out.println("请输入一个数a:");
|
System.out.println("请输入一个数a:");
|
||||||
int a = input.nextInt();
|
int a = input.nextInt();
|
||||||
System.out.println("请输入一个数b:");
|
System.out.println("请输入一个数b:");
|
||||||
int b = input.nextInt();
|
int b = input.nextInt();
|
||||||
System.out.println("a==b=" + (a == b));
|
System.out.println("a==b=" + (a == b));
|
||||||
System.out.println("a!=b=" + (a != b));
|
System.out.println("a!=b=" + (a != b));
|
||||||
System.out.println("a>b=" + (a > b));
|
System.out.println("a>b=" + (a > b));
|
||||||
System.out.println("a<b=" + (a < b));
|
System.out.println("a<b=" + (a < b));
|
||||||
System.out.println("b>=a=" + (b >= a));
|
System.out.println("b>=a=" + (b >= a));
|
||||||
System.out.println("b<=a=" + (b <= a));
|
System.out.println("b<=a=" + (b <= a));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+9
-9
@@ -1,9 +1,9 @@
|
|||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
|
||||||
public class task3 {
|
public class task3 {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
Scanner input = new Scanner(System.in);
|
Scanner input = new Scanner(System.in);
|
||||||
int year = input.nextInt();
|
int year = input.nextInt();
|
||||||
System.out.println(year + "年是否为闰年:" + ((year % 4 == 0) | (year % 400 == 0)));
|
System.out.println(year + "年是否为闰年:" + ((year % 4 == 0) | (year % 400 == 0)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+9
-9
@@ -1,9 +1,9 @@
|
|||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
|
||||||
public class task4 {
|
public class task4 {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
Scanner input = new Scanner(System.in);
|
Scanner input = new Scanner(System.in);
|
||||||
int num = input.nextInt();
|
int num = input.nextInt();
|
||||||
System.out.println((num / 100 + num/10-num/100*10 + num % 10));
|
System.out.println((num / 100 + num/10-num/100*10 + num % 10));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+18
-18
@@ -1,19 +1,19 @@
|
|||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
|
||||||
public class task1 {
|
public class task1 {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
Scanner input = new Scanner(System.in);
|
Scanner input = new Scanner(System.in);
|
||||||
double score = input.nextDouble();
|
double score = input.nextDouble();
|
||||||
if (score >= 90 & score <= 100) {
|
if (score >= 90 & score <= 100) {
|
||||||
System.out.println(4.0);
|
System.out.println(4.0);
|
||||||
} else if (score >= 80 & score < 90) {
|
} else if (score >= 80 & score < 90) {
|
||||||
System.out.println(3.5);
|
System.out.println(3.5);
|
||||||
} else if (score >= 70 && score < 80) {
|
} else if (score >= 70 && score < 80) {
|
||||||
System.out.println(3.0);
|
System.out.println(3.0);
|
||||||
} else if (score >= 60 && score < 70) {
|
} else if (score >= 60 && score < 70) {
|
||||||
System.out.println(2.5);
|
System.out.println(2.5);
|
||||||
} else {
|
} else {
|
||||||
System.out.println(0d);
|
System.out.println(0d);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+13
-13
@@ -1,13 +1,13 @@
|
|||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
|
||||||
public class task2 {
|
public class task2 {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
Scanner input = new Scanner(System.in);
|
Scanner input = new Scanner(System.in);
|
||||||
int goal = input.nextInt();
|
int goal = input.nextInt();
|
||||||
int mutied = 1;
|
int mutied = 1;
|
||||||
for (int i = 1; i <= goal; i++) {
|
for (int i = 1; i <= goal; i++) {
|
||||||
mutied *= i;
|
mutied *= i;
|
||||||
}
|
}
|
||||||
System.out.println(mutied);
|
System.out.println(mutied);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+32
-32
@@ -1,32 +1,32 @@
|
|||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
|
||||||
public class task3 {
|
public class task3 {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
Scanner input = new Scanner(System.in);
|
Scanner input = new Scanner(System.in);
|
||||||
System.out.println("星级成绩评定系统");
|
System.out.println("星级成绩评定系统");
|
||||||
System.out.print("请输入成绩:");
|
System.out.print("请输入成绩:");
|
||||||
double score = input.nextDouble();
|
double score = input.nextDouble();
|
||||||
int stars = 0;
|
int stars = 0;
|
||||||
String starHanzi;
|
String starHanzi;
|
||||||
if (score > 90) {
|
if (score > 90) {
|
||||||
stars = 5;
|
stars = 5;
|
||||||
starHanzi = "五";
|
starHanzi = "五";
|
||||||
} else if (score > 80 & score <= 90) {
|
} else if (score > 80 & score <= 90) {
|
||||||
stars = 4;
|
stars = 4;
|
||||||
starHanzi = "四";
|
starHanzi = "四";
|
||||||
} else if (score > 70 & score <= 80) {
|
} else if (score > 70 & score <= 80) {
|
||||||
stars = 3;
|
stars = 3;
|
||||||
starHanzi = "三";
|
starHanzi = "三";
|
||||||
} else if (score >= 60 & score <= 70) {
|
} else if (score >= 60 & score <= 70) {
|
||||||
stars = 2;
|
stars = 2;
|
||||||
starHanzi = "俩";
|
starHanzi = "俩";
|
||||||
} else {
|
} else {
|
||||||
stars=0;
|
stars=0;
|
||||||
starHanzi="无";
|
starHanzi="无";
|
||||||
}
|
}
|
||||||
for(int i=1;i<=stars;i++){
|
for(int i=1;i<=stars;i++){
|
||||||
System.out.print("*");
|
System.out.print("*");
|
||||||
}
|
}
|
||||||
System.out.println(starHanzi+"星成绩");
|
System.out.println(starHanzi+"星成绩");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+12
-12
@@ -1,13 +1,13 @@
|
|||||||
public class task4 {
|
public class task4 {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
int time = 0;
|
int time = 0;
|
||||||
for (int i = 1; i <= 100; i++) {
|
for (int i = 1; i <= 100; i++) {
|
||||||
if (i % 6 == 0) {
|
if (i % 6 == 0) {
|
||||||
System.out.print(i + " ");
|
System.out.print(i + " ");
|
||||||
time += 1;
|
time += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
System.out.println();
|
System.out.println();
|
||||||
System.out.println(time);
|
System.out.println(time);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+17
-17
@@ -1,17 +1,17 @@
|
|||||||
public class task5 {
|
public class task5 {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
for (int i = 1; i <= 10; i++) {
|
for (int i = 1; i <= 10; i++) {
|
||||||
for (int j = 1; j <= i; j++) {
|
for (int j = 1; j <= i; j++) {
|
||||||
System.out.print("*");
|
System.out.print("*");
|
||||||
}
|
}
|
||||||
System.out.println();
|
System.out.println();
|
||||||
}
|
}
|
||||||
System.out.println("-----------------我是华丽的分割线-----------------");
|
System.out.println("-----------------我是华丽的分割线-----------------");
|
||||||
for (int i = 10; i >= 1; i--) {
|
for (int i = 10; i >= 1; i--) {
|
||||||
for (int j = 1; j <= i; j++) {
|
for (int j = 1; j <= i; j++) {
|
||||||
System.out.print("*");
|
System.out.print("*");
|
||||||
}
|
}
|
||||||
System.out.println();
|
System.out.println();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+10
-10
@@ -1,10 +1,10 @@
|
|||||||
public class task6 {
|
public class task6 {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
for (int i = 1; i <= 9; i++) {
|
for (int i = 1; i <= 9; i++) {
|
||||||
for (int j = 1; j <= i; j++) {
|
for (int j = 1; j <= i; j++) {
|
||||||
System.out.print(i + "*" + j + "=" + i * j + "\t");
|
System.out.print(i + "*" + j + "=" + i * j + "\t");
|
||||||
}
|
}
|
||||||
System.out.println();
|
System.out.println();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Vendored
+7
-7
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"java.project.sourcePaths": ["src"],
|
"java.project.sourcePaths": ["src"],
|
||||||
"java.project.outputPath": "bin",
|
"java.project.outputPath": "bin",
|
||||||
"java.project.referencedLibraries": [
|
"java.project.referencedLibraries": [
|
||||||
"lib/**/*.jar"
|
"lib/**/*.jar"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
+18
-18
@@ -1,18 +1,18 @@
|
|||||||
## Getting Started
|
## 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.
|
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
|
## Folder Structure
|
||||||
|
|
||||||
The workspace contains two folders by default, where:
|
The workspace contains two folders by default, where:
|
||||||
|
|
||||||
- `src`: the folder to maintain sources
|
- `src`: the folder to maintain sources
|
||||||
- `lib`: the folder to maintain dependencies
|
- `lib`: the folder to maintain dependencies
|
||||||
|
|
||||||
Meanwhile, the compiled output files will be generated in the `bin` folder by default.
|
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.
|
> If you want to customize the folder structure, open `.vscode/settings.json` and update the related settings there.
|
||||||
|
|
||||||
## Dependency Management
|
## 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).
|
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).
|
||||||
|
|||||||
+21
-21
@@ -1,21 +1,21 @@
|
|||||||
//Student.java
|
//Student.java
|
||||||
package test1;
|
package test1;
|
||||||
|
|
||||||
public class Student {
|
public class Student {
|
||||||
int id;
|
int id;
|
||||||
int age;
|
int age;
|
||||||
int grade;
|
int grade;
|
||||||
|
|
||||||
public void study() {
|
public void study() {
|
||||||
System.err.println("学号为" + id + "的学生正在学习");
|
System.err.println("学号为" + id + "的学生正在学习");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void examination() {
|
public void examination() {
|
||||||
System.err.println(id + "年级正在考试");
|
System.err.println(id + "年级正在考试");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void tell() {
|
public void tell() {
|
||||||
System.out.print("正在讲话的是一个" + age + "岁的学生");
|
System.out.print("正在讲话的是一个" + age + "岁的学生");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+14
-14
@@ -1,14 +1,14 @@
|
|||||||
//test.java
|
//test.java
|
||||||
package test1;
|
package test1;
|
||||||
|
|
||||||
public class test {
|
public class test {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
Student s1 = new Student();
|
Student s1 = new Student();
|
||||||
s1.id = 001;
|
s1.id = 001;
|
||||||
s1.age = 18;
|
s1.age = 18;
|
||||||
s1.grade = 1;
|
s1.grade = 1;
|
||||||
s1.study();
|
s1.study();
|
||||||
s1.examination();
|
s1.examination();
|
||||||
s1.tell();
|
s1.tell();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+16
-16
@@ -1,16 +1,16 @@
|
|||||||
//Circle.java
|
//Circle.java
|
||||||
package test2;
|
package test2;
|
||||||
|
|
||||||
public class Circle {
|
public class Circle {
|
||||||
double radius;
|
double radius;
|
||||||
double area;
|
double area;
|
||||||
|
|
||||||
public void set(double radius) {
|
public void set(double radius) {
|
||||||
this.radius = radius;
|
this.radius = radius;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void disaplay() {
|
public void disaplay() {
|
||||||
area = radius * radius * 3.14;
|
area = radius * radius * 3.14;
|
||||||
System.err.println("This circle's radius is " + radius + ", area is " + area);
|
System.err.println("This circle's radius is " + radius + ", area is " + area);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+21
-21
@@ -1,21 +1,21 @@
|
|||||||
//Cone.java
|
//Cone.java
|
||||||
package test2;
|
package test2;
|
||||||
|
|
||||||
public class Cone {
|
public class Cone {
|
||||||
double buttom;
|
double buttom;
|
||||||
double height;
|
double height;
|
||||||
|
|
||||||
public void set(double buttom, double height) {
|
public void set(double buttom, double height) {
|
||||||
this.buttom = buttom;
|
this.buttom = buttom;
|
||||||
this.height = height;
|
this.height = height;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Cone() {
|
public Cone() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void disaplay() {
|
public void disaplay() {
|
||||||
System.out.println(
|
System.out.println(
|
||||||
"This cone's buttom area is " + buttom + ", height is " + height + ", volume is "
|
"This cone's buttom area is " + buttom + ", height is " + height + ", volume is "
|
||||||
+ buttom * height / 3);
|
+ buttom * height / 3);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+14
-14
@@ -1,14 +1,14 @@
|
|||||||
//test.java
|
//test.java
|
||||||
package test2;
|
package test2;
|
||||||
|
|
||||||
public class test {
|
public class test {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
Circle r1 = new Circle();
|
Circle r1 = new Circle();
|
||||||
r1.set(3);
|
r1.set(3);
|
||||||
r1.disaplay();
|
r1.disaplay();
|
||||||
Cone c1 = new Cone();
|
Cone c1 = new Cone();
|
||||||
c1.set(28.26, 5);
|
c1.set(28.26, 5);
|
||||||
c1.disaplay();
|
c1.disaplay();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+33
-33
@@ -1,33 +1,33 @@
|
|||||||
//Student.java
|
//Student.java
|
||||||
package test3;
|
package test3;
|
||||||
|
|
||||||
public class Student {
|
public class Student {
|
||||||
private int age;
|
private int age;
|
||||||
private String sex;
|
private String sex;
|
||||||
|
|
||||||
// setters
|
// setters
|
||||||
public void setAge(int age) {
|
public void setAge(int age) {
|
||||||
if (age >= 0 & age <= 120) {
|
if (age >= 0 & age <= 120) {
|
||||||
this.age = age;
|
this.age = age;
|
||||||
} else {
|
} else {
|
||||||
this.age = 18;
|
this.age = 18;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSex(String sex) {
|
public void setSex(String sex) {
|
||||||
if ("男".equals(sex) || "女".equals(sex)) {
|
if ("男".equals(sex) || "女".equals(sex)) {
|
||||||
this.sex = sex;
|
this.sex = sex;
|
||||||
} else {
|
} else {
|
||||||
this.sex = "保密";
|
this.sex = "保密";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// getters
|
// getters
|
||||||
public int getAge() {
|
public int getAge() {
|
||||||
return age;
|
return age;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getSex() {
|
public String getSex() {
|
||||||
return sex;
|
return sex;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+14
-14
@@ -1,14 +1,14 @@
|
|||||||
//test.java
|
//test.java
|
||||||
package test3;
|
package test3;
|
||||||
|
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
|
||||||
public class test {
|
public class test {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
Scanner input = new Scanner(System.in);
|
Scanner input = new Scanner(System.in);
|
||||||
Student s1 = new Student();
|
Student s1 = new Student();
|
||||||
s1.setAge(input.nextInt());
|
s1.setAge(input.nextInt());
|
||||||
s1.setSex(input.next());
|
s1.setSex(input.next());
|
||||||
System.out.println("This student's age is " + s1.getAge() + ", gender is " + s1.getSex());
|
System.out.println("This student's age is " + s1.getAge() + ", gender is " + s1.getSex());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+20
-20
@@ -1,20 +1,20 @@
|
|||||||
//Yard.java
|
//Yard.java
|
||||||
package test4;
|
package test4;
|
||||||
|
|
||||||
public class Yard {
|
public class Yard {
|
||||||
double length;
|
double length;
|
||||||
double width;
|
double width;
|
||||||
|
|
||||||
public Yard(double length, double width) {
|
public Yard(double length, double width) {
|
||||||
this.length = length;
|
this.length = length;
|
||||||
this.width = width;
|
this.width = width;
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getPerimeter() {
|
public double getPerimeter() {
|
||||||
return (length + width) * 2;
|
return (length + width) * 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getAcreage() {
|
public double getAcreage() {
|
||||||
return length * width;
|
return length * width;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+12
-12
@@ -1,12 +1,12 @@
|
|||||||
//test.java
|
//test.java
|
||||||
package test4;
|
package test4;
|
||||||
|
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
|
||||||
public class test {
|
public class test {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
Scanner input = new Scanner(System.in);
|
Scanner input = new Scanner(System.in);
|
||||||
Yard y1 = new Yard(input.nextDouble(), input.nextDouble());
|
Yard y1 = new Yard(input.nextDouble(), input.nextDouble());
|
||||||
System.err.println(y1.getPerimeter()+" "+y1.getAcreage());
|
System.err.println(y1.getPerimeter()+" "+y1.getAcreage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+25
-25
@@ -1,25 +1,25 @@
|
|||||||
//Employee.java
|
//Employee.java
|
||||||
package test5;
|
package test5;
|
||||||
|
|
||||||
public class Employee {
|
public class Employee {
|
||||||
String name;
|
String name;
|
||||||
int age;
|
int age;
|
||||||
String dept;
|
String dept;
|
||||||
static String company;
|
static String company;
|
||||||
|
|
||||||
public void showInfos() {
|
public void showInfos() {
|
||||||
System.out.println("name\t" + name);
|
System.out.println("name\t" + name);
|
||||||
System.out.println("age\t" + age);
|
System.out.println("age\t" + age);
|
||||||
System.out.println("dept\t" + dept);
|
System.out.println("dept\t" + dept);
|
||||||
System.out.println("company\t" + company);
|
System.out.println("company\t" + company);
|
||||||
System.out.println();
|
System.out.println();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int compareAge(int age1, int age2) {
|
public static int compareAge(int age1, int age2) {
|
||||||
if (age1 > age2) {
|
if (age1 > age2) {
|
||||||
return age1;
|
return age1;
|
||||||
} else {
|
} else {
|
||||||
return age2;
|
return age2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+19
-19
@@ -1,19 +1,19 @@
|
|||||||
//test.java
|
//test.java
|
||||||
package test5;
|
package test5;
|
||||||
|
|
||||||
public class test {
|
public class test {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
Employee e1 = new Employee();
|
Employee e1 = new Employee();
|
||||||
e1.name = "Jack";
|
e1.name = "Jack";
|
||||||
e1.age = 30;
|
e1.age = 30;
|
||||||
e1.dept = "Software";
|
e1.dept = "Software";
|
||||||
Employee.company = "XJIT.inc";
|
Employee.company = "XJIT.inc";
|
||||||
e1.showInfos();
|
e1.showInfos();
|
||||||
Employee e2 = new Employee();
|
Employee e2 = new Employee();
|
||||||
e2.name = "Mike";
|
e2.name = "Mike";
|
||||||
e2.age = 45;
|
e2.age = 45;
|
||||||
e2.dept = "Hardware";
|
e2.dept = "Hardware";
|
||||||
e2.showInfos();
|
e2.showInfos();
|
||||||
System.out.println("2个人中最大年龄是" + Employee.compareAge(e1.age, e2.age) + "岁。");
|
System.out.println("2个人中最大年龄是" + Employee.compareAge(e1.age, e2.age) + "岁。");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+14
-14
@@ -1,14 +1,14 @@
|
|||||||
//Animal.java
|
//Animal.java
|
||||||
package Task1;
|
package Task1;
|
||||||
|
|
||||||
public class Animal {
|
public class Animal {
|
||||||
String name;
|
String name;
|
||||||
|
|
||||||
public Animal() {
|
public Animal() {
|
||||||
System.out.println("super");
|
System.out.println("super");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void shout() {
|
public void shout() {
|
||||||
System.out.println(String.format("%s发出叫声", this.name));
|
System.out.println(String.format("%s发出叫声", this.name));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+16
-16
@@ -1,16 +1,16 @@
|
|||||||
//Dog.java
|
//Dog.java
|
||||||
package Task1;
|
package Task1;
|
||||||
|
|
||||||
public class Dog extends Animal {
|
public class Dog extends Animal {
|
||||||
public Dog() {
|
public Dog() {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void shout() {
|
public void shout() {
|
||||||
System.out.println(String.format("%s发出汪汪叫", this.name));
|
System.out.println(String.format("%s发出汪汪叫", this.name));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void superShout() {
|
public void superShout() {
|
||||||
super.shout();
|
super.shout();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+11
-11
@@ -1,11 +1,11 @@
|
|||||||
//Test.java
|
//Test.java
|
||||||
package Task1;
|
package Task1;
|
||||||
|
|
||||||
public class Test {
|
public class Test {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
Dog lucky = new Dog();
|
Dog lucky = new Dog();
|
||||||
lucky.name = "lucky";
|
lucky.name = "lucky";
|
||||||
lucky.shout();
|
lucky.shout();
|
||||||
lucky.superShout();
|
lucky.superShout();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+13
-13
@@ -1,13 +1,13 @@
|
|||||||
//Person.java
|
//Person.java
|
||||||
package Task2;
|
package Task2;
|
||||||
|
|
||||||
public abstract class Person {
|
public abstract class Person {
|
||||||
String name;
|
String name;
|
||||||
int age;
|
int age;
|
||||||
|
|
||||||
public Person() {
|
public Person() {
|
||||||
System.out.println("super");
|
System.out.println("super");
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract void sayHello();
|
public abstract void sayHello();
|
||||||
}
|
}
|
||||||
|
|||||||
+19
-19
@@ -1,19 +1,19 @@
|
|||||||
//Student.java
|
//Student.java
|
||||||
package Task2;
|
package Task2;
|
||||||
|
|
||||||
public class Student extends Person {
|
public class Student extends Person {
|
||||||
public Student() {
|
public Student() {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sayHello() {
|
public void sayHello() {
|
||||||
System.out.println(String.format("大家好,我叫%s,今年%d岁,很高兴认识大家", this.name, this.age));
|
System.out.println(String.format("大家好,我叫%s,今年%d岁,很高兴认识大家", this.name, this.age));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
Student s1 = new Student();
|
Student s1 = new Student();
|
||||||
s1.name = "Jack";
|
s1.name = "Jack";
|
||||||
s1.age = 18;
|
s1.age = 18;
|
||||||
s1.sayHello();
|
s1.sayHello();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,24 +1,24 @@
|
|||||||
//Rectangle.java
|
//Rectangle.java
|
||||||
package Task4;
|
package Task4;
|
||||||
|
|
||||||
public class Rectangle {
|
public class Rectangle {
|
||||||
public interface AreaRectangle {
|
public interface AreaRectangle {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private double x;
|
private double x;
|
||||||
private double y;
|
private double y;
|
||||||
|
|
||||||
public Rectangle(double x, double y) {
|
public Rectangle(double x, double y) {
|
||||||
this.x = x;
|
this.x = x;
|
||||||
this.y = y;
|
this.y = y;
|
||||||
}
|
}
|
||||||
|
|
||||||
public double area() {
|
public double area() {
|
||||||
return x * y;
|
return x * y;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "该长方形面积为" + this.area();
|
return "该长方形面积为" + this.area();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,9 +1,9 @@
|
|||||||
//TestArea.java
|
//TestArea.java
|
||||||
package Task4;
|
package Task4;
|
||||||
|
|
||||||
public class TestArea {
|
public class TestArea {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
Rectangle r1 = new Rectangle(10.0, 20.0);
|
Rectangle r1 = new Rectangle(10.0, 20.0);
|
||||||
System.out.println(r1.toString());
|
System.out.println(r1.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+10
-10
@@ -1,10 +1,10 @@
|
|||||||
//Person.java
|
//Person.java
|
||||||
package Task5;
|
package Task5;
|
||||||
|
|
||||||
public abstract class Person {
|
public abstract class Person {
|
||||||
String name;
|
String name;
|
||||||
String gender;
|
String gender;
|
||||||
String birthday;
|
String birthday;
|
||||||
|
|
||||||
public abstract void printInfo();
|
public abstract void printInfo();
|
||||||
}
|
}
|
||||||
|
|||||||
+17
-17
@@ -1,17 +1,17 @@
|
|||||||
//Student.java
|
//Student.java
|
||||||
package Task5;
|
package Task5;
|
||||||
|
|
||||||
public class Student extends Person {
|
public class Student extends Person {
|
||||||
String school;
|
String school;
|
||||||
String id;
|
String id;
|
||||||
String grade;
|
String grade;
|
||||||
|
|
||||||
public void printInfo() {
|
public void printInfo() {
|
||||||
System.out.println("name:\t" + this.name);
|
System.out.println("name:\t" + this.name);
|
||||||
System.out.println("gender:\t" + this.gender);
|
System.out.println("gender:\t" + this.gender);
|
||||||
System.out.println("birthday:\t" + this.birthday);
|
System.out.println("birthday:\t" + this.birthday);
|
||||||
System.out.println("school:\t" + this.school);
|
System.out.println("school:\t" + this.school);
|
||||||
System.out.println("id:\t" + this.id);
|
System.out.println("id:\t" + this.id);
|
||||||
System.out.println("grade\t" + this.grade);
|
System.out.println("grade\t" + this.grade);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+15
-15
@@ -1,15 +1,15 @@
|
|||||||
//Teacher.java
|
//Teacher.java
|
||||||
package Task5;
|
package Task5;
|
||||||
|
|
||||||
public class Teacher extends Person {
|
public class Teacher extends Person {
|
||||||
String school;
|
String school;
|
||||||
String id;
|
String id;
|
||||||
|
|
||||||
public void printInfo() {
|
public void printInfo() {
|
||||||
System.out.println("name:\t" + this.name);
|
System.out.println("name:\t" + this.name);
|
||||||
System.out.println("gender:\t" + this.gender);
|
System.out.println("gender:\t" + this.gender);
|
||||||
System.out.println("birthday:\t" + this.birthday);
|
System.out.println("birthday:\t" + this.birthday);
|
||||||
System.out.println("school:\t" + this.school);
|
System.out.println("school:\t" + this.school);
|
||||||
System.out.println("id:\t" + this.id);
|
System.out.println("id:\t" + this.id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,22 +1,22 @@
|
|||||||
//TestPerson.java
|
//TestPerson.java
|
||||||
package Task5;
|
package Task5;
|
||||||
|
|
||||||
public class TestPerson {
|
public class TestPerson {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
Student s1 = new Student();
|
Student s1 = new Student();
|
||||||
s1.name = "Jason Fate Chen";
|
s1.name = "Jason Fate Chen";
|
||||||
s1.gender = "male";
|
s1.gender = "male";
|
||||||
s1.birthday = "May.5th.2005";
|
s1.birthday = "May.5th.2005";
|
||||||
s1.school = "XJIT";
|
s1.school = "XJIT";
|
||||||
s1.id = "202301130071";
|
s1.id = "202301130071";
|
||||||
s1.grade = "1";
|
s1.grade = "1";
|
||||||
s1.printInfo();
|
s1.printInfo();
|
||||||
Teacher t1 = new Teacher();
|
Teacher t1 = new Teacher();
|
||||||
t1.name = "White";
|
t1.name = "White";
|
||||||
t1.gender = "female";
|
t1.gender = "female";
|
||||||
t1.birthday = "Mar.7th.1993";
|
t1.birthday = "Mar.7th.1993";
|
||||||
t1.school = "Tsinghua";
|
t1.school = "Tsinghua";
|
||||||
t1.id = "199303071145";
|
t1.id = "199303071145";
|
||||||
t1.printInfo();
|
t1.printInfo();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+128
-128
@@ -1,129 +1,129 @@
|
|||||||
package case1;
|
package case1;
|
||||||
|
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
|
||||||
public class Task1 {
|
public class Task1 {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
Scanner sc = new Scanner(System.in);
|
Scanner sc = new Scanner(System.in);
|
||||||
String dogName = sc.next();
|
String dogName = sc.next();
|
||||||
String dogSex = sc.next();
|
String dogSex = sc.next();
|
||||||
String dogColor = sc.next();
|
String dogColor = sc.next();
|
||||||
String catName = sc.next();
|
String catName = sc.next();
|
||||||
String catSex = sc.next();
|
String catSex = sc.next();
|
||||||
double catWeight = sc.nextDouble();
|
double catWeight = sc.nextDouble();
|
||||||
// 通过有参构造函数实例化Dog类对象dog
|
// 通过有参构造函数实例化Dog类对象dog
|
||||||
// dog调用talk()方法
|
// dog调用talk()方法
|
||||||
// dog调用eat()方法
|
// dog调用eat()方法
|
||||||
/********* begin *********/
|
/********* begin *********/
|
||||||
Dog lucky = new Dog(dogName, dogSex, dogColor);
|
Dog lucky = new Dog(dogName, dogSex, dogColor);
|
||||||
lucky.talk();
|
lucky.talk();
|
||||||
lucky.eat();
|
lucky.eat();
|
||||||
/********* end *********/
|
/********* end *********/
|
||||||
// 通过有参构造函数实例化Cat类对象cat
|
// 通过有参构造函数实例化Cat类对象cat
|
||||||
// cat调用talk()方法
|
// cat调用talk()方法
|
||||||
// cat调用eat()方法
|
// cat调用eat()方法
|
||||||
/********* begin *********/
|
/********* begin *********/
|
||||||
Cat 哈基米 = new Cat(catName, catSex, catWeight);
|
Cat 哈基米 = new Cat(catName, catSex, catWeight);
|
||||||
哈基米.talk();
|
哈基米.talk();
|
||||||
哈基米.eat();
|
哈基米.eat();
|
||||||
/********* end *********/
|
/********* end *********/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 抽象类Pet 封装属性name和sex
|
// 抽象类Pet 封装属性name和sex
|
||||||
// 构造函数初始化name和sex
|
// 构造函数初始化name和sex
|
||||||
// 声明抽象方法talk()
|
// 声明抽象方法talk()
|
||||||
// 声明抽象方法eat()
|
// 声明抽象方法eat()
|
||||||
abstract class Pet {
|
abstract class Pet {
|
||||||
/********* begin *********/
|
/********* begin *********/
|
||||||
protected String name;
|
protected String name;
|
||||||
protected String sex;
|
protected String sex;
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setName(String name) {
|
public void setName(String name) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getSex() {
|
public String getSex() {
|
||||||
return sex;
|
return sex;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSex(String sex) {
|
public void setSex(String sex) {
|
||||||
this.sex = sex;
|
this.sex = sex;
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract void talk();
|
public abstract void talk();
|
||||||
|
|
||||||
public abstract void eat();
|
public abstract void eat();
|
||||||
/********* end *********/
|
/********* end *********/
|
||||||
}
|
}
|
||||||
|
|
||||||
// Dog类继承自Pet类 封装属性color
|
// Dog类继承自Pet类 封装属性color
|
||||||
// 构造函数初始化name、sex和color
|
// 构造函数初始化name、sex和color
|
||||||
// 实现自己的talk()方法和eat()方法
|
// 实现自己的talk()方法和eat()方法
|
||||||
// talk()输出'名称:name,性别:sex,颜色:color,汪汪叫'
|
// talk()输出'名称:name,性别:sex,颜色:color,汪汪叫'
|
||||||
// eat()输出'name吃骨头'
|
// eat()输出'name吃骨头'
|
||||||
class Dog extends Pet {
|
class Dog extends Pet {
|
||||||
/********* begin *********/
|
/********* begin *********/
|
||||||
private String color;
|
private String color;
|
||||||
|
|
||||||
public String getColor() {
|
public String getColor() {
|
||||||
return color;
|
return color;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setColor(String color) {
|
public void setColor(String color) {
|
||||||
this.color = color;
|
this.color = color;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Dog(String name, String sex, String color) {
|
public Dog(String name, String sex, String color) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.sex = sex;
|
this.sex = sex;
|
||||||
this.color = color;
|
this.color = color;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void talk() {
|
public void talk() {
|
||||||
System.out.println("名称:" + this.name + ",性别:" + this.sex + ",颜色:" + this.color + ",汪汪叫");
|
System.out.println("名称:" + this.name + ",性别:" + this.sex + ",颜色:" + this.color + ",汪汪叫");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void eat() {
|
public void eat() {
|
||||||
System.out.println(this.name + "吃骨头");
|
System.out.println(this.name + "吃骨头");
|
||||||
}
|
}
|
||||||
/********* end *********/
|
/********* end *********/
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cat类继承自Pet类 封装属性weight
|
// Cat类继承自Pet类 封装属性weight
|
||||||
// 构造函数初始化name、sex和weight
|
// 构造函数初始化name、sex和weight
|
||||||
// 实现自己的talk()方法和eat()方法
|
// 实现自己的talk()方法和eat()方法
|
||||||
// talk()输出'名称:name,性别:sex,体重:weight kg,喵喵叫'
|
// talk()输出'名称:name,性别:sex,体重:weight kg,喵喵叫'
|
||||||
// eat()输出'name吃鱼'
|
// eat()输出'name吃鱼'
|
||||||
class Cat extends Pet {
|
class Cat extends Pet {
|
||||||
/********* begin *********/
|
/********* begin *********/
|
||||||
private double weight;
|
private double weight;
|
||||||
|
|
||||||
public double getWeight() {
|
public double getWeight() {
|
||||||
return weight;
|
return weight;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setWeight(double weight) {
|
public void setWeight(double weight) {
|
||||||
this.weight = weight;
|
this.weight = weight;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Cat(String name, String sex, double weight) {
|
public Cat(String name, String sex, double weight) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.sex = sex;
|
this.sex = sex;
|
||||||
this.weight = weight;
|
this.weight = weight;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void talk() {
|
public void talk() {
|
||||||
System.out.println("名称:" + this.name + ",性别:" + this.sex + ",体重:" + this.weight + " kg,喵喵叫");
|
System.out.println("名称:" + this.name + ",性别:" + this.sex + ",体重:" + this.weight + " kg,喵喵叫");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void eat() {
|
public void eat() {
|
||||||
System.out.println(this.name + "吃鱼");
|
System.out.println(this.name + "吃鱼");
|
||||||
}
|
}
|
||||||
/********* end *********/
|
/********* end *********/
|
||||||
|
|
||||||
}
|
}
|
||||||
+24
-24
@@ -1,25 +1,25 @@
|
|||||||
//Main.java
|
//Main.java
|
||||||
package task1;
|
package task1;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
public class Main {
|
public class Main {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
Scanner input = new Scanner(System.in);
|
Scanner input = new Scanner(System.in);
|
||||||
SimpleDateFormat in = new SimpleDateFormat("yyyy M dd");
|
SimpleDateFormat in = new SimpleDateFormat("yyyy M dd");
|
||||||
Date d = new Date();
|
Date d = new Date();
|
||||||
try {
|
try {
|
||||||
d = in.parse(input.nextLine());
|
d = in.parse(input.nextLine());
|
||||||
} catch (ParseException e) {
|
} catch (ParseException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
SimpleDateFormat out = new SimpleDateFormat("yyyy MMMM dd EEEE", Locale.ENGLISH);
|
SimpleDateFormat out = new SimpleDateFormat("yyyy MMMM dd EEEE", Locale.ENGLISH);
|
||||||
String formattedDate = out.format(d);
|
String formattedDate = out.format(d);
|
||||||
System.out.println("今天是" + out.format(d).toUpperCase());
|
System.out.println("今天是" + out.format(d).toUpperCase());
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+27
-27
@@ -1,27 +1,27 @@
|
|||||||
//Main.java
|
//Main.java
|
||||||
package task2;
|
package task2;
|
||||||
|
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
|
||||||
public class Main {
|
public class Main {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
Scanner input = new Scanner(System.in);
|
Scanner input = new Scanner(System.in);
|
||||||
Date inDate = new Date();
|
Date inDate = new Date();
|
||||||
SimpleDateFormat inFormat = new SimpleDateFormat("yyyy年M月d日", Locale.CHINA);
|
SimpleDateFormat inFormat = new SimpleDateFormat("yyyy年M月d日", Locale.CHINA);
|
||||||
System.out.print("请输入您家孩子的出生日期(格式为yyyy年M月d日):");
|
System.out.print("请输入您家孩子的出生日期(格式为yyyy年M月d日):");
|
||||||
try {
|
try {
|
||||||
inDate = inFormat.parse(input.nextLine());
|
inDate = inFormat.parse(input.nextLine());
|
||||||
} catch (ParseException e) {
|
} catch (ParseException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
long inTimeStamp = inDate.getTime();
|
long inTimeStamp = inDate.getTime();
|
||||||
long outTimeStamp = inTimeStamp + (long) 100 * 24 * 60 * 60 * 1000;
|
long outTimeStamp = inTimeStamp + (long) 100 * 24 * 60 * 60 * 1000;
|
||||||
Date outDate = new Date(outTimeStamp);
|
Date outDate = new Date(outTimeStamp);
|
||||||
SimpleDateFormat outFormat = new SimpleDateFormat("yyyy年M月dd日 EEEE", Locale.CHINA);
|
SimpleDateFormat outFormat = new SimpleDateFormat("yyyy年M月dd日 EEEE", Locale.CHINA);
|
||||||
System.out.println("经计算,您家孩子的百日宴应该设在" + outFormat.format(outDate));
|
System.out.println("经计算,您家孩子的百日宴应该设在" + outFormat.format(outDate));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,22 +1,22 @@
|
|||||||
package task3;
|
package task3;
|
||||||
|
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
|
||||||
public class StringLearning {
|
public class StringLearning {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
Scanner scanner = new Scanner(System.in);
|
Scanner scanner = new Scanner(System.in);
|
||||||
String stringExample = scanner.next();
|
String stringExample = scanner.next();
|
||||||
String endStr = " end";
|
String endStr = " end";
|
||||||
// ---------------------Begin------------------------
|
// ---------------------Begin------------------------
|
||||||
System.out.println(stringExample);// 1.输出原字符串
|
System.out.println(stringExample);// 1.输出原字符串
|
||||||
System.out.println(stringExample.length());// 2.求出字符串长度
|
System.out.println(stringExample.length());// 2.求出字符串长度
|
||||||
// 3.字符串转换成相应的大/小写
|
// 3.字符串转换成相应的大/小写
|
||||||
System.out.println(stringExample.toUpperCase());
|
System.out.println(stringExample.toUpperCase());
|
||||||
System.out.println(stringExample.toLowerCase());
|
System.out.println(stringExample.toLowerCase());
|
||||||
// 4.截取指定位置的字符串(3-7)
|
// 4.截取指定位置的字符串(3-7)
|
||||||
System.out.println(stringExample.substring(3, 7));
|
System.out.println(stringExample.substring(3, 7));
|
||||||
// 5.字符串相加具体输出要求请看测试说明。
|
// 5.字符串相加具体输出要求请看测试说明。
|
||||||
System.out.println(stringExample + endStr);
|
System.out.println(stringExample + endStr);
|
||||||
// ---------------------End------------------------
|
// ---------------------End------------------------
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+15
-15
@@ -1,15 +1,15 @@
|
|||||||
//Main.java
|
//Main.java
|
||||||
package task4;
|
package task4;
|
||||||
|
|
||||||
import java.lang.Math;
|
import java.lang.Math;
|
||||||
|
|
||||||
public class Main {
|
public class Main {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
double value1 = 2, value2 = 0;
|
double value1 = 2, value2 = 0;
|
||||||
System.out.println("绝对值:\t" + Math.abs(value1));
|
System.out.println("绝对值:\t" + Math.abs(value1));
|
||||||
System.out.println("3次幂:\t" + Math.pow(value1, 3));
|
System.out.println("3次幂:\t" + Math.pow(value1, 3));
|
||||||
System.out.println("二次方根:\t" + Math.pow(value1, 0.5));
|
System.out.println("二次方根:\t" + Math.pow(value1, 0.5));
|
||||||
System.out.println("sin值:\t" + Math.sin(value1));
|
System.out.println("sin值:\t" + Math.sin(value1));
|
||||||
System.out.println("较大者:\t" + Math.max(value1, value2));
|
System.out.println("较大者:\t" + Math.max(value1, value2));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+18
-18
@@ -1,18 +1,18 @@
|
|||||||
package task5;
|
package task5;
|
||||||
|
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
|
||||||
public class Roster {
|
public class Roster {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
Scanner scanner = new Scanner(System.in);
|
Scanner scanner = new Scanner(System.in);
|
||||||
/********** Begin *********/
|
/********** Begin *********/
|
||||||
String roster1 = "张三,李四,王五";
|
String roster1 = "张三,李四,王五";
|
||||||
String roster2 = scanner.nextLine();
|
String roster2 = scanner.nextLine();
|
||||||
if (roster1.equals(roster2)) {
|
if (roster1.equals(roster2)) {
|
||||||
System.out.println("相同");
|
System.out.println("相同");
|
||||||
} else {
|
} else {
|
||||||
System.out.println("不同");
|
System.out.println("不同");
|
||||||
}
|
}
|
||||||
/********** End *********/
|
/********** End *********/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+17
-17
@@ -1,18 +1,18 @@
|
|||||||
package task1;
|
package task1;
|
||||||
|
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
|
||||||
public class Task {
|
public class Task {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
Scanner sc = new Scanner(System.in);
|
Scanner sc = new Scanner(System.in);
|
||||||
int num1 = sc.nextInt();
|
int num1 = sc.nextInt();
|
||||||
int num2 = sc.nextInt();
|
int num2 = sc.nextInt();
|
||||||
/********* Begin *********/
|
/********* Begin *********/
|
||||||
try {
|
try {
|
||||||
System.out.println(num1 / num2);
|
System.out.println(num1 / num2);
|
||||||
} catch (java.lang.ArithmeticException e) {
|
} catch (java.lang.ArithmeticException e) {
|
||||||
System.out.println("除数不能为0");
|
System.out.println("除数不能为0");
|
||||||
}
|
}
|
||||||
/********* End *********/
|
/********* End *********/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+35
-35
@@ -1,35 +1,35 @@
|
|||||||
package task2;
|
package task2;
|
||||||
|
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
|
||||||
public class Task {
|
public class Task {
|
||||||
/********* Begin *********/
|
/********* Begin *********/
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
Scanner sc = new Scanner(System.in);
|
Scanner sc = new Scanner(System.in);
|
||||||
String username = sc.next();
|
String username = sc.next();
|
||||||
// 判断用户名
|
// 判断用户名
|
||||||
if (username.length() < 3) {
|
if (username.length() < 3) {
|
||||||
try {
|
try {
|
||||||
throw new MyException("用户名小于3位Exception");
|
throw new MyException("用户名小于3位Exception");
|
||||||
} catch (MyException e) {
|
} catch (MyException e) {
|
||||||
// TODO Auto-generated catch block
|
// TODO Auto-generated catch block
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
System.out.println("用户名格式正确");
|
System.out.println("用户名格式正确");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class MyException extends java.lang.Exception {
|
class MyException extends java.lang.Exception {
|
||||||
public MyException() {
|
public MyException() {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public MyException(String msg) {
|
public MyException(String msg) {
|
||||||
super(msg);
|
super(msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/********* End *********/
|
/********* End *********/
|
||||||
|
|||||||
+257
-257
@@ -1,258 +1,258 @@
|
|||||||
package task3;
|
package task3;
|
||||||
|
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
|
||||||
public class Task3 {
|
public class Task3 {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
Scanner sc = new Scanner(System.in);
|
Scanner sc = new Scanner(System.in);
|
||||||
String pppName = sc.next();
|
String pppName = sc.next();
|
||||||
int pppAge = sc.nextInt();
|
int pppAge = sc.nextInt();
|
||||||
String bpName = sc.next();
|
String bpName = sc.next();
|
||||||
int bpAge = sc.nextInt();
|
int bpAge = sc.nextInt();
|
||||||
String ppcName = sc.next();
|
String ppcName = sc.next();
|
||||||
int ppcAge = sc.nextInt();
|
int ppcAge = sc.nextInt();
|
||||||
String bcName = sc.next();
|
String bcName = sc.next();
|
||||||
int bcAge = sc.nextInt();
|
int bcAge = sc.nextInt();
|
||||||
// 测试运动员(乒乓球运动员和篮球运动员)
|
// 测试运动员(乒乓球运动员和篮球运动员)
|
||||||
// 乒乓球运动员
|
// 乒乓球运动员
|
||||||
// 通过带参构造函数实例化PingPangPlayer对象ppp
|
// 通过带参构造函数实例化PingPangPlayer对象ppp
|
||||||
// 输出'name---age'
|
// 输出'name---age'
|
||||||
// 分别调用sleep()、eat()、study()、speak()方法
|
// 分别调用sleep()、eat()、study()、speak()方法
|
||||||
/********* begin *********/
|
/********* begin *********/
|
||||||
PingPangPlayer ppp = new PingPangPlayer(pppName, pppAge);
|
PingPangPlayer ppp = new PingPangPlayer(pppName, pppAge);
|
||||||
System.out.println(ppp.getName() + "---" + ppp.getAge());
|
System.out.println(ppp.getName() + "---" + ppp.getAge());
|
||||||
ppp.sleep();
|
ppp.sleep();
|
||||||
ppp.eat();
|
ppp.eat();
|
||||||
ppp.study();
|
ppp.study();
|
||||||
ppp.speak();
|
ppp.speak();
|
||||||
/********* end *********/
|
/********* end *********/
|
||||||
System.out.println("----------------");
|
System.out.println("----------------");
|
||||||
// 篮球运动员
|
// 篮球运动员
|
||||||
// 通过带参构造函数实例化BasketballPlayer对象bp
|
// 通过带参构造函数实例化BasketballPlayer对象bp
|
||||||
// 输出'name---age'
|
// 输出'name---age'
|
||||||
// 分别调用sleep()、eat()、study()方法
|
// 分别调用sleep()、eat()、study()方法
|
||||||
/********* begin *********/
|
/********* begin *********/
|
||||||
BasketballPlayer bp = new BasketballPlayer(bpName, bpAge);
|
BasketballPlayer bp = new BasketballPlayer(bpName, bpAge);
|
||||||
System.out.println(bp.getName() + "---" + bp.getAge());
|
System.out.println(bp.getName() + "---" + bp.getAge());
|
||||||
bp.sleep();
|
bp.sleep();
|
||||||
bp.eat();
|
bp.eat();
|
||||||
bp.study();
|
bp.study();
|
||||||
/********* end *********/
|
/********* end *********/
|
||||||
System.out.println("----------------");
|
System.out.println("----------------");
|
||||||
// 测试教练(乒乓球教练和篮球教练)
|
// 测试教练(乒乓球教练和篮球教练)
|
||||||
// 乒乓球教练
|
// 乒乓球教练
|
||||||
// 通过带参构造函数实例化PingPangCoach对象ppc
|
// 通过带参构造函数实例化PingPangCoach对象ppc
|
||||||
// 输出'name---age'
|
// 输出'name---age'
|
||||||
// 分别调用sleep()、eat()、teach()、speak()方法
|
// 分别调用sleep()、eat()、teach()、speak()方法
|
||||||
/********* begin *********/
|
/********* begin *********/
|
||||||
PingPangCoach ppc = new PingPangCoach(ppcName, ppcAge);
|
PingPangCoach ppc = new PingPangCoach(ppcName, ppcAge);
|
||||||
System.out.println(ppc.getName() + "---" + ppc.getAge());
|
System.out.println(ppc.getName() + "---" + ppc.getAge());
|
||||||
ppc.sleep();
|
ppc.sleep();
|
||||||
ppc.eat();
|
ppc.eat();
|
||||||
ppc.teach();
|
ppc.teach();
|
||||||
ppc.speak();
|
ppc.speak();
|
||||||
/********* end *********/
|
/********* end *********/
|
||||||
System.out.println("----------------");
|
System.out.println("----------------");
|
||||||
// 篮球教练
|
// 篮球教练
|
||||||
// 通过带参构造函数实例化BasketballCoach对象bc
|
// 通过带参构造函数实例化BasketballCoach对象bc
|
||||||
// 输出'name---age'
|
// 输出'name---age'
|
||||||
// 分别调用sleep()、eat()、teach()方法
|
// 分别调用sleep()、eat()、teach()方法
|
||||||
/********* begin *********/
|
/********* begin *********/
|
||||||
BasketballCoach bc = new BasketballCoach(bcName, bcAge);
|
BasketballCoach bc = new BasketballCoach(bcName, bcAge);
|
||||||
System.out.println(bc.getName() + "---" + bc.getAge());
|
System.out.println(bc.getName() + "---" + bc.getAge());
|
||||||
bc.sleep();
|
bc.sleep();
|
||||||
bc.eat();
|
bc.eat();
|
||||||
bc.teach();
|
bc.teach();
|
||||||
/********* end *********/
|
/********* end *********/
|
||||||
System.out.println("----------------");
|
System.out.println("----------------");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 说英语接口 声明抽象方法speak()
|
// 说英语接口 声明抽象方法speak()
|
||||||
interface SpeakEnglish {
|
interface SpeakEnglish {
|
||||||
/********* begin *********/
|
/********* begin *********/
|
||||||
public abstract void speak();
|
public abstract void speak();
|
||||||
/********* end *********/
|
/********* end *********/
|
||||||
}
|
}
|
||||||
|
|
||||||
// 定义人的抽象类Person 封装name和age
|
// 定义人的抽象类Person 封装name和age
|
||||||
// 无参构造函数
|
// 无参构造函数
|
||||||
// 有参构造函数初始化name和age
|
// 有参构造函数初始化name和age
|
||||||
// 定义具体方法sleep() 输出'人都是要睡觉的'
|
// 定义具体方法sleep() 输出'人都是要睡觉的'
|
||||||
// 抽象方法eat()(吃的不一样)
|
// 抽象方法eat()(吃的不一样)
|
||||||
abstract class Person {
|
abstract class Person {
|
||||||
/********* begin *********/
|
/********* begin *********/
|
||||||
private String name;
|
private String name;
|
||||||
private int age;
|
private int age;
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setName(String name) {
|
public void setName(String name) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getAge() {
|
public int getAge() {
|
||||||
return age;
|
return age;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setAge(int age) {
|
public void setAge(int age) {
|
||||||
this.age = age;
|
this.age = age;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Person() {
|
public Person() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Person(String name, int age) {
|
public Person(String name, int age) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.age = age;
|
this.age = age;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sleep() {
|
public void sleep() {
|
||||||
System.out.println("人都是要睡觉的");
|
System.out.println("人都是要睡觉的");
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract void eat();
|
public abstract void eat();
|
||||||
/********* end *********/
|
/********* end *********/
|
||||||
}
|
}
|
||||||
|
|
||||||
// 定义运动员Player(抽象类)继承自Person类
|
// 定义运动员Player(抽象类)继承自Person类
|
||||||
// 无参构造函数
|
// 无参构造函数
|
||||||
// 有参构造函数初始化name和age
|
// 有参构造函数初始化name和age
|
||||||
// 运动员学习内容不一样,抽取为抽象 定义抽象方法study()
|
// 运动员学习内容不一样,抽取为抽象 定义抽象方法study()
|
||||||
abstract class Player extends Person {
|
abstract class Player extends Person {
|
||||||
/********* begin *********/
|
/********* begin *********/
|
||||||
public Player() {
|
public Player() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Player(String name, int age) {
|
public Player(String name, int age) {
|
||||||
super(name, age);
|
super(name, age);
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract void study();
|
public abstract void study();
|
||||||
/********* end *********/
|
/********* end *********/
|
||||||
}
|
}
|
||||||
|
|
||||||
// 定义教练Coach(抽象类)继承自Person类
|
// 定义教练Coach(抽象类)继承自Person类
|
||||||
// 无参构造函数
|
// 无参构造函数
|
||||||
// 有参构造函数初始化name和age
|
// 有参构造函数初始化name和age
|
||||||
// 教练教的不一样 定义抽象方法teach()
|
// 教练教的不一样 定义抽象方法teach()
|
||||||
abstract class Coach extends Person {
|
abstract class Coach extends Person {
|
||||||
/********* begin *********/
|
/********* begin *********/
|
||||||
public Coach() {
|
public Coach() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Coach(String name, int age) {
|
public Coach(String name, int age) {
|
||||||
super(name, age);
|
super(name, age);
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract void teach();
|
public abstract void teach();
|
||||||
/********* end *********/
|
/********* end *********/
|
||||||
}
|
}
|
||||||
|
|
||||||
// 定义乒乓球运动员具体类PingPangPlayer 继承自Player类并实现SpeakEnglish类(兵乓球运动员需要说英语)
|
// 定义乒乓球运动员具体类PingPangPlayer 继承自Player类并实现SpeakEnglish类(兵乓球运动员需要说英语)
|
||||||
// 无参构造函数
|
// 无参构造函数
|
||||||
// 有参构造函数初始化name和age
|
// 有参构造函数初始化name和age
|
||||||
// 实现自己的eat()方法 输出'乒乓球运动员吃大白菜,喝小米粥'
|
// 实现自己的eat()方法 输出'乒乓球运动员吃大白菜,喝小米粥'
|
||||||
// 实现自己的study()方法 输出'乒乓球运动员学习如何发球和接球'
|
// 实现自己的study()方法 输出'乒乓球运动员学习如何发球和接球'
|
||||||
// 实现自己的speak()方法 输出'乒乓球运动员说英语'
|
// 实现自己的speak()方法 输出'乒乓球运动员说英语'
|
||||||
class PingPangPlayer extends Player implements SpeakEnglish {
|
class PingPangPlayer extends Player implements SpeakEnglish {
|
||||||
/********* begin *********/
|
/********* begin *********/
|
||||||
public PingPangPlayer() {
|
public PingPangPlayer() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public PingPangPlayer(String name, int age) {
|
public PingPangPlayer(String name, int age) {
|
||||||
super(name, age);
|
super(name, age);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void eat() {
|
public void eat() {
|
||||||
System.out.println("乒乓球运动员吃大白菜,喝小米粥");
|
System.out.println("乒乓球运动员吃大白菜,喝小米粥");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void study() {
|
public void study() {
|
||||||
System.out.println("乒乓球运动员学习如何发球和接球");
|
System.out.println("乒乓球运动员学习如何发球和接球");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void speak() {
|
public void speak() {
|
||||||
System.out.println("乒乓球运动员说英语");
|
System.out.println("乒乓球运动员说英语");
|
||||||
}
|
}
|
||||||
/********* end *********/
|
/********* end *********/
|
||||||
}
|
}
|
||||||
|
|
||||||
// 定义篮球运动员具体类BasketballPlayer 继承自Player类 不需要继承接口,因为他不需要说英语
|
// 定义篮球运动员具体类BasketballPlayer 继承自Player类 不需要继承接口,因为他不需要说英语
|
||||||
// 无参构造函数
|
// 无参构造函数
|
||||||
// 有参构造函数初始化name和age
|
// 有参构造函数初始化name和age
|
||||||
// 实现自己的eat()方法 输出'篮球运动员吃牛肉,喝牛奶'
|
// 实现自己的eat()方法 输出'篮球运动员吃牛肉,喝牛奶'
|
||||||
// 实现自己的study()方法 输出'篮球运动员学习如何运球和投篮'
|
// 实现自己的study()方法 输出'篮球运动员学习如何运球和投篮'
|
||||||
class BasketballPlayer extends Player {
|
class BasketballPlayer extends Player {
|
||||||
/********* begin *********/
|
/********* begin *********/
|
||||||
public BasketballPlayer() {
|
public BasketballPlayer() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public BasketballPlayer(String name, int age) {
|
public BasketballPlayer(String name, int age) {
|
||||||
super(name, age);
|
super(name, age);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void eat() {
|
public void eat() {
|
||||||
System.out.println("篮球运动员吃牛肉,喝牛奶");
|
System.out.println("篮球运动员吃牛肉,喝牛奶");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void study() {
|
public void study() {
|
||||||
System.out.println("篮球运动员学习如何运球和投篮");
|
System.out.println("篮球运动员学习如何运球和投篮");
|
||||||
}
|
}
|
||||||
/********* end *********/
|
/********* end *********/
|
||||||
}
|
}
|
||||||
|
|
||||||
// 定义乒乓球教练具体类 PingPangCoach 继承自Coach类并实现SpeakEnglish类(兵乓球教练需要说英语)
|
// 定义乒乓球教练具体类 PingPangCoach 继承自Coach类并实现SpeakEnglish类(兵乓球教练需要说英语)
|
||||||
// 无参构造函数
|
// 无参构造函数
|
||||||
// 有参构造函数初始化name和age
|
// 有参构造函数初始化name和age
|
||||||
// 实现自己的eat()方法 输出'乒乓球教练吃小白菜,喝大米粥'
|
// 实现自己的eat()方法 输出'乒乓球教练吃小白菜,喝大米粥'
|
||||||
// 实现自己的teach()方法 输出'乒乓球教练教如何发球和接球'
|
// 实现自己的teach()方法 输出'乒乓球教练教如何发球和接球'
|
||||||
// 实现自己的speak()方法 输出'乒乓球教练说英语'
|
// 实现自己的speak()方法 输出'乒乓球教练说英语'
|
||||||
class PingPangCoach extends Coach implements SpeakEnglish {
|
class PingPangCoach extends Coach implements SpeakEnglish {
|
||||||
/********* begin *********/
|
/********* begin *********/
|
||||||
public PingPangCoach() {
|
public PingPangCoach() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public PingPangCoach(String name, int age) {
|
public PingPangCoach(String name, int age) {
|
||||||
super(name, age);
|
super(name, age);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void eat() {
|
public void eat() {
|
||||||
System.out.println("乒乓球教练吃小白菜,喝大米粥");
|
System.out.println("乒乓球教练吃小白菜,喝大米粥");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void teach() {
|
public void teach() {
|
||||||
System.out.println("乒乓球教练教如何发球和接球");
|
System.out.println("乒乓球教练教如何发球和接球");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void speak() {
|
public void speak() {
|
||||||
System.out.println("乒乓球教练说英语");
|
System.out.println("乒乓球教练说英语");
|
||||||
}
|
}
|
||||||
/********* end *********/
|
/********* end *********/
|
||||||
}
|
}
|
||||||
|
|
||||||
// 定义篮球教练具体类BasketballCoach 继承自Coach类 不需要继承接口,因为他不需要说英语
|
// 定义篮球教练具体类BasketballCoach 继承自Coach类 不需要继承接口,因为他不需要说英语
|
||||||
// 无参构造函数
|
// 无参构造函数
|
||||||
// 有参构造函数初始化name和age
|
// 有参构造函数初始化name和age
|
||||||
// 实现自己的eat()方法 输出'篮球教练吃羊肉,喝羊奶'
|
// 实现自己的eat()方法 输出'篮球教练吃羊肉,喝羊奶'
|
||||||
// 实现自己的teach()方法 输出'篮球教练教如何运球和投篮'
|
// 实现自己的teach()方法 输出'篮球教练教如何运球和投篮'
|
||||||
class BasketballCoach extends Coach {
|
class BasketballCoach extends Coach {
|
||||||
/********* begin *********/
|
/********* begin *********/
|
||||||
public BasketballCoach() {
|
public BasketballCoach() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public BasketballCoach(String name, int age) {
|
public BasketballCoach(String name, int age) {
|
||||||
super(name, age);
|
super(name, age);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void eat() {
|
public void eat() {
|
||||||
System.out.println("篮球教练吃羊肉,喝羊奶");
|
System.out.println("篮球教练吃羊肉,喝羊奶");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void teach() {
|
public void teach() {
|
||||||
System.out.println("篮球教练教如何运球和投篮");
|
System.out.println("篮球教练教如何运球和投篮");
|
||||||
}
|
}
|
||||||
/********* end *********/
|
/********* end *********/
|
||||||
}
|
}
|
||||||
+15
-15
@@ -1,15 +1,15 @@
|
|||||||
//Cuboid.java
|
//Cuboid.java
|
||||||
package task4;
|
package task4;
|
||||||
|
|
||||||
public class Cuboid extends Rectangle {
|
public class Cuboid extends Rectangle {
|
||||||
double height;
|
double height;
|
||||||
|
|
||||||
public Cuboid(double length, double width, double height) {
|
public Cuboid(double length, double width, double height) {
|
||||||
super(length, width);
|
super(length, width);
|
||||||
this.height = height;
|
this.height = height;
|
||||||
}
|
}
|
||||||
|
|
||||||
public double volume() {
|
public double volume() {
|
||||||
return this.length * this.width * this.height;
|
return this.length * this.width * this.height;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,24 +1,24 @@
|
|||||||
//Rectangle.java
|
//Rectangle.java
|
||||||
package task4;
|
package task4;
|
||||||
|
|
||||||
public class Rectangle {
|
public class Rectangle {
|
||||||
double length;
|
double length;
|
||||||
double width;
|
double width;
|
||||||
|
|
||||||
public double getPerimeter() {
|
public double getPerimeter() {
|
||||||
return (this.length + this.width) * 2;
|
return (this.length + this.width) * 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getArea() {
|
public double getArea() {
|
||||||
return this.length * this.width;
|
return this.length * this.width;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Rectangle(double length, double width) {
|
public Rectangle(double length, double width) {
|
||||||
this.length = length;
|
this.length = length;
|
||||||
this.width = width;
|
this.width = width;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Rectangle() {
|
public Rectangle() {
|
||||||
this(1.0, 1.0);
|
this(1.0, 1.0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+20
-20
@@ -1,20 +1,20 @@
|
|||||||
//Test.java
|
//Test.java
|
||||||
package task4;
|
package task4;
|
||||||
|
|
||||||
public class Test {
|
public class Test {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
Rectangle r1 = new Rectangle(3, 4);
|
Rectangle r1 = new Rectangle(3, 4);
|
||||||
System.out.println("r1's perimeter:\t" + r1.getPerimeter());
|
System.out.println("r1's perimeter:\t" + r1.getPerimeter());
|
||||||
System.out.println("r1's area:\t" + r1.getArea());
|
System.out.println("r1's area:\t" + r1.getArea());
|
||||||
System.out.println("__________________________________");
|
System.out.println("__________________________________");
|
||||||
Rectangle r2 = new Rectangle();
|
Rectangle r2 = new Rectangle();
|
||||||
System.out.println("r2's perimeter:\t" + r2.getPerimeter());
|
System.out.println("r2's perimeter:\t" + r2.getPerimeter());
|
||||||
System.out.println("r2's area:\t" + r2.getArea());
|
System.out.println("r2's area:\t" + r2.getArea());
|
||||||
System.out.println("__________________________________");
|
System.out.println("__________________________________");
|
||||||
Cuboid c = new Cuboid(3, 4, 5);
|
Cuboid c = new Cuboid(3, 4, 5);
|
||||||
System.out.println("bottom of c's perimeter:\t" + c.getPerimeter());
|
System.out.println("bottom of c's perimeter:\t" + c.getPerimeter());
|
||||||
System.out.println("bottom c's area:\t" + c.getArea());
|
System.out.println("bottom c's area:\t" + c.getArea());
|
||||||
System.out.println("c's volume:\t" + c.volume());
|
System.out.println("c's volume:\t" + c.volume());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
//HelloCollections.java
|
//HelloCollections.java
|
||||||
package task1;
|
package task1;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
public class HelloCollections {
|
public class HelloCollections {
|
||||||
public ArrayList run() {
|
public ArrayList run() {
|
||||||
ArrayList<String> list = new ArrayList<>();
|
ArrayList<String> list = new ArrayList<>();
|
||||||
list.add("hello, world");
|
list.add("hello, world");
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
//test.java
|
||||||
|
package task1;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
public class test {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
HelloCollections h1 = new HelloCollections();
|
||||||
|
ArrayList a1 = h1.run();
|
||||||
|
System.out.println(a1);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,25 +1,25 @@
|
|||||||
package task2;
|
package task2;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
|
||||||
public class WalkCollection {
|
public class WalkCollection {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
ArrayList arrayListExample = new ArrayList();
|
ArrayList arrayListExample = new ArrayList();
|
||||||
// ---------------------Begin------------------------
|
// ---------------------Begin------------------------
|
||||||
// arrayListExample.add("aaa");
|
// arrayListExample.add("aaa");
|
||||||
// arrayListExample.add("bbb");
|
// arrayListExample.add("bbb");
|
||||||
// arrayListExample.add("ccc");
|
// arrayListExample.add("ccc");
|
||||||
// arrayListExample.add("ddd");
|
// arrayListExample.add("ddd");
|
||||||
// 展示运行结果前删下注释
|
// 展示运行结果前删下注释
|
||||||
// 使用迭代器iterator遍历arrayListExample集合
|
// 使用迭代器iterator遍历arrayListExample集合
|
||||||
Iterator itr = arrayListExample.iterator();
|
Iterator itr = arrayListExample.iterator();
|
||||||
while (itr.hasNext()) {
|
while (itr.hasNext()) {
|
||||||
System.out.println(itr.next());
|
System.out.println(itr.next());
|
||||||
}
|
}
|
||||||
|
|
||||||
// 使用foreach遍历arrayListExample集合
|
// 使用foreach遍历arrayListExample集合
|
||||||
arrayListExample.forEach(System.out::println);
|
arrayListExample.forEach(System.out::println);
|
||||||
// ---------------------End------------------------
|
// ---------------------End------------------------
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+20
-20
@@ -1,21 +1,21 @@
|
|||||||
package task3;
|
package task3;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
|
||||||
public class HelloSet {
|
public class HelloSet {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
HashSet<Object> hashSet = new HashSet<>();
|
HashSet<Object> hashSet = new HashSet<>();
|
||||||
Scanner scanner = new Scanner(System.in);
|
Scanner scanner = new Scanner(System.in);
|
||||||
for (int i = 0; i < 5; i++) {
|
for (int i = 0; i < 5; i++) {
|
||||||
hashSet.add(scanner.next());
|
hashSet.add(scanner.next());
|
||||||
}
|
}
|
||||||
// ---------------------Begin------------------------
|
// ---------------------Begin------------------------
|
||||||
hashSet.add("helloHashSet");
|
hashSet.add("helloHashSet");
|
||||||
hashSet.remove("cat");
|
hashSet.remove("cat");
|
||||||
hashSet.add("fish");
|
hashSet.add("fish");
|
||||||
hashSet.remove("apple");
|
hashSet.remove("apple");
|
||||||
// ---------------------End------------------------
|
// ---------------------End------------------------
|
||||||
hashSet.forEach(ele -> System.out.println(ele));
|
hashSet.forEach(ele -> System.out.println(ele));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,21 +1,21 @@
|
|||||||
package task4;
|
package task4;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
|
||||||
public class HelloHashMap {
|
public class HelloHashMap {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
Scanner scanner = new Scanner(System.in);
|
Scanner scanner = new Scanner(System.in);
|
||||||
HashMap hashMapExample = new HashMap<>();
|
HashMap hashMapExample = new HashMap<>();
|
||||||
for (int i = 0; i < 2; i++) {
|
for (int i = 0; i < 2; i++) {
|
||||||
hashMapExample.put(scanner.next(), scanner.next());
|
hashMapExample.put(scanner.next(), scanner.next());
|
||||||
}
|
}
|
||||||
// ---------------------Begin------------------------
|
// ---------------------Begin------------------------
|
||||||
hashMapExample.put("name", "lihong");
|
hashMapExample.put("name", "lihong");
|
||||||
hashMapExample.remove("firstkey");
|
hashMapExample.remove("firstkey");
|
||||||
hashMapExample.replace("secondkey", "educode");
|
hashMapExample.replace("secondkey", "educode");
|
||||||
System.out.println(hashMapExample);
|
System.out.println(hashMapExample);
|
||||||
// ---------------------End------------------------
|
// ---------------------End------------------------
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user