用Java写代码:某次软件设计竞赛有5个队伍参赛,比赛中,每个队伍需要说明作品名称、队员人数和阐述自己的作品。为此,测试类命名为:SoftwareCompetition,队伍类名为:Team,它具有私有成员数据:作品名称name,队员人数numberofMember,作品说明introduction,和相应的get和set方法。 测试类的作用:创建具有5个元素的Team数组,人数依次为1,2,3,4,5,请利用循环结构和Scanner对象,进行相应的Team的信息输入,最后输出各队信息(人数直接用循环赋值,不通过输入赋值)。用两个窗口写测试类和队伍类
时间: 2024-02-25 10:55:50 浏览: 112
第十九届中国计量大学ACM程序设计竞赛竞赛规则及平台使用说明.docx
窗口一:Team类
```java
public class Team {
private String name;
private int numberOfMember;
private String introduction;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getNumberOfMember() {
return numberOfMember;
}
public void setNumberOfMember(int numberOfMember) {
this.numberOfMember = numberOfMember;
}
public String getIntroduction() {
return introduction;
}
public void setIntroduction(String introduction) {
this.introduction = introduction;
}
}
```
窗口二:SoftwareCompetition类
```java
import java.util.Scanner;
public class SoftwareCompetition {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
Team[] teams = new Team[5];
int[] numberOfMembers = {1, 2, 3, 4, 5};
for (int i = 0; i < teams.length; i++) {
Team team = new Team();
System.out.println("请输入第" + (i + 1) + "个队伍的作品名称:");
team.setName(scanner.nextLine());
team.setNumberOfMember(numberOfMembers[i]);
System.out.println("请输入第" + (i + 1) + "个队伍的作品说明:");
team.setIntroduction(scanner.nextLine());
teams[i] = team;
}
System.out.println("各队信息如下:");
for (int i = 0; i < teams.length; i++) {
System.out.println("第" + (i + 1) + "个队伍的作品名称:" + teams[i].getName());
System.out.println("第" + (i + 1) + "个队伍的队员人数:" + teams[i].getNumberOfMember());
System.out.println("第" + (i + 1) + "个队伍的作品说明:" + teams[i].getIntroduction());
System.out.println("--------------------");
}
}
}
```
阅读全文