忘记丶只是借口 忘记丶只是借口
Let
关注数: 31 粉丝数: 23 发帖数: 3,168 关注贴吧数: 55
【求解】谁能帮我改下!!!! 标题要长。。。。。 //我想把下面的所有Keyboard全部改成Scanner 的,开头的import java.util.Scanner 和static Scanner sc=new Scanner(System.in);这个我知道,但是最后的main方法中的不知道怎么改成和keyboard一样的效果。希望能有人帮忙改下!! 先谢谢了 import tools.Keyboard; //1.Student类定义 //学生抽象类 abstract class Student{ private String id; private String name; private int eng; private int math; private int comp; public static int MUM_OF_TEST = 3; // 构造方法 public Student(){} public Student(String id, String name, int eng, int math, int comp){ this.id = id; this.name = name; this.eng = eng; this.math = math; this.comp =comp; } public Student(Student s){ this.id = s.id; this.name = new String(s.name); this.eng = s.eng; this.math = s.math; this.comp = s.comp; } //get、set方法 public String getId() { return id; } public void setId(String id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public int getEng() { return eng; } public void setEng(int eng) { this.eng = eng; } public int getMath() { return math; } public void setMath(int math) { this.math = math; } public int getComp() { return comp; } public void setComp(int comp) { this.comp = comp; } public String toString(){ return "学号为:"+getId()+"\t"+"姓名为:"+getName()+"\t"+"英语成绩为:"+getEng()+"\t"+"数学成绩为:"+"\t"+"计算机成绩为;"+getComp()+"分\t"; } // 比较两个Student对象的学号是否相等 public boolean equals(Object anObject){ if(this.getClass() !=anObject.getClass()){ } if(anObject instanceof Student){ Student b = (Student)anObject; return(this.getId().equals(b.getId())); } return false; } // 显示学生记录 public void display(){ System.out .println(toString()+"\n"+"总成绩为"+sum()+"分\t\t"+"平均成绩为"+average()+"分"); }//display方法结束 // 计算总成绩 abstract int sum(); // 计算平均成绩 abstract int average(); }//Student类结束 // UndergraduateStudent类定义 // 声明UndergraduateStudent(本科生类) class UndergraduateStudent extends Student{ int grade;//论文分数 String article;//论文标题 public UndergraduateStudent(){} public UndergraduateStudent(String id, String name, int eng, int math, int comp, int grade, String article){ super(id, name, eng, math, comp); this.setGrade(grade); this.setArticle(article); } public UndergraduateStudent(UndergraduateStudent graStudent){ super(graStudent); this.article = graStudent.getArticle(); } // get、set方法 public int getGrade() { return grade;
帮我看下里面other是什么意思? public class ComplexTest { public static void main(String[] args) { Complex c = new Complex(3,5); Complex d = new Complex(2,2); System.out .println("复数运算"); System.out .println("第一个复数>>" + c); System.out .println("第二个复数>>" + d); System.out .println("两复数相加"); System.out .println(c + " + " + d + " = " + c.add(d)); System.out .println(c + " + " + 2 + ")" + " = " + c.add(2)); System.out .println("两复数相减"); System.out .println(c + " - " + d + " = " + c.subtract(d)); System.out .println(c + " - " + 2 + ")" + " = " + c.subtract(2)); System.out .println("两复数相乘"); System.out .println(c + " * " + d + " = " + c.multiply(d)); System.out .println(c + " * " + 2 + ")" + " = " + c.multiply(2)); } } //声明复数类 class Complex{ private double real; private double imaginary; //构造方法 public Complex(){ this(0.0,0.0); } public Complex(double real, double imaginary){ this.real=real; this.imaginary=imaginary; } public Complex(Complex c){ this(c.getReal(), c.getImaginary()); } //get,set方法 public double getReal() { return real; } public void setReal(double real) { this.real = real; } public double getImaginary() { return imaginary; } public void setImaginary(double imaginary) { this.imaginary = imaginary; } //两个复数相加 public Complex add(double real){ return new Complex(this.real+real,this.imaginary); } public Complex add(Complex other){ return add(this,other); } private Complex add(Complex c1,Complex c2){ return new Complex(c1.real+c2.real,c1.imaginary+c2.imaginary); } //两个复数相减 public Complex subtract(double real){ return new Complex(this.real - real,this.imaginary); } public Complex subtract(Complex other){ return subtract(this, other); } private Complex subtract(Complex c1,Complex c2){ return new Complex(c1.real - c2.real,c1.imaginary - c2.imaginary); } //两个复数相乘 public Complex multiply(double c){ return new Complex(this.real * c,this.imaginary * c); } public Complex multiply(Complex other){ return multiply(this, other); } private Complex multiply(Complex c1, Complex c2){ return new Complex(c1.real* c2.real - c1.imaginary* c2.imaginary, c1.real* c2.imaginary + c2.real* c1.imaginary); } public String toString(){ return"("+real+"+"+imaginary+"i"+")"; } }
1 下一页