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

|
||||
# Java作业存放处
|
||||
|
||||
这是一个专门拿来存放java课时作业的地方
|
||||
|
||||
不会用git的,想直接看代码
|
||||
[点这里](https://gitee.com/msksbr/java-homework/tree/master/)
|
||||
|
||||
以后我的代码都会放到这里,和我要代码的直接来仓库里找,会更新
|
||||
|
||||
帮忙点个免费的star呗
|
||||
|
||||
😃☕
|
||||
|
||||
[放个B站主页试试看](https://space.bilibili.com/521936200)
|
||||
|
||||

|
||||
|
||||
+16
-16
@@ -1,17 +1,17 @@
|
||||
import java.util.Scanner;
|
||||
|
||||
public class task1 {
|
||||
public static void main(String args[]) {
|
||||
Scanner input = new Scanner(System.in);
|
||||
System.out.println("请输入第一个整数:");
|
||||
int a = input.nextInt();
|
||||
System.out.println("请输入第二个整数:");
|
||||
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));
|
||||
}
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
public class task1 {
|
||||
public static void main(String args[]) {
|
||||
Scanner input = new Scanner(System.in);
|
||||
System.out.println("请输入第一个整数:");
|
||||
int a = input.nextInt();
|
||||
System.out.println("请输入第二个整数:");
|
||||
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));
|
||||
}
|
||||
|
||||
}
|
||||
+17
-17
@@ -1,17 +1,17 @@
|
||||
import java.util.Scanner;
|
||||
|
||||
public class task2 {
|
||||
public static void main(String[] args) {
|
||||
Scanner input = new Scanner(System.in);
|
||||
System.out.println("请输入一个数a:");
|
||||
int a = input.nextInt();
|
||||
System.out.println("请输入一个数b:");
|
||||
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("b>=a=" + (b >= a));
|
||||
System.out.println("b<=a=" + (b <= a));
|
||||
}
|
||||
}
|
||||
import java.util.Scanner;
|
||||
|
||||
public class task2 {
|
||||
public static void main(String[] args) {
|
||||
Scanner input = new Scanner(System.in);
|
||||
System.out.println("请输入一个数a:");
|
||||
int a = input.nextInt();
|
||||
System.out.println("请输入一个数b:");
|
||||
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("b>=a=" + (b >= a));
|
||||
System.out.println("b<=a=" + (b <= a));
|
||||
}
|
||||
}
|
||||
|
||||
+9
-9
@@ -1,9 +1,9 @@
|
||||
import java.util.Scanner;
|
||||
|
||||
public class task3 {
|
||||
public static void main(String[] args) {
|
||||
Scanner input = new Scanner(System.in);
|
||||
int year = input.nextInt();
|
||||
System.out.println(year + "年是否为闰年:" + ((year % 4 == 0) | (year % 400 == 0)));
|
||||
}
|
||||
}
|
||||
import java.util.Scanner;
|
||||
|
||||
public class task3 {
|
||||
public static void main(String[] args) {
|
||||
Scanner input = new Scanner(System.in);
|
||||
int year = input.nextInt();
|
||||
System.out.println(year + "年是否为闰年:" + ((year % 4 == 0) | (year % 400 == 0)));
|
||||
}
|
||||
}
|
||||
|
||||
+9
-9
@@ -1,9 +1,9 @@
|
||||
import java.util.Scanner;
|
||||
|
||||
public class task4 {
|
||||
public static void main(String[] args) {
|
||||
Scanner input = new Scanner(System.in);
|
||||
int num = input.nextInt();
|
||||
System.out.println((num / 100 + num/10-num/100*10 + num % 10));
|
||||
}
|
||||
}
|
||||
import java.util.Scanner;
|
||||
|
||||
public class task4 {
|
||||
public static void main(String[] args) {
|
||||
Scanner input = new Scanner(System.in);
|
||||
int num = input.nextInt();
|
||||
System.out.println((num / 100 + num/10-num/100*10 + num % 10));
|
||||
}
|
||||
}
|
||||
|
||||
+18
-18
@@ -1,19 +1,19 @@
|
||||
import java.util.Scanner;
|
||||
|
||||
public class task1 {
|
||||
public static void main(String[] args) {
|
||||
Scanner input = new Scanner(System.in);
|
||||
double score = input.nextDouble();
|
||||
if (score >= 90 & score <= 100) {
|
||||
System.out.println(4.0);
|
||||
} else if (score >= 80 & score < 90) {
|
||||
System.out.println(3.5);
|
||||
} else if (score >= 70 && score < 80) {
|
||||
System.out.println(3.0);
|
||||
} else if (score >= 60 && score < 70) {
|
||||
System.out.println(2.5);
|
||||
} else {
|
||||
System.out.println(0d);
|
||||
}
|
||||
}
|
||||
import java.util.Scanner;
|
||||
|
||||
public class task1 {
|
||||
public static void main(String[] args) {
|
||||
Scanner input = new Scanner(System.in);
|
||||
double score = input.nextDouble();
|
||||
if (score >= 90 & score <= 100) {
|
||||
System.out.println(4.0);
|
||||
} else if (score >= 80 & score < 90) {
|
||||
System.out.println(3.5);
|
||||
} else if (score >= 70 && score < 80) {
|
||||
System.out.println(3.0);
|
||||
} else if (score >= 60 && score < 70) {
|
||||
System.out.println(2.5);
|
||||
} else {
|
||||
System.out.println(0d);
|
||||
}
|
||||
}
|
||||
}
|
||||
+13
-13
@@ -1,13 +1,13 @@
|
||||
import java.util.Scanner;
|
||||
|
||||
public class task2 {
|
||||
public static void main(String[] args) {
|
||||
Scanner input = new Scanner(System.in);
|
||||
int goal = input.nextInt();
|
||||
int mutied = 1;
|
||||
for (int i = 1; i <= goal; i++) {
|
||||
mutied *= i;
|
||||
}
|
||||
System.out.println(mutied);
|
||||
}
|
||||
}
|
||||
import java.util.Scanner;
|
||||
|
||||
public class task2 {
|
||||
public static void main(String[] args) {
|
||||
Scanner input = new Scanner(System.in);
|
||||
int goal = input.nextInt();
|
||||
int mutied = 1;
|
||||
for (int i = 1; i <= goal; i++) {
|
||||
mutied *= i;
|
||||
}
|
||||
System.out.println(mutied);
|
||||
}
|
||||
}
|
||||
|
||||
+32
-32
@@ -1,32 +1,32 @@
|
||||
import java.util.Scanner;
|
||||
|
||||
public class task3 {
|
||||
public static void main(String[] args) {
|
||||
Scanner input = new Scanner(System.in);
|
||||
System.out.println("星级成绩评定系统");
|
||||
System.out.print("请输入成绩:");
|
||||
double score = input.nextDouble();
|
||||
int stars = 0;
|
||||
String starHanzi;
|
||||
if (score > 90) {
|
||||
stars = 5;
|
||||
starHanzi = "五";
|
||||
} else if (score > 80 & score <= 90) {
|
||||
stars = 4;
|
||||
starHanzi = "四";
|
||||
} else if (score > 70 & score <= 80) {
|
||||
stars = 3;
|
||||
starHanzi = "三";
|
||||
} else if (score >= 60 & score <= 70) {
|
||||
stars = 2;
|
||||
starHanzi = "俩";
|
||||
} else {
|
||||
stars=0;
|
||||
starHanzi="无";
|
||||
}
|
||||
for(int i=1;i<=stars;i++){
|
||||
System.out.print("*");
|
||||
}
|
||||
System.out.println(starHanzi+"星成绩");
|
||||
}
|
||||
}
|
||||
import java.util.Scanner;
|
||||
|
||||
public class task3 {
|
||||
public static void main(String[] args) {
|
||||
Scanner input = new Scanner(System.in);
|
||||
System.out.println("星级成绩评定系统");
|
||||
System.out.print("请输入成绩:");
|
||||
double score = input.nextDouble();
|
||||
int stars = 0;
|
||||
String starHanzi;
|
||||
if (score > 90) {
|
||||
stars = 5;
|
||||
starHanzi = "五";
|
||||
} else if (score > 80 & score <= 90) {
|
||||
stars = 4;
|
||||
starHanzi = "四";
|
||||
} else if (score > 70 & score <= 80) {
|
||||
stars = 3;
|
||||
starHanzi = "三";
|
||||
} else if (score >= 60 & score <= 70) {
|
||||
stars = 2;
|
||||
starHanzi = "俩";
|
||||
} else {
|
||||
stars=0;
|
||||
starHanzi="无";
|
||||
}
|
||||
for(int i=1;i<=stars;i++){
|
||||
System.out.print("*");
|
||||
}
|
||||
System.out.println(starHanzi+"星成绩");
|
||||
}
|
||||
}
|
||||
|
||||
+12
-12
@@ -1,13 +1,13 @@
|
||||
public class task4 {
|
||||
public static void main(String[] args) {
|
||||
int time = 0;
|
||||
for (int i = 1; i <= 100; i++) {
|
||||
if (i % 6 == 0) {
|
||||
System.out.print(i + " ");
|
||||
time += 1;
|
||||
}
|
||||
}
|
||||
System.out.println();
|
||||
System.out.println(time);
|
||||
}
|
||||
public class task4 {
|
||||
public static void main(String[] args) {
|
||||
int time = 0;
|
||||
for (int i = 1; i <= 100; i++) {
|
||||
if (i % 6 == 0) {
|
||||
System.out.print(i + " ");
|
||||
time += 1;
|
||||
}
|
||||
}
|
||||
System.out.println();
|
||||
System.out.println(time);
|
||||
}
|
||||
}
|
||||
+17
-17
@@ -1,17 +1,17 @@
|
||||
public class task5 {
|
||||
public static void main(String[] args) {
|
||||
for (int i = 1; i <= 10; i++) {
|
||||
for (int j = 1; j <= i; j++) {
|
||||
System.out.print("*");
|
||||
}
|
||||
System.out.println();
|
||||
}
|
||||
System.out.println("-----------------我是华丽的分割线-----------------");
|
||||
for (int i = 10; i >= 1; i--) {
|
||||
for (int j = 1; j <= i; j++) {
|
||||
System.out.print("*");
|
||||
}
|
||||
System.out.println();
|
||||
}
|
||||
}
|
||||
}
|
||||
public class task5 {
|
||||
public static void main(String[] args) {
|
||||
for (int i = 1; i <= 10; i++) {
|
||||
for (int j = 1; j <= i; j++) {
|
||||
System.out.print("*");
|
||||
}
|
||||
System.out.println();
|
||||
}
|
||||
System.out.println("-----------------我是华丽的分割线-----------------");
|
||||
for (int i = 10; i >= 1; i--) {
|
||||
for (int j = 1; j <= i; j++) {
|
||||
System.out.print("*");
|
||||
}
|
||||
System.out.println();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+10
-10
@@ -1,10 +1,10 @@
|
||||
public class task6 {
|
||||
public static void main(String[] args) {
|
||||
for (int i = 1; i <= 9; i++) {
|
||||
for (int j = 1; j <= i; j++) {
|
||||
System.out.print(i + "*" + j + "=" + i * j + "\t");
|
||||
}
|
||||
System.out.println();
|
||||
}
|
||||
}
|
||||
}
|
||||
public class task6 {
|
||||
public static void main(String[] args) {
|
||||
for (int i = 1; i <= 9; i++) {
|
||||
for (int j = 1; j <= i; j++) {
|
||||
System.out.print(i + "*" + j + "=" + i * j + "\t");
|
||||
}
|
||||
System.out.println();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Vendored
+7
-7
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"java.project.sourcePaths": ["src"],
|
||||
"java.project.outputPath": "bin",
|
||||
"java.project.referencedLibraries": [
|
||||
"lib/**/*.jar"
|
||||
]
|
||||
}
|
||||
{
|
||||
"java.project.sourcePaths": ["src"],
|
||||
"java.project.outputPath": "bin",
|
||||
"java.project.referencedLibraries": [
|
||||
"lib/**/*.jar"
|
||||
]
|
||||
}
|
||||
|
||||
+18
-18
@@ -1,18 +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).
|
||||
## 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).
|
||||
|
||||
+21
-21
@@ -1,21 +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 + "岁的学生");
|
||||
}
|
||||
|
||||
}
|
||||
//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 + "岁的学生");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+14
-14
@@ -1,14 +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();
|
||||
}
|
||||
}
|
||||
//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();
|
||||
}
|
||||
}
|
||||
|
||||
+16
-16
@@ -1,16 +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);
|
||||
}
|
||||
}
|
||||
//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);
|
||||
}
|
||||
}
|
||||
|
||||
+21
-21
@@ -1,21 +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);
|
||||
}
|
||||
}
|
||||
//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);
|
||||
}
|
||||
}
|
||||
|
||||
+14
-14
@@ -1,14 +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();
|
||||
}
|
||||
}
|
||||
//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();
|
||||
}
|
||||
}
|
||||
|
||||
+33
-33
@@ -1,33 +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;
|
||||
}
|
||||
}
|
||||
//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;
|
||||
}
|
||||
}
|
||||
|
||||
+14
-14
@@ -1,14 +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());
|
||||
}
|
||||
}
|
||||
//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());
|
||||
}
|
||||
}
|
||||
|
||||
+20
-20
@@ -1,20 +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;
|
||||
}
|
||||
}
|
||||
//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;
|
||||
}
|
||||
}
|
||||
|
||||
+12
-12
@@ -1,12 +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());
|
||||
}
|
||||
}
|
||||
//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());
|
||||
}
|
||||
}
|
||||
|
||||
+25
-25
@@ -1,25 +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;
|
||||
}
|
||||
}
|
||||
}
|
||||
//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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+19
-19
@@ -1,19 +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) + "岁。");
|
||||
}
|
||||
}
|
||||
//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) + "岁。");
|
||||
}
|
||||
}
|
||||
|
||||
+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 *********/
|
||||
|
||||
}
|
||||
+24
-24
@@ -1,25 +1,25 @@
|
||||
//Main.java
|
||||
package task1;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.Scanner;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Locale;
|
||||
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
Scanner input = new Scanner(System.in);
|
||||
SimpleDateFormat in = new SimpleDateFormat("yyyy M dd");
|
||||
Date d = new Date();
|
||||
try {
|
||||
d = in.parse(input.nextLine());
|
||||
} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
SimpleDateFormat out = new SimpleDateFormat("yyyy MMMM dd EEEE", Locale.ENGLISH);
|
||||
String formattedDate = out.format(d);
|
||||
System.out.println("今天是" + out.format(d).toUpperCase());
|
||||
|
||||
}
|
||||
//Main.java
|
||||
package task1;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.Scanner;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Locale;
|
||||
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
Scanner input = new Scanner(System.in);
|
||||
SimpleDateFormat in = new SimpleDateFormat("yyyy M dd");
|
||||
Date d = new Date();
|
||||
try {
|
||||
d = in.parse(input.nextLine());
|
||||
} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
SimpleDateFormat out = new SimpleDateFormat("yyyy MMMM dd EEEE", Locale.ENGLISH);
|
||||
String formattedDate = out.format(d);
|
||||
System.out.println("今天是" + out.format(d).toUpperCase());
|
||||
|
||||
}
|
||||
}
|
||||
+27
-27
@@ -1,27 +1,27 @@
|
||||
//Main.java
|
||||
package task2;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
import java.util.Scanner;
|
||||
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
Scanner input = new Scanner(System.in);
|
||||
Date inDate = new Date();
|
||||
SimpleDateFormat inFormat = new SimpleDateFormat("yyyy年M月d日", Locale.CHINA);
|
||||
System.out.print("请输入您家孩子的出生日期(格式为yyyy年M月d日):");
|
||||
try {
|
||||
inDate = inFormat.parse(input.nextLine());
|
||||
} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
long inTimeStamp = inDate.getTime();
|
||||
long outTimeStamp = inTimeStamp + (long) 100 * 24 * 60 * 60 * 1000;
|
||||
Date outDate = new Date(outTimeStamp);
|
||||
SimpleDateFormat outFormat = new SimpleDateFormat("yyyy年M月dd日 EEEE", Locale.CHINA);
|
||||
System.out.println("经计算,您家孩子的百日宴应该设在" + outFormat.format(outDate));
|
||||
}
|
||||
}
|
||||
//Main.java
|
||||
package task2;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
import java.util.Scanner;
|
||||
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
Scanner input = new Scanner(System.in);
|
||||
Date inDate = new Date();
|
||||
SimpleDateFormat inFormat = new SimpleDateFormat("yyyy年M月d日", Locale.CHINA);
|
||||
System.out.print("请输入您家孩子的出生日期(格式为yyyy年M月d日):");
|
||||
try {
|
||||
inDate = inFormat.parse(input.nextLine());
|
||||
} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
long inTimeStamp = inDate.getTime();
|
||||
long outTimeStamp = inTimeStamp + (long) 100 * 24 * 60 * 60 * 1000;
|
||||
Date outDate = new Date(outTimeStamp);
|
||||
SimpleDateFormat outFormat = new SimpleDateFormat("yyyy年M月dd日 EEEE", Locale.CHINA);
|
||||
System.out.println("经计算,您家孩子的百日宴应该设在" + outFormat.format(outDate));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,22 +1,22 @@
|
||||
package task3;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
public class StringLearning {
|
||||
public static void main(String[] args) {
|
||||
Scanner scanner = new Scanner(System.in);
|
||||
String stringExample = scanner.next();
|
||||
String endStr = " end";
|
||||
// ---------------------Begin------------------------
|
||||
System.out.println(stringExample);// 1.输出原字符串
|
||||
System.out.println(stringExample.length());// 2.求出字符串长度
|
||||
// 3.字符串转换成相应的大/小写
|
||||
System.out.println(stringExample.toUpperCase());
|
||||
System.out.println(stringExample.toLowerCase());
|
||||
// 4.截取指定位置的字符串(3-7)
|
||||
System.out.println(stringExample.substring(3, 7));
|
||||
// 5.字符串相加具体输出要求请看测试说明。
|
||||
System.out.println(stringExample + endStr);
|
||||
// ---------------------End------------------------
|
||||
}
|
||||
}
|
||||
package task3;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
public class StringLearning {
|
||||
public static void main(String[] args) {
|
||||
Scanner scanner = new Scanner(System.in);
|
||||
String stringExample = scanner.next();
|
||||
String endStr = " end";
|
||||
// ---------------------Begin------------------------
|
||||
System.out.println(stringExample);// 1.输出原字符串
|
||||
System.out.println(stringExample.length());// 2.求出字符串长度
|
||||
// 3.字符串转换成相应的大/小写
|
||||
System.out.println(stringExample.toUpperCase());
|
||||
System.out.println(stringExample.toLowerCase());
|
||||
// 4.截取指定位置的字符串(3-7)
|
||||
System.out.println(stringExample.substring(3, 7));
|
||||
// 5.字符串相加具体输出要求请看测试说明。
|
||||
System.out.println(stringExample + endStr);
|
||||
// ---------------------End------------------------
|
||||
}
|
||||
}
|
||||
|
||||
+15
-15
@@ -1,15 +1,15 @@
|
||||
//Main.java
|
||||
package task4;
|
||||
|
||||
import java.lang.Math;
|
||||
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
double value1 = 2, value2 = 0;
|
||||
System.out.println("绝对值:\t" + Math.abs(value1));
|
||||
System.out.println("3次幂:\t" + Math.pow(value1, 3));
|
||||
System.out.println("二次方根:\t" + Math.pow(value1, 0.5));
|
||||
System.out.println("sin值:\t" + Math.sin(value1));
|
||||
System.out.println("较大者:\t" + Math.max(value1, value2));
|
||||
}
|
||||
}
|
||||
//Main.java
|
||||
package task4;
|
||||
|
||||
import java.lang.Math;
|
||||
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
double value1 = 2, value2 = 0;
|
||||
System.out.println("绝对值:\t" + Math.abs(value1));
|
||||
System.out.println("3次幂:\t" + Math.pow(value1, 3));
|
||||
System.out.println("二次方根:\t" + Math.pow(value1, 0.5));
|
||||
System.out.println("sin值:\t" + Math.sin(value1));
|
||||
System.out.println("较大者:\t" + Math.max(value1, value2));
|
||||
}
|
||||
}
|
||||
|
||||
+18
-18
@@ -1,18 +1,18 @@
|
||||
package task5;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
public class Roster {
|
||||
public static void main(String[] args) {
|
||||
Scanner scanner = new Scanner(System.in);
|
||||
/********** Begin *********/
|
||||
String roster1 = "张三,李四,王五";
|
||||
String roster2 = scanner.nextLine();
|
||||
if (roster1.equals(roster2)) {
|
||||
System.out.println("相同");
|
||||
} else {
|
||||
System.out.println("不同");
|
||||
}
|
||||
/********** End *********/
|
||||
}
|
||||
}
|
||||
package task5;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
public class Roster {
|
||||
public static void main(String[] args) {
|
||||
Scanner scanner = new Scanner(System.in);
|
||||
/********** Begin *********/
|
||||
String roster1 = "张三,李四,王五";
|
||||
String roster2 = scanner.nextLine();
|
||||
if (roster1.equals(roster2)) {
|
||||
System.out.println("相同");
|
||||
} else {
|
||||
System.out.println("不同");
|
||||
}
|
||||
/********** End *********/
|
||||
}
|
||||
}
|
||||
|
||||
+17
-17
@@ -1,18 +1,18 @@
|
||||
package task1;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
public class Task {
|
||||
public static void main(String[] args) {
|
||||
Scanner sc = new Scanner(System.in);
|
||||
int num1 = sc.nextInt();
|
||||
int num2 = sc.nextInt();
|
||||
/********* Begin *********/
|
||||
try {
|
||||
System.out.println(num1 / num2);
|
||||
} catch (java.lang.ArithmeticException e) {
|
||||
System.out.println("除数不能为0");
|
||||
}
|
||||
/********* End *********/
|
||||
}
|
||||
package task1;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
public class Task {
|
||||
public static void main(String[] args) {
|
||||
Scanner sc = new Scanner(System.in);
|
||||
int num1 = sc.nextInt();
|
||||
int num2 = sc.nextInt();
|
||||
/********* Begin *********/
|
||||
try {
|
||||
System.out.println(num1 / num2);
|
||||
} catch (java.lang.ArithmeticException e) {
|
||||
System.out.println("除数不能为0");
|
||||
}
|
||||
/********* End *********/
|
||||
}
|
||||
}
|
||||
+35
-35
@@ -1,35 +1,35 @@
|
||||
package task2;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
public class Task {
|
||||
/********* Begin *********/
|
||||
public static void main(String[] args) {
|
||||
Scanner sc = new Scanner(System.in);
|
||||
String username = sc.next();
|
||||
// 判断用户名
|
||||
if (username.length() < 3) {
|
||||
try {
|
||||
throw new MyException("用户名小于3位Exception");
|
||||
} catch (MyException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
System.out.println("用户名格式正确");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
class MyException extends java.lang.Exception {
|
||||
public MyException() {
|
||||
super();
|
||||
|
||||
}
|
||||
|
||||
public MyException(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
}
|
||||
/********* End *********/
|
||||
package task2;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
public class Task {
|
||||
/********* Begin *********/
|
||||
public static void main(String[] args) {
|
||||
Scanner sc = new Scanner(System.in);
|
||||
String username = sc.next();
|
||||
// 判断用户名
|
||||
if (username.length() < 3) {
|
||||
try {
|
||||
throw new MyException("用户名小于3位Exception");
|
||||
} catch (MyException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
System.out.println("用户名格式正确");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
class MyException extends java.lang.Exception {
|
||||
public MyException() {
|
||||
super();
|
||||
|
||||
}
|
||||
|
||||
public MyException(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
}
|
||||
/********* End *********/
|
||||
|
||||
+257
-257
@@ -1,258 +1,258 @@
|
||||
package task3;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
public class Task3 {
|
||||
public static void main(String[] args) {
|
||||
Scanner sc = new Scanner(System.in);
|
||||
String pppName = sc.next();
|
||||
int pppAge = sc.nextInt();
|
||||
String bpName = sc.next();
|
||||
int bpAge = sc.nextInt();
|
||||
String ppcName = sc.next();
|
||||
int ppcAge = sc.nextInt();
|
||||
String bcName = sc.next();
|
||||
int bcAge = sc.nextInt();
|
||||
// 测试运动员(乒乓球运动员和篮球运动员)
|
||||
// 乒乓球运动员
|
||||
// 通过带参构造函数实例化PingPangPlayer对象ppp
|
||||
// 输出'name---age'
|
||||
// 分别调用sleep()、eat()、study()、speak()方法
|
||||
/********* begin *********/
|
||||
PingPangPlayer ppp = new PingPangPlayer(pppName, pppAge);
|
||||
System.out.println(ppp.getName() + "---" + ppp.getAge());
|
||||
ppp.sleep();
|
||||
ppp.eat();
|
||||
ppp.study();
|
||||
ppp.speak();
|
||||
/********* end *********/
|
||||
System.out.println("----------------");
|
||||
// 篮球运动员
|
||||
// 通过带参构造函数实例化BasketballPlayer对象bp
|
||||
// 输出'name---age'
|
||||
// 分别调用sleep()、eat()、study()方法
|
||||
/********* begin *********/
|
||||
BasketballPlayer bp = new BasketballPlayer(bpName, bpAge);
|
||||
System.out.println(bp.getName() + "---" + bp.getAge());
|
||||
bp.sleep();
|
||||
bp.eat();
|
||||
bp.study();
|
||||
/********* end *********/
|
||||
System.out.println("----------------");
|
||||
// 测试教练(乒乓球教练和篮球教练)
|
||||
// 乒乓球教练
|
||||
// 通过带参构造函数实例化PingPangCoach对象ppc
|
||||
// 输出'name---age'
|
||||
// 分别调用sleep()、eat()、teach()、speak()方法
|
||||
/********* begin *********/
|
||||
PingPangCoach ppc = new PingPangCoach(ppcName, ppcAge);
|
||||
System.out.println(ppc.getName() + "---" + ppc.getAge());
|
||||
ppc.sleep();
|
||||
ppc.eat();
|
||||
ppc.teach();
|
||||
ppc.speak();
|
||||
/********* end *********/
|
||||
System.out.println("----------------");
|
||||
// 篮球教练
|
||||
// 通过带参构造函数实例化BasketballCoach对象bc
|
||||
// 输出'name---age'
|
||||
// 分别调用sleep()、eat()、teach()方法
|
||||
/********* begin *********/
|
||||
BasketballCoach bc = new BasketballCoach(bcName, bcAge);
|
||||
System.out.println(bc.getName() + "---" + bc.getAge());
|
||||
bc.sleep();
|
||||
bc.eat();
|
||||
bc.teach();
|
||||
/********* end *********/
|
||||
System.out.println("----------------");
|
||||
}
|
||||
}
|
||||
|
||||
// 说英语接口 声明抽象方法speak()
|
||||
interface SpeakEnglish {
|
||||
/********* begin *********/
|
||||
public abstract void speak();
|
||||
/********* end *********/
|
||||
}
|
||||
|
||||
// 定义人的抽象类Person 封装name和age
|
||||
// 无参构造函数
|
||||
// 有参构造函数初始化name和age
|
||||
// 定义具体方法sleep() 输出'人都是要睡觉的'
|
||||
// 抽象方法eat()(吃的不一样)
|
||||
abstract class Person {
|
||||
/********* begin *********/
|
||||
private String name;
|
||||
private int age;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public int getAge() {
|
||||
return age;
|
||||
}
|
||||
|
||||
public void setAge(int age) {
|
||||
this.age = age;
|
||||
}
|
||||
|
||||
public Person() {
|
||||
}
|
||||
|
||||
public Person(String name, int age) {
|
||||
this.name = name;
|
||||
this.age = age;
|
||||
}
|
||||
|
||||
public void sleep() {
|
||||
System.out.println("人都是要睡觉的");
|
||||
}
|
||||
|
||||
public abstract void eat();
|
||||
/********* end *********/
|
||||
}
|
||||
|
||||
// 定义运动员Player(抽象类)继承自Person类
|
||||
// 无参构造函数
|
||||
// 有参构造函数初始化name和age
|
||||
// 运动员学习内容不一样,抽取为抽象 定义抽象方法study()
|
||||
abstract class Player extends Person {
|
||||
/********* begin *********/
|
||||
public Player() {
|
||||
}
|
||||
|
||||
public Player(String name, int age) {
|
||||
super(name, age);
|
||||
}
|
||||
|
||||
public abstract void study();
|
||||
/********* end *********/
|
||||
}
|
||||
|
||||
// 定义教练Coach(抽象类)继承自Person类
|
||||
// 无参构造函数
|
||||
// 有参构造函数初始化name和age
|
||||
// 教练教的不一样 定义抽象方法teach()
|
||||
abstract class Coach extends Person {
|
||||
/********* begin *********/
|
||||
public Coach() {
|
||||
}
|
||||
|
||||
public Coach(String name, int age) {
|
||||
super(name, age);
|
||||
}
|
||||
|
||||
public abstract void teach();
|
||||
/********* end *********/
|
||||
}
|
||||
|
||||
// 定义乒乓球运动员具体类PingPangPlayer 继承自Player类并实现SpeakEnglish类(兵乓球运动员需要说英语)
|
||||
// 无参构造函数
|
||||
// 有参构造函数初始化name和age
|
||||
// 实现自己的eat()方法 输出'乒乓球运动员吃大白菜,喝小米粥'
|
||||
// 实现自己的study()方法 输出'乒乓球运动员学习如何发球和接球'
|
||||
// 实现自己的speak()方法 输出'乒乓球运动员说英语'
|
||||
class PingPangPlayer extends Player implements SpeakEnglish {
|
||||
/********* begin *********/
|
||||
public PingPangPlayer() {
|
||||
}
|
||||
|
||||
public PingPangPlayer(String name, int age) {
|
||||
super(name, age);
|
||||
}
|
||||
|
||||
public void eat() {
|
||||
System.out.println("乒乓球运动员吃大白菜,喝小米粥");
|
||||
}
|
||||
|
||||
public void study() {
|
||||
System.out.println("乒乓球运动员学习如何发球和接球");
|
||||
}
|
||||
|
||||
public void speak() {
|
||||
System.out.println("乒乓球运动员说英语");
|
||||
}
|
||||
/********* end *********/
|
||||
}
|
||||
|
||||
// 定义篮球运动员具体类BasketballPlayer 继承自Player类 不需要继承接口,因为他不需要说英语
|
||||
// 无参构造函数
|
||||
// 有参构造函数初始化name和age
|
||||
// 实现自己的eat()方法 输出'篮球运动员吃牛肉,喝牛奶'
|
||||
// 实现自己的study()方法 输出'篮球运动员学习如何运球和投篮'
|
||||
class BasketballPlayer extends Player {
|
||||
/********* begin *********/
|
||||
public BasketballPlayer() {
|
||||
}
|
||||
|
||||
public BasketballPlayer(String name, int age) {
|
||||
super(name, age);
|
||||
}
|
||||
|
||||
public void eat() {
|
||||
System.out.println("篮球运动员吃牛肉,喝牛奶");
|
||||
}
|
||||
|
||||
public void study() {
|
||||
System.out.println("篮球运动员学习如何运球和投篮");
|
||||
}
|
||||
/********* end *********/
|
||||
}
|
||||
|
||||
// 定义乒乓球教练具体类 PingPangCoach 继承自Coach类并实现SpeakEnglish类(兵乓球教练需要说英语)
|
||||
// 无参构造函数
|
||||
// 有参构造函数初始化name和age
|
||||
// 实现自己的eat()方法 输出'乒乓球教练吃小白菜,喝大米粥'
|
||||
// 实现自己的teach()方法 输出'乒乓球教练教如何发球和接球'
|
||||
// 实现自己的speak()方法 输出'乒乓球教练说英语'
|
||||
class PingPangCoach extends Coach implements SpeakEnglish {
|
||||
/********* begin *********/
|
||||
public PingPangCoach() {
|
||||
}
|
||||
|
||||
public PingPangCoach(String name, int age) {
|
||||
super(name, age);
|
||||
}
|
||||
|
||||
public void eat() {
|
||||
System.out.println("乒乓球教练吃小白菜,喝大米粥");
|
||||
}
|
||||
|
||||
public void teach() {
|
||||
System.out.println("乒乓球教练教如何发球和接球");
|
||||
}
|
||||
|
||||
public void speak() {
|
||||
System.out.println("乒乓球教练说英语");
|
||||
}
|
||||
/********* end *********/
|
||||
}
|
||||
|
||||
// 定义篮球教练具体类BasketballCoach 继承自Coach类 不需要继承接口,因为他不需要说英语
|
||||
// 无参构造函数
|
||||
// 有参构造函数初始化name和age
|
||||
// 实现自己的eat()方法 输出'篮球教练吃羊肉,喝羊奶'
|
||||
// 实现自己的teach()方法 输出'篮球教练教如何运球和投篮'
|
||||
class BasketballCoach extends Coach {
|
||||
/********* begin *********/
|
||||
public BasketballCoach() {
|
||||
}
|
||||
|
||||
public BasketballCoach(String name, int age) {
|
||||
super(name, age);
|
||||
}
|
||||
|
||||
public void eat() {
|
||||
System.out.println("篮球教练吃羊肉,喝羊奶");
|
||||
}
|
||||
|
||||
public void teach() {
|
||||
System.out.println("篮球教练教如何运球和投篮");
|
||||
}
|
||||
/********* end *********/
|
||||
package task3;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
public class Task3 {
|
||||
public static void main(String[] args) {
|
||||
Scanner sc = new Scanner(System.in);
|
||||
String pppName = sc.next();
|
||||
int pppAge = sc.nextInt();
|
||||
String bpName = sc.next();
|
||||
int bpAge = sc.nextInt();
|
||||
String ppcName = sc.next();
|
||||
int ppcAge = sc.nextInt();
|
||||
String bcName = sc.next();
|
||||
int bcAge = sc.nextInt();
|
||||
// 测试运动员(乒乓球运动员和篮球运动员)
|
||||
// 乒乓球运动员
|
||||
// 通过带参构造函数实例化PingPangPlayer对象ppp
|
||||
// 输出'name---age'
|
||||
// 分别调用sleep()、eat()、study()、speak()方法
|
||||
/********* begin *********/
|
||||
PingPangPlayer ppp = new PingPangPlayer(pppName, pppAge);
|
||||
System.out.println(ppp.getName() + "---" + ppp.getAge());
|
||||
ppp.sleep();
|
||||
ppp.eat();
|
||||
ppp.study();
|
||||
ppp.speak();
|
||||
/********* end *********/
|
||||
System.out.println("----------------");
|
||||
// 篮球运动员
|
||||
// 通过带参构造函数实例化BasketballPlayer对象bp
|
||||
// 输出'name---age'
|
||||
// 分别调用sleep()、eat()、study()方法
|
||||
/********* begin *********/
|
||||
BasketballPlayer bp = new BasketballPlayer(bpName, bpAge);
|
||||
System.out.println(bp.getName() + "---" + bp.getAge());
|
||||
bp.sleep();
|
||||
bp.eat();
|
||||
bp.study();
|
||||
/********* end *********/
|
||||
System.out.println("----------------");
|
||||
// 测试教练(乒乓球教练和篮球教练)
|
||||
// 乒乓球教练
|
||||
// 通过带参构造函数实例化PingPangCoach对象ppc
|
||||
// 输出'name---age'
|
||||
// 分别调用sleep()、eat()、teach()、speak()方法
|
||||
/********* begin *********/
|
||||
PingPangCoach ppc = new PingPangCoach(ppcName, ppcAge);
|
||||
System.out.println(ppc.getName() + "---" + ppc.getAge());
|
||||
ppc.sleep();
|
||||
ppc.eat();
|
||||
ppc.teach();
|
||||
ppc.speak();
|
||||
/********* end *********/
|
||||
System.out.println("----------------");
|
||||
// 篮球教练
|
||||
// 通过带参构造函数实例化BasketballCoach对象bc
|
||||
// 输出'name---age'
|
||||
// 分别调用sleep()、eat()、teach()方法
|
||||
/********* begin *********/
|
||||
BasketballCoach bc = new BasketballCoach(bcName, bcAge);
|
||||
System.out.println(bc.getName() + "---" + bc.getAge());
|
||||
bc.sleep();
|
||||
bc.eat();
|
||||
bc.teach();
|
||||
/********* end *********/
|
||||
System.out.println("----------------");
|
||||
}
|
||||
}
|
||||
|
||||
// 说英语接口 声明抽象方法speak()
|
||||
interface SpeakEnglish {
|
||||
/********* begin *********/
|
||||
public abstract void speak();
|
||||
/********* end *********/
|
||||
}
|
||||
|
||||
// 定义人的抽象类Person 封装name和age
|
||||
// 无参构造函数
|
||||
// 有参构造函数初始化name和age
|
||||
// 定义具体方法sleep() 输出'人都是要睡觉的'
|
||||
// 抽象方法eat()(吃的不一样)
|
||||
abstract class Person {
|
||||
/********* begin *********/
|
||||
private String name;
|
||||
private int age;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public int getAge() {
|
||||
return age;
|
||||
}
|
||||
|
||||
public void setAge(int age) {
|
||||
this.age = age;
|
||||
}
|
||||
|
||||
public Person() {
|
||||
}
|
||||
|
||||
public Person(String name, int age) {
|
||||
this.name = name;
|
||||
this.age = age;
|
||||
}
|
||||
|
||||
public void sleep() {
|
||||
System.out.println("人都是要睡觉的");
|
||||
}
|
||||
|
||||
public abstract void eat();
|
||||
/********* end *********/
|
||||
}
|
||||
|
||||
// 定义运动员Player(抽象类)继承自Person类
|
||||
// 无参构造函数
|
||||
// 有参构造函数初始化name和age
|
||||
// 运动员学习内容不一样,抽取为抽象 定义抽象方法study()
|
||||
abstract class Player extends Person {
|
||||
/********* begin *********/
|
||||
public Player() {
|
||||
}
|
||||
|
||||
public Player(String name, int age) {
|
||||
super(name, age);
|
||||
}
|
||||
|
||||
public abstract void study();
|
||||
/********* end *********/
|
||||
}
|
||||
|
||||
// 定义教练Coach(抽象类)继承自Person类
|
||||
// 无参构造函数
|
||||
// 有参构造函数初始化name和age
|
||||
// 教练教的不一样 定义抽象方法teach()
|
||||
abstract class Coach extends Person {
|
||||
/********* begin *********/
|
||||
public Coach() {
|
||||
}
|
||||
|
||||
public Coach(String name, int age) {
|
||||
super(name, age);
|
||||
}
|
||||
|
||||
public abstract void teach();
|
||||
/********* end *********/
|
||||
}
|
||||
|
||||
// 定义乒乓球运动员具体类PingPangPlayer 继承自Player类并实现SpeakEnglish类(兵乓球运动员需要说英语)
|
||||
// 无参构造函数
|
||||
// 有参构造函数初始化name和age
|
||||
// 实现自己的eat()方法 输出'乒乓球运动员吃大白菜,喝小米粥'
|
||||
// 实现自己的study()方法 输出'乒乓球运动员学习如何发球和接球'
|
||||
// 实现自己的speak()方法 输出'乒乓球运动员说英语'
|
||||
class PingPangPlayer extends Player implements SpeakEnglish {
|
||||
/********* begin *********/
|
||||
public PingPangPlayer() {
|
||||
}
|
||||
|
||||
public PingPangPlayer(String name, int age) {
|
||||
super(name, age);
|
||||
}
|
||||
|
||||
public void eat() {
|
||||
System.out.println("乒乓球运动员吃大白菜,喝小米粥");
|
||||
}
|
||||
|
||||
public void study() {
|
||||
System.out.println("乒乓球运动员学习如何发球和接球");
|
||||
}
|
||||
|
||||
public void speak() {
|
||||
System.out.println("乒乓球运动员说英语");
|
||||
}
|
||||
/********* end *********/
|
||||
}
|
||||
|
||||
// 定义篮球运动员具体类BasketballPlayer 继承自Player类 不需要继承接口,因为他不需要说英语
|
||||
// 无参构造函数
|
||||
// 有参构造函数初始化name和age
|
||||
// 实现自己的eat()方法 输出'篮球运动员吃牛肉,喝牛奶'
|
||||
// 实现自己的study()方法 输出'篮球运动员学习如何运球和投篮'
|
||||
class BasketballPlayer extends Player {
|
||||
/********* begin *********/
|
||||
public BasketballPlayer() {
|
||||
}
|
||||
|
||||
public BasketballPlayer(String name, int age) {
|
||||
super(name, age);
|
||||
}
|
||||
|
||||
public void eat() {
|
||||
System.out.println("篮球运动员吃牛肉,喝牛奶");
|
||||
}
|
||||
|
||||
public void study() {
|
||||
System.out.println("篮球运动员学习如何运球和投篮");
|
||||
}
|
||||
/********* end *********/
|
||||
}
|
||||
|
||||
// 定义乒乓球教练具体类 PingPangCoach 继承自Coach类并实现SpeakEnglish类(兵乓球教练需要说英语)
|
||||
// 无参构造函数
|
||||
// 有参构造函数初始化name和age
|
||||
// 实现自己的eat()方法 输出'乒乓球教练吃小白菜,喝大米粥'
|
||||
// 实现自己的teach()方法 输出'乒乓球教练教如何发球和接球'
|
||||
// 实现自己的speak()方法 输出'乒乓球教练说英语'
|
||||
class PingPangCoach extends Coach implements SpeakEnglish {
|
||||
/********* begin *********/
|
||||
public PingPangCoach() {
|
||||
}
|
||||
|
||||
public PingPangCoach(String name, int age) {
|
||||
super(name, age);
|
||||
}
|
||||
|
||||
public void eat() {
|
||||
System.out.println("乒乓球教练吃小白菜,喝大米粥");
|
||||
}
|
||||
|
||||
public void teach() {
|
||||
System.out.println("乒乓球教练教如何发球和接球");
|
||||
}
|
||||
|
||||
public void speak() {
|
||||
System.out.println("乒乓球教练说英语");
|
||||
}
|
||||
/********* end *********/
|
||||
}
|
||||
|
||||
// 定义篮球教练具体类BasketballCoach 继承自Coach类 不需要继承接口,因为他不需要说英语
|
||||
// 无参构造函数
|
||||
// 有参构造函数初始化name和age
|
||||
// 实现自己的eat()方法 输出'篮球教练吃羊肉,喝羊奶'
|
||||
// 实现自己的teach()方法 输出'篮球教练教如何运球和投篮'
|
||||
class BasketballCoach extends Coach {
|
||||
/********* begin *********/
|
||||
public BasketballCoach() {
|
||||
}
|
||||
|
||||
public BasketballCoach(String name, int age) {
|
||||
super(name, age);
|
||||
}
|
||||
|
||||
public void eat() {
|
||||
System.out.println("篮球教练吃羊肉,喝羊奶");
|
||||
}
|
||||
|
||||
public void teach() {
|
||||
System.out.println("篮球教练教如何运球和投篮");
|
||||
}
|
||||
/********* end *********/
|
||||
}
|
||||
+15
-15
@@ -1,15 +1,15 @@
|
||||
//Cuboid.java
|
||||
package task4;
|
||||
|
||||
public class Cuboid extends Rectangle {
|
||||
double height;
|
||||
|
||||
public Cuboid(double length, double width, double height) {
|
||||
super(length, width);
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
public double volume() {
|
||||
return this.length * this.width * this.height;
|
||||
}
|
||||
}
|
||||
//Cuboid.java
|
||||
package task4;
|
||||
|
||||
public class Cuboid extends Rectangle {
|
||||
double height;
|
||||
|
||||
public Cuboid(double length, double width, double height) {
|
||||
super(length, width);
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
public double volume() {
|
||||
return this.length * this.width * this.height;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,24 +1,24 @@
|
||||
//Rectangle.java
|
||||
package task4;
|
||||
|
||||
public class Rectangle {
|
||||
double length;
|
||||
double width;
|
||||
|
||||
public double getPerimeter() {
|
||||
return (this.length + this.width) * 2;
|
||||
}
|
||||
|
||||
public double getArea() {
|
||||
return this.length * this.width;
|
||||
}
|
||||
|
||||
public Rectangle(double length, double width) {
|
||||
this.length = length;
|
||||
this.width = width;
|
||||
}
|
||||
|
||||
public Rectangle() {
|
||||
this(1.0, 1.0);
|
||||
}
|
||||
}
|
||||
//Rectangle.java
|
||||
package task4;
|
||||
|
||||
public class Rectangle {
|
||||
double length;
|
||||
double width;
|
||||
|
||||
public double getPerimeter() {
|
||||
return (this.length + this.width) * 2;
|
||||
}
|
||||
|
||||
public double getArea() {
|
||||
return this.length * this.width;
|
||||
}
|
||||
|
||||
public Rectangle(double length, double width) {
|
||||
this.length = length;
|
||||
this.width = width;
|
||||
}
|
||||
|
||||
public Rectangle() {
|
||||
this(1.0, 1.0);
|
||||
}
|
||||
}
|
||||
|
||||
+20
-20
@@ -1,20 +1,20 @@
|
||||
//Test.java
|
||||
package task4;
|
||||
|
||||
public class Test {
|
||||
public static void main(String[] args) {
|
||||
Rectangle r1 = new Rectangle(3, 4);
|
||||
System.out.println("r1's perimeter:\t" + r1.getPerimeter());
|
||||
System.out.println("r1's area:\t" + r1.getArea());
|
||||
System.out.println("__________________________________");
|
||||
Rectangle r2 = new Rectangle();
|
||||
System.out.println("r2's perimeter:\t" + r2.getPerimeter());
|
||||
System.out.println("r2's area:\t" + r2.getArea());
|
||||
System.out.println("__________________________________");
|
||||
Cuboid c = new Cuboid(3, 4, 5);
|
||||
System.out.println("bottom of c's perimeter:\t" + c.getPerimeter());
|
||||
System.out.println("bottom c's area:\t" + c.getArea());
|
||||
System.out.println("c's volume:\t" + c.volume());
|
||||
}
|
||||
|
||||
}
|
||||
//Test.java
|
||||
package task4;
|
||||
|
||||
public class Test {
|
||||
public static void main(String[] args) {
|
||||
Rectangle r1 = new Rectangle(3, 4);
|
||||
System.out.println("r1's perimeter:\t" + r1.getPerimeter());
|
||||
System.out.println("r1's area:\t" + r1.getArea());
|
||||
System.out.println("__________________________________");
|
||||
Rectangle r2 = new Rectangle();
|
||||
System.out.println("r2's perimeter:\t" + r2.getPerimeter());
|
||||
System.out.println("r2's area:\t" + r2.getArea());
|
||||
System.out.println("__________________________________");
|
||||
Cuboid c = new Cuboid(3, 4, 5);
|
||||
System.out.println("bottom of c's perimeter:\t" + c.getPerimeter());
|
||||
System.out.println("bottom c's area:\t" + c.getArea());
|
||||
System.out.println("c's volume:\t" + c.volume());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
//HelloCollections.java
|
||||
package task1;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class HelloCollections {
|
||||
public ArrayList run() {
|
||||
ArrayList<String> list = new ArrayList<>();
|
||||
list.add("hello, world");
|
||||
return list;
|
||||
}
|
||||
//HelloCollections.java
|
||||
package task1;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class HelloCollections {
|
||||
public ArrayList run() {
|
||||
ArrayList<String> list = new ArrayList<>();
|
||||
list.add("hello, world");
|
||||
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;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
|
||||
public class WalkCollection {
|
||||
public static void main(String[] args) {
|
||||
ArrayList arrayListExample = new ArrayList();
|
||||
// ---------------------Begin------------------------
|
||||
// arrayListExample.add("aaa");
|
||||
// arrayListExample.add("bbb");
|
||||
// arrayListExample.add("ccc");
|
||||
// arrayListExample.add("ddd");
|
||||
// 展示运行结果前删下注释
|
||||
// 使用迭代器iterator遍历arrayListExample集合
|
||||
Iterator itr = arrayListExample.iterator();
|
||||
while (itr.hasNext()) {
|
||||
System.out.println(itr.next());
|
||||
}
|
||||
|
||||
// 使用foreach遍历arrayListExample集合
|
||||
arrayListExample.forEach(System.out::println);
|
||||
// ---------------------End------------------------
|
||||
}
|
||||
package task2;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
|
||||
public class WalkCollection {
|
||||
public static void main(String[] args) {
|
||||
ArrayList arrayListExample = new ArrayList();
|
||||
// ---------------------Begin------------------------
|
||||
// arrayListExample.add("aaa");
|
||||
// arrayListExample.add("bbb");
|
||||
// arrayListExample.add("ccc");
|
||||
// arrayListExample.add("ddd");
|
||||
// 展示运行结果前删下注释
|
||||
// 使用迭代器iterator遍历arrayListExample集合
|
||||
Iterator itr = arrayListExample.iterator();
|
||||
while (itr.hasNext()) {
|
||||
System.out.println(itr.next());
|
||||
}
|
||||
|
||||
// 使用foreach遍历arrayListExample集合
|
||||
arrayListExample.forEach(System.out::println);
|
||||
// ---------------------End------------------------
|
||||
}
|
||||
}
|
||||
+20
-20
@@ -1,21 +1,21 @@
|
||||
package task3;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Scanner;
|
||||
|
||||
public class HelloSet {
|
||||
public static void main(String[] args) {
|
||||
HashSet<Object> hashSet = new HashSet<>();
|
||||
Scanner scanner = new Scanner(System.in);
|
||||
for (int i = 0; i < 5; i++) {
|
||||
hashSet.add(scanner.next());
|
||||
}
|
||||
// ---------------------Begin------------------------
|
||||
hashSet.add("helloHashSet");
|
||||
hashSet.remove("cat");
|
||||
hashSet.add("fish");
|
||||
hashSet.remove("apple");
|
||||
// ---------------------End------------------------
|
||||
hashSet.forEach(ele -> System.out.println(ele));
|
||||
}
|
||||
package task3;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Scanner;
|
||||
|
||||
public class HelloSet {
|
||||
public static void main(String[] args) {
|
||||
HashSet<Object> hashSet = new HashSet<>();
|
||||
Scanner scanner = new Scanner(System.in);
|
||||
for (int i = 0; i < 5; i++) {
|
||||
hashSet.add(scanner.next());
|
||||
}
|
||||
// ---------------------Begin------------------------
|
||||
hashSet.add("helloHashSet");
|
||||
hashSet.remove("cat");
|
||||
hashSet.add("fish");
|
||||
hashSet.remove("apple");
|
||||
// ---------------------End------------------------
|
||||
hashSet.forEach(ele -> System.out.println(ele));
|
||||
}
|
||||
}
|
||||
@@ -1,21 +1,21 @@
|
||||
package task4;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Scanner;
|
||||
|
||||
public class HelloHashMap {
|
||||
public static void main(String[] args) {
|
||||
Scanner scanner = new Scanner(System.in);
|
||||
HashMap hashMapExample = new HashMap<>();
|
||||
for (int i = 0; i < 2; i++) {
|
||||
hashMapExample.put(scanner.next(), scanner.next());
|
||||
}
|
||||
// ---------------------Begin------------------------
|
||||
hashMapExample.put("name", "lihong");
|
||||
hashMapExample.remove("firstkey");
|
||||
hashMapExample.replace("secondkey", "educode");
|
||||
System.out.println(hashMapExample);
|
||||
// ---------------------End------------------------
|
||||
}
|
||||
}
|
||||
package task4;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Scanner;
|
||||
|
||||
public class HelloHashMap {
|
||||
public static void main(String[] args) {
|
||||
Scanner scanner = new Scanner(System.in);
|
||||
HashMap hashMapExample = new HashMap<>();
|
||||
for (int i = 0; i < 2; i++) {
|
||||
hashMapExample.put(scanner.next(), scanner.next());
|
||||
}
|
||||
// ---------------------Begin------------------------
|
||||
hashMapExample.put("name", "lihong");
|
||||
hashMapExample.remove("firstkey");
|
||||
hashMapExample.replace("secondkey", "educode");
|
||||
System.out.println(hashMapExample);
|
||||
// ---------------------End------------------------
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user