马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
Scanner banzhang1 = new Scanner(System.in);
String getName = banzhang1.nextLine();
System.out.println();这个就是要完成这个任务是代码,没有写完,不会写了,求帮助package lianxi;
import java.util.Scanner;
import jdk.internal.util.xml.impl.Input;
public class MyClass {
public MyStudent s1;
public MyStudent s2;
public MyStudent s3;
public void Myclass()
{
s1 = new MyStudent();
s2 = new MyStudent();
s3 = new MyStudent();
}
public int getTotal()
{
return s1.getTotalScore() + s2.getTotalScore() + s3.getTotalScore();
}
public static void main(String[] args) {
MyClass c1,c2;
c1 = new MyClass();
c2 = new MyClass();
c1.s1 = new MyStudent();
c1.s2 = new MyStudent();
c1.s3 = new MyStudent();
c2.s1 = new MyStudent();
c2.s2 = new MyStudent();
c2.s3 = new MyStudent();
c1.s1.getName("张三");
c1.s1.sex = "男";
c1.s1.EnglishScore = 90;
c1.s1.LinuxScore = 96;
c1.s1.JavaScore = 87;
c1.s1.TotalScore = c1.s1.EnglishScore +c1.s1.LinuxScore +c1.s1.JavaScore;
c1.s2.getName("李四");
c1.s2.sex = "男";
c1.s2.EnglishScore = 90;
c1.s2.LinuxScore = 76;
c1.s2.JavaScore = 80;
c1.s2.TotalScore = c1.s2.EnglishScore +c1.s2.LinuxScore +c1.s2.JavaScore;
c1.s3.getName("王五");
c1.s3.sex = "女";
c1.s3.EnglishScore = 95;
c1.s3.LinuxScore = 95;
c1.s3.JavaScore = 87;
c1.s3.TotalScore = c1.s3.EnglishScore +c1.s3.LinuxScore +c1.s3.JavaScore;
c2.s1.getName("甲");
c2.s1.sex = "女";
c2.s1.EnglishScore = 95;
c2.s1.LinuxScore = 95;
c2.s1.JavaScore = 89;
c2.s1.TotalScore = c2.s1.EnglishScore +c2.s1.LinuxScore +c2.s1.JavaScore;
c2.s2.getName("乙");
c2.s2.sex = "女";
c2.s2.EnglishScore = 95;
c2.s2.LinuxScore = 85;
c2.s2.JavaScore = 87;
c2.s2.TotalScore = c2.s2.EnglishScore +c2.s2.LinuxScore +c2.s2.JavaScore;
c2.s3.getName("丙");
c2.s3.sex = "男";
c2.s3.EnglishScore = 75;
c2.s3.LinuxScore = 95;
c2.s3.JavaScore = 89;
c2.s3.TotalScore = c2.s1.EnglishScore +c2.s1.LinuxScore +c2.s1.JavaScore;
System.out.println("一班总成绩:"+c1.getTotal());
System.out.println("二班总成绩:"+c2.getTotal());
System.out.println("一班班长为:");
Scanner banzhang1 = new Scanner(System.in);
String getName = banzhang1.nextLine();
System.out.println();
// Scanner sc = new Scanner(System.in);
// String getName =sc.next();
// for sc in c1.getClass();
// System.println("总成绩为:"+c1.TotalScore());
// sc.TotalScore = TotalScore;
}
}
package lianxi;
public class MyStudent {
String name;
String sex;
int EnglishScore;
int LinuxScore;
int JavaScore;
int TotalScore;
public MyStudent() {
}
public MyStudent(String name, String sex, int EnglishScore,int LinuxScore, int JavaScore, int TotalScore
) {
super();
this.name = name;
this.sex = sex;
this.EnglishScore = EnglishScore;
this.LinuxScore = LinuxScore;
this.JavaScore = JavaScore;
this.TotalScore = TotalScore;
}
public String getName() {//1 name
return name;
}
public void getName(String name) {
this.name = name;
}
public String getSex() {//2 sex
return sex;
}
public void getSex(String sex) {
this.sex = sex;
}
public int getEnglishScore() {//3 EnglishScore
return EnglishScore;
}
public void getEnglishScore(int EnglishScore) {
this.EnglishScore = EnglishScore;
}
public int getLinuxScore() {//4 LinuxScore
return LinuxScore;
}
public void getLinuxScore(int LinuxScore) {
this.LinuxScore = LinuxScore;
}
public int getJavaScore() {//5 JavaScore
return JavaScore;
}
public void getJavaScore(int JavaScore) {
this.JavaScore = JavaScore;
}
public int getTotalScore() {//6 TotalScore
return TotalScore;
}
public void getTotalScore(int TotalScore) {
this.TotalScore = TotalScore;//EnglishScore+LinuxScore+JavaScore
}
}
我帮你改好了,累死我了, 要是不给我个最佳答案-》以后就不回答你的问题了哈!!! 太累了
首先说明一波:
你的:MyStudent.java这个文件是不用改的!
需要改的仅仅是:MyClass.java 且解释全在注释里了,而且我认为算是比较详细得了,累啊
我自认为我写的 满足了你的所有需求!
代码如下:package lianxi;
import java.util.Scanner;
public class MyClass {
public MyStudent s1;
public MyStudent s2;
public MyStudent s3;
public MyClass()
{
s1=new MyStudent();
s2=new MyStudent();
s3=new MyStudent();
}
//应该加上参数的,不然怎么知道要返回谁的成绩信息呢
public void getTotal(String s,MyClass mc)
{
if(s.equals("张三")){
System.out.println("姓名:"+mc.s1.name+" 性别:"+mc.s1.sex+" 英语成绩:"+s1.EnglishScore+"Linux成绩:"+s1.LinuxScore+" Java成绩:"+s1.JavaScore+" Total的成绩:"+mc.s1.TotalScore); ;
}
if(s.equals("李四")){
System.out.println("姓名:"+mc.s2.name+" 性别:"+mc.s2.sex+" 英语成绩:"+mc.s2.EnglishScore+"Linux成绩:"+mc.s2.LinuxScore+" Java成绩:"+mc.s2.JavaScore+" Total的成绩:"+mc.s2.TotalScore); ;
}
if(s.equals("王五")){
System.out.println( "姓名:"+mc.s3.name+" 性别:"+mc.s3.sex+" 英语成绩:"+mc.s3.EnglishScore+"Linux成绩:"+mc.s3.LinuxScore+" Java成绩:"+mc.s3.JavaScore+" Total的成绩:"+mc.s3.TotalScore);
}
if(s.equals("王翠花")){
System.out.println("姓名:"+mc.s3.name+" 性别:"+mc.s3.sex+" 英语成绩:"+mc.s3.EnglishScore+"Linux成绩:"+mc.s3.LinuxScore+" Java成绩:"+mc.s3.JavaScore+" Total的成绩:"+mc.s3.TotalScore);
}
if(s.equals("甲")){
System.out.println("姓名:"+mc.s1.name+" 性别:"+mc.s1.sex+" 英语成绩:"+mc.s1.EnglishScore+"Linux成绩:"+mc.s1.LinuxScore+" Java成绩:"+mc.s1.JavaScore+" Total的成绩:"+mc.s1.TotalScore);
}
if(s.equals("乙")){
System.out.println("姓名:"+mc.s2.name+" 性别:"+mc.s2.sex+" 英语成绩:"+mc.s2.EnglishScore+"Linux成绩:"+mc.s2.LinuxScore+" Java成绩:"+mc.s2.JavaScore+" Total的成绩:"+mc.s2.TotalScore);
}
if(s.equals("王翠翠")){
System.out.println("姓名:"+mc.s1.name+" 性别:"+mc.s1.sex+" 英语成绩:"+mc.s1.EnglishScore+"Linux成绩:"+mc.s1.LinuxScore+" Java成绩:"+mc.s1.JavaScore+" Total的成绩:"+mc.s1.TotalScore);
}
//return "你所输入的姓名不存在,请重新输入!";
}
//main方法
public static void main(String[] args){
//因为你的实例化是再Myclass中所以需要实例化MyClass如下:
MyClass Myclass = new MyClass();
//第一个人的
Myclass.s1.setName("张三");
Myclass.s1.setSex("男");
Myclass.s1.setEnglishScore(90);
Myclass.s1.setLinuxScore(96);
Myclass.s1.setJavaScore(87);
Myclass.s1.setTotalScore(Myclass.s1.EnglishScore+Myclass.s1.JavaScore+Myclass.s1.LinuxScore);//这么写也是挺六的感觉
//第二个人的
Myclass.s2.setName("李四");
Myclass.s2.setSex("男");
Myclass.s2.setEnglishScore(91);
Myclass.s2.setLinuxScore(81);
Myclass.s2.setJavaScore(87);
Myclass.s2.setTotalScore(Myclass.s2.EnglishScore+Myclass.s2.JavaScore+Myclass.s2.LinuxScore);
//第三个人的
Myclass.s3.setName("王翠花");
Myclass.s3.setSex("女");
Myclass.s3.setEnglishScore(92);
Myclass.s3.setLinuxScore(92);
Myclass.s3.setJavaScore(82);
Myclass.s3.setTotalScore(Myclass.s3.EnglishScore+Myclass.s3.JavaScore+Myclass.s3.LinuxScore);
MyClass Myclass2 = new MyClass();
//第一个人的
Myclass2.s1.setName("甲");
Myclass2.s1.setSex("男");
Myclass2.s1.setEnglishScore(93);
Myclass2.s1.setLinuxScore(83);
Myclass2.s1.setJavaScore(73);
Myclass2.s1.setTotalScore(Myclass2.s1.EnglishScore+Myclass2.s1.JavaScore+Myclass2.s1.LinuxScore);
//第二个人的
Myclass2.s2.setName("乙");
Myclass2.s2.setSex("男");
Myclass2.s2.setEnglishScore(84);
Myclass2.s2.setLinuxScore(84);
Myclass2.s2.setJavaScore(74);
Myclass2.s2.setTotalScore(Myclass2.s2.EnglishScore+Myclass2.s2.JavaScore+Myclass2.s2.LinuxScore);
//第三个人的
Myclass2.s3.setName("王翠翠");
Myclass2.s3.setSex("女");
Myclass2.s3.setEnglishScore(95);
Myclass2.s3.setLinuxScore(85);
Myclass2.s3.setJavaScore(75);
Myclass2.s3.setTotalScore(Myclass2.s3.EnglishScore+Myclass2.s3.JavaScore+Myclass2.s3.LinuxScore);
//接收用户输入
System.out.print("请输入班级:");
Scanner sc=new Scanner(System.in);
int bj = sc.nextInt();
if(bj==1){
System.out.print("请输入姓名:");
Scanner sc1 = new Scanner(System.in);
String name = sc1.nextLine();
System.out.println(name);
//用js接收返回的字符串
Myclass.getTotal(name, Myclass);
//System.out.println(js);
}else if(bj==2){
System.out.print("请输入姓名:");
Scanner sc2 = new Scanner(System.in);
String name = sc2.nextLine();
//用js接收返回的字符串
Myclass2.getTotal(name, Myclass2);
//System.out.println(js);
}else{
System.out.println("你输入的班级不存在!");
}
}
}
执行效果如下:
OK 希望对你有用吧
|