Java fourth time job

Source: Internet
Author: User

1, design a dog class, have a name, color, age and other attributes, define a constructor method to initialize these properties of the class, define methods to output the dog information, write the application using the dog class. Code: packagecore; public classHomework1 { public Static voidmain (string[] Args) {//TODO auto-generated method stubsDog dog=NewDog ("black shellfish", "black brown", 5);         System.out.println (dog); }        }    classDog {PrivateString name; PrivateString color; Private intage ;  publicString getName () {returnname; }     publicString getColor () {returncolor; }     public intgetage () {returnage ; }     public voidsetName (String Name) { this. name=name; }     public voidsetcolor (String Color) { this. color=color; }     public voidSetage (intage ) {         this. age=age ; }     publicDog (String name,string color,intage ) {        Super();  this. name=name;  this. color=color;  this. age=age ; }     publicString toString () {return"dog's name:" + this. name+ ", Dog color:" + this. color+ ", Age of the dog:" + this. age; }}2, design a user class that represents users, variables in a class that have user names, passwords, and variables that record the number of users, define the 3 constructor methods of a class (no parameters, assign a value to a user name, assign a value to a user name and password), get and set the password method, and return class Information. Code: packagecore; public classHOMEWORK2 { public Static voidmain (string[] Args) {//TODO auto-generated method stubsUser user1=NewUser ("the Great lord", "12345678");        User1.print (); User User2=NewUser ("little devil", "87654321");        User2.print (); NewUser (). Count (); }}classuser{PrivateString name; PrivateString password; Private Static intcount;  publicUser () {count++; } publicUser (String Name) { this. name=name; Count++;} publicUser (String name,string password) { this. name=name;  this. password=password; Count++;} publicString getName () {returnname;} public voidsetName (String Name) { this. name=name;} publicString GetPassword () {returnpassword;} public voidSetPassword (String Password) { this. password=password;} public voidprint () {System.out.println ("user name:" +name+ "\ t" + "password:" +password);} public voidCount () {System.out.println ("number of users:" + (count-1)); }}

Java fourth time job

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.