按你现在说的这个内容,我觉得三个类就能表现出来,我写了一下,你看看能不能满足你的要求:
10年积累的成都网站设计、网站建设经验,可以快速应对客户对网站的新想法和需求。提供各种问题对应的解决方案。让选择我们的客户得到更好、更有力的网络服务。我虽然不认识你,你也不认识我。但先网站设计后付款的网站建设流程,更有绩溪免费网站建设让你可以放心的选择与我们合作。
/**
* 运动员信息
* @author songfeng163
*/
public class PlayerState {
private String lx; //运动类型
private String xing; // 姓
private String ming; // 名
public String getLx() {
return lx;
}
public void setLx(String lx) {
this.lx = lx;
}
public String getXing() {
return xing;
}
public void setXing(String xing) {
this.xing = xing;
}
public String getMing() {
return ming;
}
public void setMing(String ming) {
this.ming = ming;
}
//返回姓名信息
@Override
public String toString() {
return xing+ming;
}
}
/**
* 运动员得分信息
* @author songfeng163
*/
public class SoccerPlayerStats {
private PlayerState player; //运动员信息
private double spointsScored; //点球得分
private double assists; //助攻得分
private double penaltyKickRate; //罚球得分概率
public PlayerState getPlayer() {
return player;
}
public void setPlayer(PlayerState player) {
this.player = player;
}
public double getSpointsScored() {
return spointsScored;
}
public void setSpointsScored(double spointsScored) {
this.spointsScored = spointsScored;
}
public double getAssists() {
return assists;
}
public void setAssists(double assists) {
this.assists = assists;
}
public double getPenaltyKickRate() {
return penaltyKickRate;
}
public void setPenaltyKickRate(double penaltyKickRate) {
this.penaltyKickRate = penaltyKickRate;
}
//返回分数信息
@Override
public String toString() {
return "** PLAYER ADDED **"+ player.toString()+"; Points:"+ spointsScored + "; Assists: "+ assists +"; Penalty Kick %:" + penaltyKickRate;
}
}
这里是主类:
import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;
/**
* 主类
* @author songfeng163
*/
public class MyMain {
//添加方法
public ListSoccerPlayerStats add(ListSoccerPlayerStats list){
Scanner in=new Scanner(System.in);
PlayerState player=new PlayerState();
SoccerPlayerStats score=new SoccerPlayerStats();
System.out.println("请输入运动类型:足球,高尔夫,田径:");
player.setLx(in.next());
System.out.println("请输入姓:");
player.setXing(in.next());
System.out.println("请输入名:");
player.setMing(in.next());
System.out.println("请输入该运动员的点球得分:");
score.setSpointsScored(in.nextDouble());
System.out.println("请输入该运动员的助攻得分:");
score.setAssists(in.nextDouble());
System.out.println("请输入该运动员的罚球得分概率:");
score.setPenaltyKickRate(in.nextDouble());
score.setPlayer(player);
System.out.println(score); //显示新添加的人员
list.add(score);
return list;
}
//删除方法
public ListSoccerPlayerStats del(ListSoccerPlayerStats list){
Scanner in=new Scanner(System.in);
PlayerState player=new PlayerState();
System.out.println("请输入要删除运动员的姓:");
player.setXing(in.next());
System.out.println("请输入要删除运动员的名:");
player.setMing(in.next());
for(SoccerPlayerStats score:list){
if(score.getPlayer().getXing().equals(player.getXing())
score.getPlayer().getMing().equals(player.getMing())){
list.remove(score);
break;
}
}
return list;
}
//显示方法
public void show(ListSoccerPlayerStats list){
System.out.println("当前共有:"+list.size()+"条记录,内容如下:");
for(SoccerPlayerStats score:list){
System.out.println(score);
}
}
//保存方法
public ListSoccerPlayerStats save(ListSoccerPlayerStats list){
System.out.println("请输入要保存的文件名:");
Scanner in=new Scanner(System.in);
String fileName=in.next();
try{
BufferedWriter bw = new BufferedWriter(new FileWriter("C:/"+fileName));
for(SoccerPlayerStats score:list){
bw.write(score.toString());
bw.newLine();
}
bw.flush();
bw.close();
}catch(Exception ex){
ex.printStackTrace();
}
System.out.println("** 1 RECORD SAVED TO "+fileName+" **");
return list;
}
public static void main(String[] args) {
MyMain myMain=new MyMain();
Scanner in=new Scanner(System.in);
//如果像你说的是数组的话,数据没有办法动态变化,所以我用了list
ListSoccerPlayerStats list=new ArrayListSoccerPlayerStats();
String cz="QUIT"; //默认的操作为退出
System.out.println("下面如何操作(ADD, REMOVE, SHOW, SAVE, QUIT)?");
String czin=in.next(); //输入数据
cz=czin.toUpperCase(); //转换成大写
while(!cz.equals("QUIT")){ //不是退出
if(cz.equals("ADD")){ //添加数据
list = myMain.add(list);
}else if(cz.equals("REMOVE")){ //删除数据
list = myMain.del(list);
}else if(cz.equals("SHOW")){ //显示数据
myMain.show(list);
}else if(cz.equals("SAVE")){ //保存数据
myMain.save(list);
}
System.out.println("下面如何操作(ADD, REMOVE, SHOW, SAVE, QUIT)?");
czin=in.next(); //输入数据
cz=czin.toUpperCase(); //转换成大写
}
System.out.println("** GOODBYE! **");
}
}
运行结果如下:
下面如何操作(ADD, REMOVE, SHOW, SAVE, QUIT)?
add
请输入运动类型:足球,高尔夫,田径:
足球
请输入姓:
王
请输入名:
明
请输入该运动员的点球得分:
4
请输入该运动员的助攻得分:
2
请输入该运动员的罚球得分概率:
0.25
** PLAYER ADDED **王明; Points:4.0; Assists: 2.0; Penalty Kick %:0.25
下面如何操作(ADD, REMOVE, SHOW, SAVE, QUIT)?
add
请输入运动类型:足球,高尔夫,田径:
高尔夫
请输入姓:
李
请输入名:
三
请输入该运动员的点球得分:
2
请输入该运动员的助攻得分:
2
请输入该运动员的罚球得分概率:
0.3
** PLAYER ADDED **李三; Points:2.0; Assists: 2.0; Penalty Kick %:0.3
下面如何操作(ADD, REMOVE, SHOW, SAVE, QUIT)?
show
当前共有:2条记录,内容如下:
** PLAYER ADDED **王明; Points:4.0; Assists: 2.0; Penalty Kick %:0.25
** PLAYER ADDED **李三; Points:2.0; Assists: 2.0; Penalty Kick %:0.3
下面如何操作(ADD, REMOVE, SHOW, SAVE, QUIT)?
save
请输入要保存的文件名:
Playerdata.txt
下面如何操作(ADD, REMOVE, SHOW, SAVE, QUIT)?
remove
请输入要删除运动员的姓:
李
请输入要删除运动员的名:
三
下面如何操作(ADD, REMOVE, SHOW, SAVE, QUIT)?
show
当前共有:1条记录,内容如下:
** PLAYER ADDED **王明; Points:4.0; Assists: 2.0; Penalty Kick %:0.25
下面如何操作(ADD, REMOVE, SHOW, SAVE, QUIT)?
quit
** GOODBYE! **
改为,你的boolean数组没有初始化,bar[0]取到的为null,if(null){} 编译通不过去
1. String foo = “blue”;
2. Boolean[] bar = {true};
3. if (bar[0]) {
4. foo = “green”;
5. }
具体如下:
连连看的小源码
package Lianliankan;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class lianliankan implements ActionListener
{
JFrame mainFrame; //主面板
Container thisContainer;
JPanel centerPanel,southPanel,northPanel; //子面板
JButton diamondsButton[][] = new JButton[6][5];//游戏按钮数组
JButton exitButton,resetButton,newlyButton; //退出,重列,重新开始按钮
JLabel fractionLable=new JLabel("0"); //分数标签
JButton firstButton,secondButton; //
分别记录两次62616964757a686964616fe59b9ee7ad9431333335326239被选中的按钮
int grid[][] = new int[8][7];//储存游戏按钮位置
static boolean pressInformation=false; //判断是否有按钮被选中
int x0=0,y0=0,x=0,y=0,fristMsg=0,secondMsg=0,validateLV; //游戏按钮的位置坐标
int i,j,k,n;//消除方法控制
代码(code)是程序员用开发工具所支持的语言写出来的源文件,是一组由字符、符号或信号码元以离散形式表示信息的明确的规则体系。
对于字符和Unicode数据的位模式的定义,此模式代表特定字母、数字或符号(例如 0x20 代表一个空格,而 0x74 代表字符“t”)。一些数据类型每个字符使用一个字节;每个字节可以具有 256 个不同的位模式中的一个模式。
在计算机中,字符由不同的位模式(ON 或 OFF)表示。每个字节有 8 位,这 8 位可以有 256 种不同的 ON 和 OFF 组合模式。对于使用 1 个字节存储每个字符的程序,通过给每个位模式指派字符可表示最多 256 个不同的字符。2 个字节有 16 位,这 16 位可以有 65,536 种唯一的 ON 和 OFF 组合模式。使用 2 个字节表示每个字符的程序可表示最多 65,536 个字符。
单字节代码页是字符定义,这些字符映射到每个字节可能有的 256 种位模式中的每一种。代码页定义大小写字符、数字、符号以及 !、@、#、% 等特殊字符的位模式。每种欧洲语言(如德语和西班牙语)都有各自的单字节代码页。
虽然用于表示 A 到 Z 拉丁字母表字符的位模式在所有的代码页中都相同,但用于表示重音字符(如"é"和"á")的位模式在不同的代码页中却不同。如果在运行不同代码页的计算机间交换数据,必须将所有字符数据由发送计算机的代码页转换为接收计算机的代码页。如果源数据中的扩展字符在接收计算机的代码页中未定义,那么数据将丢失。
如果某个数据库为来自许多不同国家的客户端提供服务,则很难为该数据库选择这样一种代码页,使其包括所有客户端计算机所需的全部扩展字符。而且,在代码页间不停地转换需要花费大量的处理时间。
我自己写的,运行没问题,如果有小问题,欢迎指出
练习一:
Customer类:
package com.wxws.sms;
public class Customer {
/**
* @param args
*/
String CustNumber;
int CustPoint;
}
--------------------------------分隔符------------------------------------
CustManager类:
package com.wxws.sms;
import java.util.*;
public class CustManager {
Customer customers[]=new Customer[100];
public void CustAdd(Customer cust) {
// TODO Auto-generated constructor stub
for(int i=0;icustomers.length;i++){
if(customers[i]==null){
customers[i]=cust;
break;
}
}
}
public void showCustomer(){
System.out.println("***Customers List***");
System.out.println("number\tpoint");
for(int i=0;icustomers.length;i++){
if(customers[i]!=null){
System.out.println(customers[i].CustNumber+"\t"+customers[i].CustPoint);
}
}
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Customer run=new Customer();
CustManager move=new CustManager();
@SuppressWarnings("resource")
Scanner input=new Scanner(System.in);
System.out.print("Please input your Vip number:");
run.CustNumber=input.next();
System.out.print("Please input your Vip point:");
run.CustPoint=input.nextInt();
move.CustAdd(run);
move.showCustomer();
}
}
---------------------------------------------分割符号---------------------------------------------------
练习二(将Customer类的属性改成数组):
package com.wxws.sms;
public class Customer {
/**
* @param args
*/
String CustNumber[]=new String[100];
int CustPoint[]=new int[100];
}
---------------------------------------------分割符号---------------------------------------------------
package com.wxws.sms;
import java.util.*;
public class CustManager {
Customer customers[]=new Customer[100];
public void CustAdd(Customer cust) {
// TODO Auto-generated constructor stub
for(int i=0;icustomers.length;i++){
if(customers[i]==null){
customers[i]=cust;
break;
}
}
}
public void showCustomer(){
System.out.println("***Customers List***");
System.out.println("number\tpoint");
for(int i=0;icustomers.length;i++){
if(customers[i]!=null){
System.out.println(customers[i].CustNumber[i]+"\t"+customers[i].CustPoint[i]);
}
}
}
public int searchScore(String custNo){
int point=1;
for(int i=0;icustomers.length;i++){
if(customers[i]!=null){
if((customers[i].CustNumber[i]).equals(custNo)){
System.out.println("The number of Vip's point is:"+customers[i].CustPoint[i]);
point=customers[i].CustPoint[i];
}
}
}
return point;
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Customer run=new Customer();
CustManager move=new CustManager();
@SuppressWarnings("resource")
Scanner input=new Scanner(System.in);
for(int i=0;i4;i++){
System.out.print("Please input your Vip number:");
run.CustNumber[i]=input.next();
System.out.print("Please input your Vip point:");
run.CustPoint[i]=input.nextInt();
move.CustAdd(run);
}
move.showCustomer();
System.out.print("Please input the Vip number you want to check:");
String custNum=input.next();
move.searchScore(custNum);
}
}
这是一个表查找,查找表中与customer相等的数据。这个表有[customer,name,phone,....]等字段
项目结构如下:
代码如下
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;