上周作业

//MyFrame.java

import java.awt.Component;

import java.awt.Container;


import java.awt.GridLayout;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.StringTokenizer;


import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JLabel;






public class MyFrame {
public void go(){
JFrame win = new JFrame("评价");
Container contentPane = win.getContentPane();

contentPane.setLayout(new GridLayout(12,1));

ArrayList <JCheckBox> cb = new ArrayList<JCheckBox>();
int length;
try{
File csvFile = new File("F:\\pingjia.csv");
BufferedReader br = new BufferedReader(new FileReader(csvFile));
String line= "";
ArrayList<Select> list = new ArrayList<Select>();

//读取题目信息
String topics = br.readLine();
JLabel labOne = new JLabel(topics,JLabel.CENTER);
contentPane.add(labOne);
topics = topics.replace(",",":");

//读取选项信息
while((line = br.readLine())!=null){
StringTokenizer st = new StringTokenizer(line,",");
List<String> list2 = new ArrayList<String>();
while((st.hasMoreTokens())){
list2.add(st.nextToken());
}
Select select = new Select(list2);
list.add(select);
}
br.close();
//生成迭代器
length = list.size();
Shuffer sf = new Shuffer(length);
Iterator<Integer> iteshuf = sf.iterator();

do{
Select select = list.get((Integer) iteshuf.next());
JCheckBox temp = new JCheckBox(select.getDes());
cb.add(temp);
if(select.getAnser()){
temp.setSelected(true);
}
}while(iteshuf.hasNext());
}catch(FileNotFoundException e){
e.printStackTrace();
}catch(IOException e){
e.printStackTrace();
}



JButton btn = new JButton("提交");
btn.setSize(10, 20);


Iterator<JCheckBox> it = cb.iterator();
while(it.hasNext()){
contentPane.add((Component) it.next());
}

contentPane.add(btn);


win.setLocation(400, 200);
win.setSize(400, 400);
win.setVisible(true);
}
public static void main(String[] args) {
// TODO Auto-generated method stub
MyFrame mf = new MyFrame();
mf.go();
}

}

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------


//IteShuf.java


import java.util.Iterator;


public class IteShuf implements Iterator<Integer> {
private int curpos;
private int[] cards;

public IteShuf(int[] cards){
curpos = 0;
this.cards = cards;
}

public boolean hasNext(){
//返回boolean值,true为还有下一个,false为无下一个
return ++curpos < cards.length;
}

public Integer next(){
//返回当前的cards
return cards[curpos];
}

public void remove(){

}
}

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------


//Select.java
import java.util.List;


public class Select {
private String description;
private boolean answer = true;

public Select(List<String> list){
//保存答案
this.description = list.get(0);
//保存答案标记
if(list.get(1).equals("1")){
this.answer = true;
}
else{
this.answer = false;
}
}

public String getDes(){
return this.description;
}

public boolean getAnser(){
return answer;
}
}


--------------------------------------------------------------------------------------------------------------------------------------------------------------


//Shuffer.java


import java.util.Iterator;
import java.util.Random;


public class Shuffer {
private int[] cards;

public Shuffer(int length){
cards = new int[length];
for(int i=0; i<length; i++){
cards[i] = i;
}
//生成随机数
Random rd = new Random();
for(int i=length-1; i>0; --i){
int j =  rd.nextInt(length-1);
int t =cards[i];
cards[i] = cards[j];
cards[j] = t;
}
}

public int items(int i){
return cards[i];
}

//迭代器生成函数
public Iterator<Integer> iterator(){
return new IteShuf(cards);
}
}

------------------------------------------------------------------------------------------------------

//csv

请选择您的评价结果: 
*****,讲解透彻生动,好评,1
授课差评!,0 
授课差差评!,0 
*****,培训组织,最好评!,1
培训组织,差评!,0 
培训环境,好评!,1
培训环境,差评!,0
*****,收获很大,好评!,1
培训没有效果,白白浪费时间!,0




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值