求大神!!!!!

来源:4-4 学生选课---添加课程 Ⅰ

A冲绳小光

2017-12-27 15:22

谁知道 Course类的id 跟 name进行封装后 怎么把 gatId  gatName 的值传入保存到 coursesToSelect中 

写回答 关注

3回答

  • A冲绳小光
    2017-12-27 15:37:01

    封装方式的已经自己解决了 大家可以参考  有好的方式留言

  • A冲绳小光
    2017-12-27 15:31:23

    import java.util.ArrayList;
    import java.util.HashSet;
    import java.util.List;
    import java.util.Set;
       public class listText{

           public List coursesToSelect;

           public listText(){
               this.coursesToSelect= new ArrayList();

           }
           public void testAdd(){
               Course t=new Course();
             String b;
              t.setId("fsdfs") ;
              t.setName("dsff");
              coursesToSelect.add(t);
               Course temp =(Course)coursesToSelect.get(0);
               System.out.println("add"+temp.getId()+"add"+temp.getName());

           }

           public static void main (String[] args){
               listText t= new listText();
               t.testAdd();
           }
       }

       class Course{
           private String id;
           private String name;
    //        public Course(String id, String name) {
    //        this.id=id;
    //        this.name=name;
    //        }

            public void setId(String newId){
              id=newId;
            }
            public String getId(){
              return id;
            }
            public void setName(String newName){
              name=newName;
            }
            public String getName(){
              return name;
            }
       }

    class student{
           public String id;
           public String name;

           public Set Coursee;

           public student(String id,String name){
               this.id=id;
               this.name=name;
               this.Coursee=new HashSet();
           }
       }



  • A冲绳小光
    2017-12-27 15:28:20

    说错了 是setid 跟setname的值

Java入门第三季

Java中你必须懂得常用技能,不容错过的精彩,快来加入吧

409784 学习 · 4339 问题

查看课程

相似问题