Java Interface Usage Learning----------------Java Rookie learn to fly the first step

Source: Internet
Author: User
Tags interface tostring
/*


* @ (#) Clsusage.java 1.0 04/12/25


*


* Can modify the template of this file in the


* directory. \jcreator\templates\template_1\project_name.java


*


* can also create your own project template by making a new


* folder in the directory. \jcreator\template\. Use the other


* Templates as examples.


*


*/


package myprojects.clsusage;


import java.util.*;


class Clsusage {





public Clsusage () {





}





public static void Main (String args[]) {


System.out.println ("Starting clsusage ...");


isplitpage isp=new userpage (12);


Isp.firstpage ();


while (Isp.haspages ())


{


Isp.nextpage ();


}





}


}


Interface Isplitpage


{


void FirstPage ();


void NextPage ();


boolean haspages ();


}


class Dateobj


{


private String name;


private int age;


private Boolean sex;


private int id;


public static int PersonID;


Static


{


personid=1000;


}


public dateobj (String na,int ag,boolean SX)


{


name=na;age=ag;sex=sx;


id=dateobj.personid++;


}


public dateobj (String Na,int AG)


{


name=na;age=ag;sex=true;


id=dateobj.personid++;


}


public int getId ()


{


return ID;


}


public String getName ()


{


return name;


}


public void SetName (String na)


{


Name=na;


}


public int getage ()


{


return age;


}


public void Setage (int dg)


{


AGE=DG;


}


public boolean issex ()


{


return this.sex;


}


public void Setsex (Boolean sx)


{


sex=sx;


}


public String toString ()


{


return "" +id+ "-" +name+ "-" +age+ "-" +sex;


}


}


class Userpage implements Isplitpage


{


//which can is accessed with itself or son


//Is independent of the package in which it or subclasses are located


protected int PageCount;


protected int pageIndex;


protected Java.util.Vector list;


public userpage (int pages)


{


if (pages<=0)


this.pagecount=10;


int age=20;


Boolean sex=false;


list=new Vector ();


for (int i=0;i<pages;i++)


{


String na= "" +i+ "";


dateobj ob=new dateobj (na,age+i,sex);


Sex=!sex;


list.addelement (OB);


}


this.pagecount=pages;


this.pageindex=1;


}


public void FirstPage ()


{


pageindex=1;


dateobj ob= (dateobj) list.get (pageIndex-1);


System.out.println ("first page" +ob.tostring ());


}


public void NextPage ()


{


pageindex++;


if (pageindex<=this.pagecount)


{


Dateobj ob= (dateobj) list.get (pageIndex-1);


System.out.println ("+pageindex+", "page" +ob.tostring);


}





}


public boolean haspages ()


{


return pageindex<=pagecount;


}


}














Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.