Java课程设计完整版

补充之前的java课程设计,不仅仅只有方法,更加人性化的在控制台给予提示输入,加入了键盘输入的代码
下面是源码,很长的

前两个类仅仅是判断是多了equals()方法,不知道为什么,加入了键盘输入方法就必须这么判断,
可能以前不规范吧

package qfy;
class myclass implements Comparable<myclass>{
    String classnum;
    String classname;
    String classyuan;
    String classtest;
    String classtype;
    String type;
    public myclass(String num,String name,String yuan,String test){
        classnum=num;
        classname=name;
        classtest=test;
        classyuan=yuan;

    }
//获得到所有的属性
    public String getMyclass(){
        return classnum+" "+classname+" "+classyuan+" "+classtest;
    }
//通过判断传来的字符串,来选择性修改某个属性,老方法
    public String changeMyclass(String classtype,String now){
       if(classtype.equals("成绩")){
           this.classtest=now;
           return this.classtype;
       }
       if(classtype.equals("学号")){
           return this.classnum=now;
       }
       if(classtype.equals("姓名")){
           return this.classname=now;
       }
       if(classtype.equals("学院")){
           return this.classyuan=now;
       }
       return "ok";
    }
    public String getClassname(){
        return classname;
    }
    public int compareTo(myclass o) {
        // TODO Auto-generated method stub
        return this.classtest.compareTo(o.classtest);
    }

}
package qfy;

class teacher implements Comparable<teacher> {
    String teachernum;
    String teachername;
    String teachertel;
    public teacher(String num,String name,String tel){
        teachertel=tel;
        teachername=name;
        teachernum=num;


    }
    //获得到所有的属性
        public String getTeacher(){
            return teachernum+" "+teachername+" "+teachertel;
        }
    //通过判断传来的字符串,来选择性修改某个属性
        public String changeTeacher(String classtype,String now){
           if(classtype=="teachernum"){
               return this.teachernum=now;
           }
           if(classtype=="teachername"){
               return this.teachername=now;
           }
           if(classtype=="teachertel"){
               return this.teachertel=now;
           }
           return "ok";
        }
        public String getTeachername(){
            return teachername;
        }
        public int compareTo(teacher o) {
            // TODO Auto-generated method stub
            return this.teachernum.compareTo(o.teachernum);
        }

    }

下面的两个改变的比较大,主要是加入了键盘输入

