java学生选课的代码 java学生选课的代码是什么
java 用eclipse做简单的学生选课
import.java.util.*;
成都创新互联专业为企业提供余干网站建设、余干做网站、余干网站设计、余干网站制作等企业网站建设、网页设计与制作、余干企业网站模板建站服务,十年余干做网站经验,不只是建网站,更提供有价值的思路和整体网络服务。
public static void Main(String [] args)
{
String [] classes=new [] String[4]{"A","B","C","D"};
int a=0,b=0,c=0,d =0;
Scanner input =new Scanner(System.in);
for(int i = 0 ;i30;i++)
{
System.out.println("请输入你选的课程号:");
String choice=input.next();
if(choice.equals("A"))
{
a++;
}
else if(choice.equals("B"))
{
b++;
}
else if(choice.equals("A"))
{
c++;
}
else if(choice.equals("A"))
{d++;
}
}
System.out.println("A门课程被选中"+a+"次");
System.out.println("B门课程被选中"+b+"次");
System.out.println("C门课程被选中"+c+"次");
System.out.println("D门课程被选中"+d+"次");
}
Java帮我写下代码~
项目结构如下:
代码如下
package main;
public class Course {
private String classNum;
private String credit;
private String startClassDate;
private String endClassDate;
private String teacher;
private String assessment;
public String getClassNum() {
return classNum;
}
public void setClassNum(String classNum) {
this.classNum = classNum;
}
public String getCredit() {
return credit;
}
public void setCredit(String credit) {
this.credit = credit;
}
public String getStartClassDate() {
return startClassDate;
}
public void setStartClassDate(String startClassDate) {
this.startClassDate = startClassDate;
}
public String getEndClassDate() {
return endClassDate;
}
public void setEndClassDate(String endClassDate) {
this.endClassDate = endClassDate;
}
public String getTeacher() {
return teacher;
}
public void setTeacher(String teacher) {
this.teacher = teacher;
}
public String getAssessment() {
return assessment;
}
public void setAssessment(String assessment) {
this.assessment = assessment;
}
@Override
public String toString() {
return " 课程号:" + classNum + ", 学分:" + credit
+ ", 上课时间:" + startClassDate + ", 下课时间:"
+ endClassDate + ", 教师:" + teacher + ", 考核方式:"
+ assessment + "";
}
}
package main;
import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
public class Main {
public static void main(String[] args) throws Exception {
Scanner sc = new Scanner(System.in);
System.out.println("创建学生请输入姓名:");
Student stu1 = new Student();
stu1.setName(sc.nextLine());
Scanner sc1 = new Scanner(System.in);
System.out.println("创建学生请输入学号:");
stu1.setNumber(sc1.nextLine());
System.out.println("请选择课程,课程如下:");
ListCourse list2 = new ArrayListCourse();
stu1.setCourses(list2);
ListCourse list = readTxt();
for (Course course : list) {
System.out.println(course.toString());
}
for (int i = 1; i 5; i++) {
System.out.println("请输入第"+i+"个课程号:");
//输入第一个课程号
list2 = handleClass(list, list2);
System.err.println("已选择成功!");
list = notSelectClass(list, list2);
System.out.println("请选择课程,课程如下:");
if(i==4){
break;
}
for (Course course : list) {
System.out.println(course.toString());
}
}
System.out.println("课程已选完!结果如下:");
System.err.println("学生:"+stu1.getName()+":");
for (Course course : list2) {
System.err.println(course.toString());
}
}
/**
*
* 查看未选择可选课程
* @param list 全部可选课程
* @param list2 已选课程
* @return
*/
private static ListCourse notSelectClass(ListCourse list,ListCourse list2){
for (int i = 0; i list.size(); i++) {
for (Course course : list2) {
//把已选课程剔除
if(course.getClassNum().equals(list.get(i).getClassNum())){
list.remove(i);
continue;
}
//把时间重合课程剔除 startdate1 =enddate2 and enddate1=startdate2
if(daYuDengYu(course.getEndClassDate(),list.get(i).getStartClassDate())daYuDengYu(list.get(i).getEndClassDate(), course.getStartClassDate())){
list.remove(i);
}
}
}
return list;
}
public static boolean daYuDengYu(String first, String second){
BigDecimal bd1 = new BigDecimal(first);
BigDecimal bd2 = new BigDecimal(second);
return bd1.compareTo(bd2)=0?true:false;
}
/**
* 处理选择课程
* @param list
* @param list2
* @return
*/
private static ListCourse handleClass(ListCourse list,ListCourse list2){
while (true) {
Scanner sssi = new Scanner(System.in);
String num = sssi.nextLine().trim();
for (Course course : list) {
if(num.equals(course.getClassNum())){
list2.add(course);
return list2;
}
}
System.out.println("课程号输入错误,请重新输入:");
}
}
/**
* 读取txt获取课程 每个课程按;分割每个属性按,分割
* @return
* @throws Exception
*/
private static ListCourse readTxt() throws Exception{
/* 读入TXT文件 */
String pathname = Main.class.getResource("/").toString();
pathname = pathname.substring(6, pathname.length()-4)+"/src/classs/class.txt"; //获取绝对路径
File filename = new File(pathname); // 要读取以上路径的txt文件
ListCourse list = new ArrayListCourse();
BufferedInputStream bis = new BufferedInputStream(new FileInputStream(filename));
//读取文件内容
byte[] b = new byte[bis.available()];
bis.read(b);
if(b!=null){
String [] strs= new String(b).split(";");
if (strs==null) {
return null;
}
for (String string : strs) {
String[] str = string.split(",");
Course course = new Course();
course.setAssessment(str[5].trim());
course.setClassNum(str[0].trim());
course.setCredit(str[1].trim());
course.setEndClassDate(str[3].trim());
course.setStartClassDate(str[2].trim());
course.setTeacher(str[4].trim());
list.add(course);
}
}
bis.close();//关闭流(关闭bis就可以了)
return list;
}
}
package main;
import java.util.List;
public class Student {
private String name;
private String number;
private ListCourse courses;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getNumber() {
return number;
}
public void setNumber(String number) {
this.number = number;
}
public ListCourse getCourses() {
return courses;
}
public void setCourses(ListCourse courses) {
this.courses = courses;
}
}
001,1,7,8,Joyce,assignment;
002,1,8,9,Joyce,assignment;
003,1,12,15,Joyce,assignment;
004,1,18,19,Joyce,assignment;
005,1,7,8,LI,assignment;
006,1,8,9,LI,assignment;
007,1,12,15,LI,assignment;
008,1,18,19,LI,assignment;
java代码
帮你改了一下:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class logon extends JFrame {
public static void main(String args[]) {
logon a=new logon();
a.show();
}
CheckboxGroup ShenFen=new CheckboxGroup();
Checkbox ShenFen1;
Checkbox ShenFen2;
Checkbox ShenFen3;
JButton LogonButton,Exit;
JTextField id;
JPasswordField password;
public logon(){
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
this.setLayout(null);
setTitle("学生选课系统");
setSize(600,600);
ShenFen1=new Checkbox("学生",ShenFen,true);
ShenFen2=new Checkbox("教师",ShenFen,false);
ShenFen3=new Checkbox("管理员",ShenFen,false);
add(ShenFen1);
add(ShenFen2);
add(ShenFen3);
ShenFen1.setBounds(300, 350, 50, 50);
ShenFen2.setBounds(350, 350, 50, 50);
ShenFen3.setBounds(400, 350, 50, 50);
LogonButton=new JButton("登录");
add(LogonButton);
Exit=new JButton("退出");
add(Exit);
Exit.setBounds(400, 400,60, 60);
id=new JTextField();
add(id);
id.setBounds(300, 200, 200, 30);
password=new JPasswordField();
add(password);
password.setBounds(300, 250, 200, 30);
}
}
文章题目:java学生选课的代码 java学生选课的代码是什么
文章地址:http://myzitong.com/article/dojcich.html