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