package qfy;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class test {
    public static void main(String[] args) throws IOException {
        System.out.println("欢迎进入学生系统");
        List<myclass> list = new ArrayList<myclass>();
        // 添加OK

        // 查找OK
        //
        // 改变OK
        // 

        // 删除调用OK
        // 
        // System.out.println(list.size());
        // 排序调用
        // 
        while (true) {
            System.out.println("请输入想要进行的操作");
            Scanner in = new Scanner(System.in);
            System.out.println("添加"+" "+"查找"+" "+"修改"+" "+"删除"+" "+"排序");
            String string = in.next();
            if(string.equals("添加")){
                addclass(list);
            }
            if(string.equals("查找")){
                getMyClass(list);
            }
            if(string.equals("修改")){
                changetype(list);
            }
            if(string.equals("删除")){
                remove(list);
            }
            if(string.equals("排序")){
                sort(list);
            }
            File file = new File("myclass.db");
            if (!file.exists()) {
                file.createNewFile();
            }
            // 写
            FileWriter fw = new FileWriter(file);
            for (int i = 0; i < list.size(); i++) {
                String result = myclassToString(list.get(i));
                fw.write(result + "\n");
            }
            fw.close();
            System.out.println("========================================");
            // 读
            BufferedReader br = new BufferedReader(new FileReader(file));
            String temp;
            while ((temp = br.readLine()) != null) {
                System.out.println(temp);
            }
            br.close();

        }
    }

    // 删除的方法
    public static void remove(List<myclass> list) {
        int i = 0;
        Scanner in = new Scanner(System.in);
        System.out.println("请输入删除对象的名字");
        String name = in.next();
        int j=0;
        for (i = 0; i < list.size(); i++) {
            if (list.get(i).getClassname().equals(name)) {
                list.remove(i);
                System.out.println("删除成功");
                j=1;
                break;
            }
        }
        if (j==0) {
            System.out.println("查无此人,请输入正确人名");
        }
    }

    // 排序方法
    public static void sort(List<myclass> list) {
        Collections.sort(list);
        for (int i = 0; i < list.size(); i++) {
            System.out.println(list.get(i).getMyclass());
        }
    }

    // 变成字符串
    public static String myclassToString(myclass my) {
        String result = null;
        StringBuffer mystr = new StringBuffer();
        mystr.append(my.classnum + " ");
        mystr.append(my.classname + " ");
        mystr.append(my.classyuan + " ");
        mystr.append(my.classtest + " ");
        result = mystr.toString();
        return result;
    }

    // 查找
    public static void getMyClass(List<myclass> list) {
        Scanner in = new Scanner(System.in);
        System.out.println("请输入所知任意信息");
        String string = in.next();
        for (int i = 0; i < list.size(); i++) {
            if ((list.get(i).getMyclass()).indexOf(string) != -1) {
                System.out.println("资料如下");
                System.out.println(list.get(i).getMyclass());
                break;
            } else {
                System.out.println("查无此人");
                break;
            }
        }
    }

    // 添加方法
    public static void addclass(List<myclass> list) {
        Scanner in = new Scanner(System.in);
        System.out.println("请输入学号");
        String num = in.next();
        System.out.println("请输入姓名");
        String name = in.next();
        System.out.println("请输入学院");
        String yuan = in.next();
        System.out.println("请输入成绩");
        String test = in.next();
        list.add(new myclass(num, name, yuan, test));
    }

    // 改变方法 changetype(list,"classname","ly", "qqq");
    public static void changetype(List<myclass> list) {
        // char saveoldtype=oldtype;
        Scanner in = new Scanner(System.in);
        System.out.println("请输入该人任意信息");
        String classtype = in.nextLine();
        System.out.println("请输入原来信息");
        String oldtype = in.nextLine();
        System.out.println("请输入修改信息");
        String now = in.nextLine();
        for (int i = 0; i < list.size(); i++) {
            if ((list.get(i).getMyclass()).indexOf(oldtype) != -1) {
                System.out.println("修改完成,结果如下");
                list.get(i).changeMyclass(classtype, now);
                System.out.println(list.get(0).getMyclass());
                break;
            } else {
                System.out.println("没有资料,无法修改");
                break;
            }
        }
    }
}
package qfy;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class test_teacher {
    public static void main(String[] args) throws IOException {
        List<teacher> list = new ArrayList<teacher>();
        System.out.println("欢迎进入老师系统");
        while (true) {
            System.out.println("请输入想要进行的操作");
            Scanner in = new Scanner(System.in);
            System.out.println("添加"+" "+"查找"+" "+"修改"+" "+"删除"+" "+"排序");
            String string = in.next();
            if(string.equals("添加")){
                addclass(list);
            }
            if(string.equals("查找")){
                getTeaCher(list);
            }
            if(string.equals("修改")){
                changetype(list);
            }
            if(string.equals("删除")){
                remove(list);
            }
            if(string.equals("排序")){
                sort(list);
            }
            File file = new File("myclass.db");
            if (!file.exists()) {
                file.createNewFile();
            }
            // 写
            FileWriter fw = new FileWriter(file);
            for (int i = 0; i < list.size(); i++) {
                String result = teacherToString(list.get(i));
                fw.write(result + "\n");
            }
            fw.close();
            System.out.println("========================================");
            // 读
            BufferedReader br = new BufferedReader(new FileReader(file));
            String temp;
            while ((temp = br.readLine()) != null) {
                System.out.println(temp);
            }
            br.close();

        }
    }




    // 删除的方法
    public static void remove(List<teacher> list) {
        int i = 0;
        Scanner in = new Scanner(System.in);
        System.out.println("请输入删除对象的名字");
        String name = in.next();
        int j=0;
        for (i = 0; i < list.size(); i++) {
            if (list.get(i).getTeachername().equals(name)) {
                list.remove(i);
                System.out.println("删除成功");
                j=1;
                break;
            }
        }
        if (j==0) {
            System.out.println("查无此人,请输入正确人名");
        }
    }

    // 排序方法
    public static void sort(List<teacher> list) {
        Collections.sort(list);
        for (int i = 0; i < list.size(); i++) {
            System.out.println(list.get(i).getTeacher());
        }
    }

    // 变成字符串
    public static String teacherToString( teacher teacher) {
        String result = null;
        StringBuffer mystr = new StringBuffer();
        mystr.append(teacher.teachernum + " ");
        mystr.append(teacher.teachername + " ");
        mystr.append(teacher.teachertel+" ");
        result = mystr.toString();
        return result;
    }

    // 查找
    public static void getTeaCher(List<teacher> list) {
        Scanner in = new Scanner(System.in);
        System.out.println("请输入所知任意信息");
        String string = in.next();
        for (int i = 0; i < list.size(); i++) {
            if((list.get(i).getTeacher()).indexOf(string)!=-1){
                System.out.println("资料如下");
                System.out.println(list.get(i).getTeacher());
                break;
            }else{
                System.out.println("查无此人");
                break;
            }
        }
    }
    //添加
    public static void addclass(List<teacher> list){
        Scanner in = new Scanner(System.in);
        System.out.println("请输入学号");
        String num = in.next();
        System.out.println("请输入姓名");
        String name = in.next();
        System.out.println("请输入电话");
        String tel = in.next();
        list.add(new teacher(num, name, tel));
    }
    //改变方法  changetype(list,"teachername","qfy", "qqq");
        public static void changetype(List<teacher> list){
            //char saveoldtype=oldtype;
            Scanner in = new Scanner(System.in);
            System.out.println("请输入该人任意信息");
            String classtype = in.nextLine();
            System.out.println("请输入原来信息");
            String oldtype = in.nextLine();
            System.out.println("请输入修改信息");
            String now = in.nextLine();
            for (int i = 0; i < list.size(); i++) {
                if((list.get(i).getTeacher()).indexOf(oldtype)!=-1){
                    System.out.println("修改完成,结果如下");
                    list.get(i).changeTeacher(classtype,now);
                    System.out.println(list.get(0).getTeacher());
                    break;
                }else{
                    System.out.println("没有资料,无法修改");
                    break;
                }
            }
        }

}
<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>html5 游戏</title> <script language="javascript" type="text/javascript"> //定义键盘值 var KEY = { D: 68, W: 87, A: 65, S:83, RIGHT:39, UP:38, LEFT:37, DOWN:40, QUICK:17}; //定义输入对象 var input = { right : false, up : false, left : false, down : false, quick : false }; //小球对象 var player = { speed : 1, qspeed : 2, left : 0, top : 0, xleft : 0, dleft : 0, xtop : 0, dtop : 0, r : 5 } player.init = function(){ this.xleft = this.r; this.xtop = this.r; this.dleft = $("myCanvas").width-this.r; this.dtop = $("myCanvas").height-this.r; this.left = $("myCanvas").width/2; this.top = $("myCanvas").height/2; } player.getSpeed = function(){ return (input.quick?this.qspeed:this.speed); } player.update = function(){ if (input.right) player.left+=player.getSpeed(); if (input.left) player.left-=player.getSpeed(); if (input.down) player.top+=player.getSpeed(); if (input.up) player.top-=player.getSpeed(); if (player.left>player.dleft) player.left=player.dleft; if (player.left<player.xleft) player.left=player.xleft; if (player.top>player.dtop) player.top=player.dtop; if (player.top<player.xtop) player.top=player.xtop; var c=$("myCanvas"); var cxt=c.getContext("2d"); cxt.fillStyle="#FF0000"; cxt.beginPath(); cxt.arc(player.left,player.top,player.r,0,Math.PI * 2,true); cxt.closePath(); cxt.fill(); } //星星 var star = function(){ this.x = 0; this.y = 0; this.r = 5; this.c = "#00FF00"; this.ax = 0; this.ay = 0; this.a = 0; this.rAngle = 0; this.speed = 0; this.isAddX = true; this.isAddY = true; this.init = function(){ var lon = ($("myCanvas").width+$("myCanvas").height)*2; var rlon = Math.floor(Math.random()*(lon+1)); this.rAngle = Math.floor(Math.random()*91); if(rlon<$("myCanvas").width){//上 this.x = rlon; this.y = 0; }else if(rlon<$("myCanvas").width+$("myCanvas").height){//右 this.x = $("myCanvas").width; this.y = rlon-$("myCanvas").width; }else if(rlon<$("myCanvas").width*2+$("myCanvas").height){//下 this.x = $("myCanvas").width - (rlon-$("myCanvas").width-$("myCanvas").height); this.y = $("myCanvas").height; }else{//左 this.x = 0; this.y = $("myCanvas").height-(rlon-$("myCanvas").width*2-$("myCanvas").height); } if(rlon<$("myCanvas").width/2 || rlon>$("myCanvas").width*2+$("myCanvas").height+$("myCanvas").height/2){//左上 this.isAddX = true; this.isAddY = true; }else if(rlon<$("myCanvas").width+$("myCanvas").height/2){//右上 this.isAddX = false; this.isAddY = true; }else if(rlon<$("myCanvas").width+$("myCanvas").height+$("myCanvas").width/2){//右下 this.isAddX = false; this.isAddY = false; }else{//左下 this.isAddX = true; this.sAddY = false; } this.ax = Math.sin(Math.PI/180*this.rAngle)*star.speed; this.ax = this.isAddX?this.ax:0-this.ax; this.ay = Math.cos(Math.PI/180*this.rAngle)*star.speed; this.ay = this.isAddY?this.ay:0-this.ay; } this.update = function(){//更新 this.x=this.x+this.ax; this.y=this.y+this.ay; if((this.isAddX && this.x>$("myCanvas").width) || (!this.isAddX && this.x<0) || (this.isAddY && this.y>$("myCanvas").height) || (!this.isAddY && this.y<0)){ this.init(); return; } //$("message").innerHTML = $("message").innerHTML+"<br> x="+this.x+";y="+this.y; //$("message").innerHTML = $("message").innerHTML+"<br>cxt.arc("+Math.round(this.x)+","+Math.round(this.y)+","+this.r+",0,Math.PI * 2,true)"; var c=$("myCanvas"); var cxt=c.getContext("2d"); cxt.fillStyle=this.c; cxt.beginPath(); cxt.arc(this.x,this.y,this.r,0,Math.PI * 2,true); cxt.closePath(); cxt.fill(); } this.iscollide = function(){//判断是否被撞到 var x = Math.abs(player.left-this.x); var y = Math.abs(player.top-this.y); var R = this.r+player.r; if(R*R < x*x+y*y){ return true; } return false; } } star.speed = 1; var press = function(event){ var code = event.keyCode || window.event; switch(code) { case KEY.RIGHT: case KEY.D: input.right = true; break; case KEY.UP: case KEY.W: input.up = true; break; case KEY.LEFT: case KEY.A: input.left = true; break; case KEY.DOWN: case KEY.S: input.down = true; break; case KEY.QUICK: input.quick = true; break; } } var release = function(event) { var code = event.keyCode || window.event; switch(code) { case KEY.RIGHT: case KEY.D: input.right = false; break; case KEY.UP: case KEY.W: input.up = false; break; case KEY.LEFT: case KEY.A: input.left = false; break; case KEY.DOWN: case KEY.S: input.down = false; break; case KEY.QUICK: input.quick = false; break; } } var stars = new Array(); var myInter; var begin; var time = 0; //加载事件 var load = function(){ player.init(); for(i=0;i<20;i++){ var s = new star(); s.init(); stars[i] = s; } begin = new Date(); myInter = setInterval(function(){update();},20); } var $ = function(id){ return document.getElementById(id); } //更新方法 var update = function(){ var c=$("myCanvas"); c.width = c.width; // Clears the canvas player.update(); for(i=0;i<stars.length;i++){ stars[i].update(); } updatetime(); isDead(); } //更新时间 var updatetime = function(){ var end = new Date(); var time = Math.round((end-begin)/1000); star.speed = Math.round(time/10); $("time").innerHTML = time; } //判断是否死了 var isDead = function(){ for(i=0;i<stars.length;i++){ var flag = stars[i].iscollide(); if(flag==false){ clearInterval(myInter); alert("失败了"); return; } } } </script> </head> <body onLoad="load();" onkeydown="press(event);" onkeyup="release(event);" > <canvas id="myCanvas" width="400" height="400" style=" border:2px solid #F00; left:30%; position:absolute; "> <h1>换个好浏览器吧,ie太垃圾了</h1> </canvas> <div id="message"> 兼容 wasd 和 ↑←↓→<br> ctrl 键加速<br> <span id="time"></span>秒 </div> </body> </html>
1. 输出50—100间的所有素数,其中判断一个数是否为素数用函数完成。 2. 设计一个学生成绩管理系统,能输入学生的学号、姓名和成绩等数据,能按成绩从高到低进行排序,并能将排序的结果输出。 提示: 设计一个学生类student,包含三个私有数据成员,即学号sno、姓名sname和成员score; 在学生类student中再设计三个方法 setdata、display和getscore,分别用于完成输入学生信息、输出学生信息、返回某个学生成绩的功能; 定义一个manage类,它有一个student类型的私有数据成员s[num],其中num表示学生人数; 在manage类中分别定义三个方法input、output、sort,分别用于完成输入、输出和排序功能。 3.一个电子产品商店里卖各种电子产品,以下是几种产品类信息。 产品Product 的属性信息包括: 产品号(number) 种类(category) 名称(name) 价格(price ) 计算机Computer除具有产品基本信息外,还可能具有下面的属性: 内存(memory) 处理器(processorName)   笔记本电脑Laptop 除具有产品基本信息外,还可能具有下面的属性: 厚度(thickness) 重量(weight) 根据以上信息,首先抽象出类Product,它派生出子类Computer,Computer又派生出它的子类Laptop,实现以上三个类的定义,定义相应的构造方法,声明一个测试类,生成类对象,并把打印结果显示在屏幕上。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小疯疯0413

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值