Advertisement
Guest User

Untitled

a guest
Apr 27th, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.56 KB | None | 0 0
  1. public c l a s s Country {
  2. S t ri n g countryName ;
  3. int noO fCi ti z e n s ;
  4. boolean i s Ro yal ;
  5. S t ri n g c o n ti n e n t ;
  6. int p o l i t i c a l S t a t e ;
  7. public Country ( ) {
  8. countryName = "" ;
  9. noO fCi ti z e n s = 0 ;
  10. i s Ro yal = f a l s e ;
  11. c o n ti n e n t = "" ;
  12. p o l i t i c a l S t a t e = 0 ;
  13. }
  14. public Country ( S t ri n g n , int nc , boolean r ,
  15. S t ri n g c , int p ) {
  16. countryName = n ;
  17. noO fCi ti z e n s = nc ;
  18. i s Ro yal = r ;
  19. c o n ti n e n t = c ;
  20. p o l i t i c a l S t a t e = p ;
  21. }
  22. public S t ri n g g e t P o l i t i c a l S t a t e ( ) {
  23. S t ri n g r e s u l t ;
  24. switch ( p o l i t i c a l S t a t e ) {
  25. 6
  26. case 1 :
  27. r e s u l t = "war" ;
  28. break ;
  29. case 2 :
  30. 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 " ;
  31. break ;
  32. case 3 :
  33. 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 " ;
  34. break ;
  35. case 4 :
  36. r e s u l t = " peace " ;
  37. break ;
  38. de fau lt :
  39. r e s u l t = " not ␣ e n t e r e d ␣ ye t " ;
  40. }
  41. return r e s u l t ;
  42. }
  43. public int compareTo ( Country a ){
  44. return noO fCi ti z e n s − a . noO fCi ti z e n s ;
  45. }
  46. public s t a t i c int compareTo ( Country a , Country b ){
  47. return a . noO fCi ti z e n s − b . noO fCi ti z e n s ;
  48. }
  49. public boolean isKingdom ( ) {
  50. return i s Ro yal ;
  51. }
  52. public void s e t P o l i t i c a l S t a t e ( int p ) {
  53. p o l i t i c a l S t a t e = p ;
  54. }
  55. public void i n c r e a s e C i t i z e n s ( int i ) {
  56. noO fCi ti z e n s += i ;
  57. }
  58. public S t ri n g d i s p l a y ( ) {
  59. return "Country␣name␣" + countryName + "\n"
  60. + " I t s ␣ po p ula tio n ␣ i s ␣" + noO fCi ti z e n s + "\n"
  61. + " I t ␣" + ( i s Ro yal ? " i s ␣" : " i s n ’ t ␣" ) +"a␣Kingdom\n"
  62. + " I t ␣ i s ␣ l o c a t e d ␣ i n ␣" + c o n ti n e n t + "\n"
  63. + " 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 ( ) ;
  64. }
  65. public s t a t i c void main ( S t ri n g [ ] a rg s ) {
  66. Country c1 = new Country ( ) ;
  67. c1 . countryName = "Egypt" ;
  68. c1 . i s Ro yal = f a l s e ;
  69. c1 . c o n ti n e n t = " A f ri ka " ;
  70. System . out . p r i n t l n ( c1 . d i s pl a y ( ) ) ;
  71. Country c2 = new Country ( "Germany" , 20 , f a ls e , "Europe" , 4 ) ;
  72. System . out . p r i n t l n ( c2 . d i s pl a y ( ) ) ;
  73. 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 ;
  74. System . out . p r i n t l n ( c1 . d i s pl a y ( ) ) ;
  75. System . out . p r i n t l n ( ( c1 . compareTo ( c2 ) >= 0 )? c1 . countryName : c2 . countryName ) ;
  76. 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