//要实现对象间的比较,就必须实现Comparable接口,它里面有个compareTo方法
//Comparable最好使用泛型,这样,无论是速度还是代码量都会减少
@SuppressWarnings("unchecked")
class Student implements ComparableStudent{
private String studentNo; //学号
private String studentName; //姓名
private double englishScore; //英语成绩
private double computerScore; //计算机成绩
private double mathScore; //数学成绩
private double totalScore; //总成绩
//空构造函数
public Student() {}
//构造函数
public Student(String studentNo,String studentName,double englishSocre,double computerScore,double mathScore) {
this.studentNo = studentNo;
this.studentName = studentName;
this.englishScore = englishSocre;
this.computerScore = computerScore;
this.mathScore = mathScore;
}
//计算总成绩
public double sum() {
this.totalScore = englishScore◆computerScore◆mathScore;
return totalScore;
//计算评测成绩
public double testScore() {
//实现compareTO方法
@Override
public int compareTo(Student student) {
double studentTotal = student.getTotalScore();
return totalScore==studentTotal?0:(totalScorestudentTotal?1:-1);
//重写toString方法
public String toString(){
return "学号:"◆this.getStudentNo()◆" 姓名:"◆this.getStudentName()◆" 英语成绩:"◆this.getEnglishScore()◆" 数学成绩:"◆this.getMathScore()◆" 计算机成绩:"◆this.getComputerScore()◆" 总成绩:"◆this.getTotalScore();
//重写equals方法
public boolean equals(Object obj) {
if(obj == null){
return false;
if(!(obj instanceof Student)){
Student student = (Student)obj;
if(this.studentNo.equals(student.getStudentName())) { //照现实来说,比较是不是同一个学生,应该只是看他的学号是不是相同
return true;
} else {
/*以下为get和set方法,我个人认为,totalScore的set的方法没必要要,因为它是由其它成绩计算出来的
在set方法中,没设置一次值,调用一次sum方法,即重新计算总成绩
*/
public String getStudentNo() {
return studentNo;
public void setStudentNo(String studentNo) {
sum();
public String getStudentName() {
return studentName;
public void setStudentName(String studentName) {
public double getEnglishScore() {
return englishScore;
public void setEnglishScore(double englishScore) {
this.englishScore = englishScore;
public double getComputerScore() {
return computerScore;
public void setComputerScore(double computerScore) {
public double getMathScore() {
return mathScore;
public void setMathScore(double mathScore) {
public double getTotalScore() {
//Student子类学习委员类的实现
class StudentXW extends Student {
//重写父类Student的testScore()方法
public StudentXW() {}
//StudentXW的构造函数
public StudentXW(String studentNo,String studentName,double englishSocre,double computerScore,double mathScore) {
super(studentNo,studentName,englishSocre,computerScore,mathScore);
//Student子类班长类的实现
class StudentBZ extends Student {
public StudentBZ() {}
public StudentBZ(String studentNo,String studentName,double englishSocre,double computerScore,double mathScore) {
//测试类
public class Test {
public static void main(String[] args) {
//生成若干个student类、StudentXW类、StudentBZ类
for(int i = 0 ; istudents.length; i◆◆){
double avgScore = students[i].testScore();
System.out.println(students[i].getStudentName()◆"学生的评测成绩为:"◆ avgScore◆"分");
运行结果为:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class ConstructFrame extends JFrame
{
private static final long serialVersionUID = 1L;
int flag=0,fix=0,sum=1;
Boolean happy;
int flagsum=0;
Container c=getContentPane();
JButton buttonx;
ConstructFrame()
{ super("计算器");
c.setLayout(null);
c.setBackground(Color.blue);
c.add(text);
text.setHorizontalAlignment(JTextField.RIGHT);
final JButton buttonx=new JButton("BackSpace");
c.add(buttonx);
buttonx.addMouseListener(new MouseAdapter()
public void mousePressed(MouseEvent e)
int count=0;
String temp;
if(flag==0)
count=value1.length();
if(count!=1)
temp=value1.substring(0, count-1);
else
temp="0";
value1=temp;
text.setText(temp);
});
final JButton buttony=new JButton("CE");
c.add(buttony);
buttony.addMouseListener(new MouseAdapter()
value1="";
flag=0;
text.setText("0");
final JButton button1=new JButton("1");
c.add(button1);
button1.addMouseListener(new MouseAdapter()
value1=value1◆1;
temp=value1;
final JButton button0=new JButton("0");
c.add(button0);
button0.addMouseListener(new MouseAdapter()
value1=value1◆0;
final JButton buttonadd=new JButton(" ◆ ");
c.add(buttonadd);
buttonadd.addMouseListener(new MouseAdapter()
flag=1;
fix=1;
flagsum=0;
final JButton buttonsubtract=new JButton(" - ");
c.add(buttonsubtract);
buttonsubtract.addMouseListener(new MouseAdapter()
final JButton buttoncheng=new JButton(" * ");
c.add(buttoncheng);
buttoncheng.addMouseListener(new MouseAdapter()
final JButton buttonchu=new JButton(" / ");
c.add(buttonchu);
buttonchu.addMouseListener(new MouseAdapter()
final JButton buttonequal=new JButton(" = ");
c.add(buttonequal);
buttonequal.addMouseListener(new MouseAdapter()
double temp=0;
temp1=Double.parseDouble(value1);
switch(fix)
result=Double.valueOf(temp).toString();
value1=result;
text.setText(result);
final JButton buttonpoint=new JButton(".");
c.add(buttonpoint);
buttonpoint.addMouseListener(new MouseAdapter()
{ if(flagsum==0)
if(flag==0 )
value1=value1◆".";
flagsum=1;
JButton buttonz=new JButton("Start");
c.add(buttonz);
buttonz.addMouseListener(new MouseAdapter()
happy=true;
text.setText("0.");
happy=false;
text.setText("");
text.setEnabled(happy);
button1.setEnabled(happy);
button0.setEnabled(happy);
buttonx.setEnabled(happy);
buttony.setEnabled(happy);
buttonadd.setEnabled(happy);
buttonsubtract.setEnabled(happy);
buttonpoint.setEnabled(happy);
buttonequal.setEnabled(happy);
buttoncheng.setEnabled(happy);
buttonchu.setEnabled(happy);
sum◆◆;
button1.setEnabled(false);
button0.setEnabled(false);
buttonx.setEnabled(false);
buttony.setEnabled(false);
buttonadd.setEnabled(false);
buttonsubtract.setEnabled(false);
buttonpoint.setEnabled(false);
buttonequal.setEnabled(false);
buttoncheng.setEnabled(false);
buttonchu.setEnabled(false);
text.setEnabled(false);
setVisible(true);
class MYMouseEvent extends MouseAdapter
value1=e.toString();
text.setText(value1);
class Calutator
public static void main(String[] args)
new ConstructFrame();
你自己慢慢的看吧!
public class TestStar {
String star = "*";
if (i == 0) {
System.out.print(" " ◆ star);
System.out.println();
if (i == 1) {
System.out.print(" ");
System.out.print(" " ◆ star ◆ " ");
是好使的 但是我没找到画五角星有什么规律(五角星好象不是正规图形吧?)如果还有什么要求的话 补充问题(如果是用*填充所有的东西 不包括 " "的话 我可以重新再给你写一个)
while(true){
//你的程序
System.out.println("再玩一次?");
String st= scan.next();
if( st=="y"){continue;}
if( st=="n"){break;}
System.out.println("既不是y也不是n,出错");
这只是一个找规律的题而已,找好规律了,谁都会做.
import java.util.Arrays;
import java.util.Scanner;
public class Kuaile {
Scanner in = new Scanner(System.in);
int num = in.nextInt();
System.out.println("数值太小了!请重输:");
num = in.nextInt();
System.out.println(Arrays.toString(row1));
以上就是土嘎嘎小编为大家整理的简单数独java源代码相关主题介绍,如果您觉得小编更新的文章只要能对粉丝们有用,就是我们最大的鼓励和动力,不要忘记讲本站分享给您身边的朋友哦!!