Advertisement
minh0702

bai3

Sep 21st, 2014
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package game;
  2.  
  3. public abstract class Game {
  4. private String Name, Phonenumber, Address;
  5. private double Songuoichoi, Sovanchoi, Sovanthua, Sovanthang, Tienvon;
  6. public static final double Tienga = 2000;
  7. public static final double Thua = 10000;
  8. public static final double Thang = 10000;
  9. public Game(){
  10.  
  11. }
  12. public Game( String name, String phonenumber, String address, double songuoichoi, double sovanchoi, double sovanthua, double sovanthang, double tienvon){
  13. this.Name = name;
  14. this.Phonenumber = phonenumber;
  15. this.Address = address;
  16. this.Songuoichoi = songuoichoi;
  17. this.Sovanchoi = sovanchoi;
  18. this.Sovanthang = sovanthang;
  19. this.Sovanthua = sovanthua;
  20. this.Tienvon = tienvon;
  21.  
  22. }
  23. public String getName() {
  24. return Name;
  25. }
  26. public void setName(String name) {
  27. Name = name;
  28. }
  29. public String getPhonenumber() {
  30. return Phonenumber;
  31. }
  32. public void setPhonenumber(String phonenumber) {
  33. Phonenumber = phonenumber;
  34. }
  35. public String getAddress() {
  36. return Address;
  37. }
  38. public void setAddress(String address) {
  39. Address = address;
  40. }
  41. public double getSonguoichoi() {
  42. return Songuoichoi;
  43. }
  44. public void setSonguoichoi(double songuoichoi) {
  45. Songuoichoi = songuoichoi;
  46. }
  47. public double getSovanchoi() {
  48. return Sovanchoi;
  49. }
  50. public void setSovanchoi(double sovanchoi) {
  51. Sovanchoi = sovanchoi;
  52. }
  53. public double getSovanthua() {
  54. return Sovanthua;
  55. }
  56. public void setSovanthua(double sovanthua) {
  57. Sovanthua = sovanthua;
  58. }
  59. public double getSovanthang() {
  60. return Sovanthang;
  61. }
  62. public void setSovanthang(double sovanthang) {
  63. Sovanthang = sovanthang;
  64. }
  65. public double getTienvon() {
  66. return Tienvon;
  67. }
  68. public void setTienvon(double tienvon) {
  69. Tienvon = tienvon;
  70. }
  71. abstract double Tongtien();
  72.  
  73. }
  74.  
  75.  
  76. package game;
  77.  
  78. public class Bacay extends Game {
  79. private double Muoi;
  80.  
  81. public Bacay() {
  82. }
  83.  
  84. public Bacay(double muoi, String name, String phonenumber,
  85. String address, double songuoichoi, double sovanchoi,
  86. double sovanthua, double sovanthang, double tienvon) {
  87. super (name, phonenumber, address, songuoichoi, sovanthang, sovanthua, tienvon,sovanchoi);
  88. this.Muoi = muoi;
  89.  
  90. }
  91.  
  92. public double getMuoi() {
  93. return Muoi;
  94. }
  95.  
  96. public void setMuoi(double muoi) {
  97. Muoi = muoi;
  98. }
  99. double Tongtien(){
  100. return getTienvon() + (getSovanthang()-getMuoi())*Thang + getMuoi()*2*Thang - getSovanthua()*Thua - getSovanchoi()*Tienga;
  101. }
  102.  
  103. }
  104.  
  105.  
  106. package game;
  107.  
  108. public class Lieng extends Game {
  109. private double Lieng, Sap;
  110. public Lieng(){
  111.  
  112. }
  113. public Lieng(double lieng, double sap, String name, String phonenumber, String address, double songuoichoi, double sovanchoi, double sovanthua, double sovanthang, double tienvon){
  114. super(name, phonenumber, address, songuoichoi, sovanthang, sovanthua, tienvon,sovanchoi);
  115. this.Lieng = lieng;
  116. this.Sap = sap;
  117.  
  118. }
  119. public double getLieng() {
  120. return Lieng;
  121. }
  122. public void setLieng(double lieng) {
  123. Lieng = lieng;
  124. }
  125. public double getSap() {
  126. return Sap;
  127. }
  128. public void setSap(double sap) {
  129. Sap = sap;
  130. }
  131. double Tongtien(){
  132. return getTienvon() + (getSovanthang() - getLieng() - getSap())*Thang + getLieng()*2*Thang + getSap()*3*Thang - getSovanthua()*Thua - getSovanchoi()*Tienga;
  133. }
  134.  
  135. }
  136.  
  137.  
  138. package game;
  139.  
  140. import java.util.ArrayList;
  141. import java.util.Scanner;
  142.  
  143. public class Hoichoi {
  144. private ArrayList<Game> Gamestart;
  145. private Scanner reader;
  146. public Hoichoi(){
  147. Gamestart = new ArrayList<>();
  148. reader = new Scanner(System.in);
  149.  
  150. }
  151. private Bacay taoBacay(){
  152. Bacay bc= new Bacay();
  153. System.out.println(" Nhap so nguoi choi : ");
  154. bc.setSonguoichoi(Double.parseDouble(reader.nextLine()));
  155. System.out.println(" Nhap ten nguoi choi : ");
  156. bc.setName(reader.nextLine());
  157. System.out.println(" Nhap So dien thoai : ");
  158. bc.setPhonenumber(reader.nextLine());
  159. System.out.println(" Nhap dia chi : ");
  160. bc.setAddress(reader.nextLine());
  161. System.out.println(" Nhap so van choi : ");
  162. bc.setSovanchoi(Double.parseDouble(reader.nextLine()));
  163. System.out.println(" Nhap so van thua : ");
  164. bc.setSovanthua(Double.parseDouble(reader.nextLine()));
  165. System.out.println(" Nhap so van thang : ");
  166. bc.setSovanthang(Double.parseDouble(reader.nextLine()));
  167. System.out.println(" nhap so van duoc muoi :");
  168. bc.setMuoi(Double.parseDouble(reader.nextLine()));
  169. return bc;
  170.  
  171. }
  172. private Lieng taoLieng(){
  173. Lieng l = new Lieng();
  174. System.out.println(" Nhap so nguoi choi : ");
  175. l.setSonguoichoi(Double.parseDouble(reader.nextLine()));
  176. System.out.println(" Nhap ten nguoi choi : ");
  177. l.setName(reader.nextLine());
  178. System.out.println(" Nhap So dien thoai : ");
  179. l.setPhonenumber(reader.nextLine());
  180. System.out.println(" Nhap dia chi : ");
  181. l.setAddress(reader.nextLine());
  182. System.out.println(" Nhap so van choi : ");
  183. l.setSovanchoi(Double.parseDouble(reader.nextLine()));
  184. System.out.println(" Nhap so van thua : ");
  185. l.setSovanthua(Double.parseDouble(reader.nextLine()));
  186. System.out.println(" Nhap so van thang : ");
  187. l.setSovanthang(Double.parseDouble(reader.nextLine()));
  188. System.out.println(" Nhap so van duoc lieng ");
  189. l.setLieng(Double.parseDouble(reader.nextLine()));
  190. System.out.println(" Nhap so van sap : ");
  191. l.setSap(Double.parseDouble(reader.nextLine()));
  192. return l;
  193. }
  194. public void nhap(){
  195. System.out.println(" chon 1: choi Lieng ");
  196. System.out.println(" chon 2: choi Ba Cay");
  197. System.out.println(" chon 3: Finish");
  198. int Game;
  199. do{
  200. System.out.println(" Ban Chon !");
  201. Game = Integer.parseInt(reader.nextLine());
  202. switch(Game){
  203. case 1 :
  204. Gamestart.add(taoLieng());
  205. break;
  206. case 2 :
  207. Gamestart.add(taoBacay());
  208. }
  209. }while(Game!=3);
  210. }
  211. public void xuat(Game G){
  212. for(int i=0; i<Gamestart.size(); i++){
  213. System.out.println(" Nhap so nguoi choi : "+G.getSonguoichoi());
  214. System.out.println(" Nhap ten nguoi choi : "+G.getName());
  215. System.out.println(" Nhap so dien thoai nguoi choi : "+G.getPhonenumber());
  216. System.out.println(" Nhap Dia chi cua nguoi choi : "+G.getAddress());
  217. System.out.println(" nhap so van choi : "+G.getSovanchoi());
  218. System.out.println(" Nhap so van thang : "+G.getSovanthang());
  219. System.out.println(" Nhap so van thua : " +G.getSovanthua());
  220. if(G instanceof Lieng ){
  221. Lieng l =(Lieng ) G;
  222. System.out.println(" So van duoc sap : "+l.getSap());
  223. System.out.println(" So van duoc lieng : "+l.getLieng());
  224. System.out.println(" So tien sau khi choi : "+l.Tongtien());
  225. }else{
  226. Bacay bc = (Bacay) G;
  227. System.out.println(" So van duoc 10 : "+bc.getMuoi());
  228. System.out.println(" So tien sau khi choi : "+bc.Tongtien());
  229. }
  230.  
  231. }
  232. }
  233. public void xuat(){
  234. for(Game G : Gamestart){
  235. xuat(G);
  236. }
  237. }
  238. public static void main(String[]args){
  239. Hoichoi choi = new Hoichoi();
  240. choi.nhap();
  241. choi.xuat();
  242. }
  243.  
  244. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement