2 wtiny WTiny 于 2016.04.17 22:26 提问

用eclipse写了一个作业,错误层出不穷,百度上资料很少希望有大触可以帮忙解决

一共有6个类1个枚举类型。

RepeatedStringEstimator.java

 package cn.qtech.util;
public class RepeatedStringEstimator {
    public boolean estimate(String s){
        boolean ac = true;
        int vis[] = new int[26];
        for(int i=0;i<26;i++) vis[i] = 0;
        for(int i=0;i<s.length();i++){
            vis[s.charAt(i)-'a']++;
        }
        for(int i=0;i<26;i++){
            if(vis[i]!=2 && vis[i]!=0)
                ac = false;
        }
        return ac;
    }
    public void stringOperate(){
        int isEqual = "abc".compareTo("acb");
        if(isEqual == 0){
            System.out.println("\"abc\" 和\" acb\"想等");
        }
        else
            System.out.println("\"abc\" 和\" acb\"不想等");
        String tmp = "c:\\java\\jsp\\A.java";
        int l = 0;
        for(int i=0;i<tmp.length();i++){
            if(tmp.regionMatches(i,"\\j",0,2)){
                //System.out.println("score");
                l++;
                if(l == 2){
                    System.out.println(tmp+"第二次出现\"\\\\j\"的位置是"+i);
                    String rear = new String(tmp.toCharArray(),i,tmp.length()-i) ;
                    System.out.println("其后的字符串为"+rear);
                    break;
                }
            }
        }
    }
}

Student.java

 package cn.qtech.teaching;
import cn.qtech.util.*;
public class Student extends UniversityPeople{
    String name;
    void settername(String s){
        name = s;
    }
    String gettername(){
        return name;
    }
    void doDuty(TeachingMessage msg){
        if(msg.state == TeachingState.BEIKE){
            msg.state = TeachingState.TINGKE;
            System.out.println("老师"+msg.getterTeaName()+"备完课后,去听课!");
        }
        if(msg.state == TeachingState.BUZHIZUOYE){
            msg.state = TeachingState.ZUOZUOYE;
            System.out.println("老师"+msg.getterTeaName()+"布置完课作业后,开始做作业!");
        }
    RepeatedStringEstimator tmp = new RepeatedStringEstimator();
    boolean istrue = tmp.estimate("aaaa");
    if(istrue){
        System.out.println("\"aaaa\"是重复串");
    }
    else{
        System.out.println("\"aaaa\"不是是重复串");
    }
    istrue = tmp.estimate("abddab");
    if(istrue)
        System.out.println("\"abddab\"是重复串");
    else
        System.out.println("\"abddab\"不是是重复串");
    istrue = tmp.estimate("acbcab");
    if(istrue)
        System.out.println("\"acbcab\"是重复串");
    else
        System.out.println("\"acbcab\"不是是重复串");
    tmp.stringOperate();
}
}

Teacher.java

 package cn.qtech.teaching;

public class Teacher extends UniversityPeople{
    String name;
    void settername(String s){
        name = s;
    }
    String gettername(){
        return name;
    }
    void doDuty(TeachingMessage msg){
        if(msg.state == TeachingState.TINGKE){
            msg.state = TeachingState.BUZHIZUOYE;
            System.out.println(msg.students);
            System.out.println("学生听完课后,开始布置作业!");
        }
    }
}

TeachingState.java

 package cn.qtech.teaching;

public enum TeachingState{
    BEIKE, TINGKE,BUZHIZUOYE, ZUOZUOYE //备课,听课,布置作业,做作业
}

TeachingMessage.java
大部分问题出现在这里

 package cn.qtech.teaching;

public class TeachingMessage {
    Teacher teacher = new Teacher();
    Student[] students = new Student[2];
    students[0] = new Student();
    students[1] = new Student();
    TeachingState state = TeachingState.BEIKE;
    void setterStuName(int n,String s){
        students[n].settername(s);
    }
    String getterStuName(int n){
        return students[n].name;
    }
    void setterTeaName(String s){
        teacher.settername(s);
    }
    String getterTeaName(){
        return teacher.name;
    }
    void setterTeaState(TeachingState x){
        state = x;
    }
    TeachingState getterTeaState(){
        return state;
    }
}

Teaching.java
存在部分问题

 package cn.qtech.teaching;

public class Teaching {
    static void doOneTeaching(){
    TeachingMessage a = new TeachingMessage();
    TeachingMessage b = new TeachingMessage();
    a.setterTeaName("ZW");
    a.setterStuName(0, "WTF");
    a.setterStuName(1, "WTY");
    a.students[0].doDuty(b);
    System.out.println("听课学生名单:");
    System.out.print(a.students[0].gettername());
    System.out.print(a.students[1].gettername());
    b.setterTeaState(TeachingState.TINGKE);
        a.teacher.doDuty(b);
    }
    public static void main(String args[]){
        doOneTeaching();
    }
}

希望有时间的大触帮忙解决一下,谢谢。

1个回答

devmiao
devmiao   Ds   Rxr 2016.04.17 23:28

不要用百度这种低端山寨的搜素引擎。

WTiny
WTiny 那从哪找资料,而且我英语很渣。
一年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!