Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public c l a s s Country {
- S t ri n g countryName ;
- int noO fCi ti z e n s ;
- boolean i s Ro yal ;
- S t ri n g c o n ti n e n t ;
- int p o l i t i c a l S t a t e ;
- public Country ( ) {
- countryName = "" ;
- noO fCi ti z e n s = 0 ;
- i s Ro yal = f a l s e ;
- c o n ti n e n t = "" ;
- p o l i t i c a l S t a t e = 0 ;
- }
- public Country ( S t ri n g n , int nc , boolean r ,
- S t ri n g c , int p ) {
- countryName = n ;
- noO fCi ti z e n s = nc ;
- i s Ro yal = r ;
- c o n ti n e n t = c ;
- p o l i t i c a l S t a t e = p ;
- }
- public S t ri n g g e t P o l i t i c a l S t a t e ( ) {
- S t ri n g r e s u l t ;
- switch ( p o l i t i c a l S t a t e ) {
- 6
- case 1 :
- r e s u l t = "war" ;
- break ;
- case 2 :
- r e s u l t = " I n c r e a s e ␣ i n ␣ f o r c e ␣ r e a d i n e s s " ;
- break ;
- case 3 :
- r e s u l t = " i n c r e a s e ␣ i n t e l l i g e n c e " ;
- break ;
- case 4 :
- r e s u l t = " peace " ;
- break ;
- de fau lt :
- r e s u l t = " not ␣ e n t e r e d ␣ ye t " ;
- }
- return r e s u l t ;
- }
- public int compareTo ( Country a ){
- return noO fCi ti z e n s − a . noO fCi ti z e n s ;
- }
- public s t a t i c int compareTo ( Country a , Country b ){
- return a . noO fCi ti z e n s − b . noO fCi ti z e n s ;
- }
- public boolean isKingdom ( ) {
- return i s Ro yal ;
- }
- public void s e t P o l i t i c a l S t a t e ( int p ) {
- p o l i t i c a l S t a t e = p ;
- }
- public void i n c r e a s e C i t i z e n s ( int i ) {
- noO fCi ti z e n s += i ;
- }
- public S t ri n g d i s p l a y ( ) {
- return "Country␣name␣" + countryName + "\n"
- + " I t s ␣ po p ula tio n ␣ i s ␣" + noO fCi ti z e n s + "\n"
- + " I t ␣" + ( i s Ro yal ? " i s ␣" : " i s n ’ t ␣" ) +"a␣Kingdom\n"
- + " I t ␣ i s ␣ l o c a t e d ␣ i n ␣" + c o n ti n e n t + "\n"
- + " I t s ␣ p o l i t i c a l ␣ s t a t e ␣ i s ␣" + g e t P o l i t i c a l S t a t e ( ) ;
- }
- public s t a t i c void main ( S t ri n g [ ] a rg s ) {
- Country c1 = new Country ( ) ;
- c1 . countryName = "Egypt" ;
- c1 . i s Ro yal = f a l s e ;
- c1 . c o n ti n e n t = " A f ri ka " ;
- System . out . p r i n t l n ( c1 . d i s pl a y ( ) ) ;
- Country c2 = new Country ( "Germany" , 20 , f a ls e , "Europe" , 4 ) ;
- System . out . p r i n t l n ( c2 . d i s pl a y ( ) ) ;
- c1 . p o l i t i c a l S t a t e = c2 . p o l i t i c a l S t a t e ;
- System . out . p r i n t l n ( c1 . d i s pl a y ( ) ) ;
- System . out . p r i n t l n ( ( c1 . compareTo ( c2 ) >= 0 )? c1 . countryName : c2 . countryName ) ;
- System . out . p r i n t l n ( ( compareTo ( c1 , c2 ) >= 0 )? c1 . countryName : c2 . countryName ) ;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement