Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package game;
- public abstract class Game {
- private String Name, Phonenumber, Address;
- private double Songuoichoi, Sovanchoi, Sovanthua, Sovanthang, Tienvon;
- public static final double Tienga = 2000;
- public static final double Thua = 10000;
- public static final double Thang = 10000;
- public Game(){
- }
- public Game( String name, String phonenumber, String address, double songuoichoi, double sovanchoi, double sovanthua, double sovanthang, double tienvon){
- this.Name = name;
- this.Phonenumber = phonenumber;
- this.Address = address;
- this.Songuoichoi = songuoichoi;
- this.Sovanchoi = sovanchoi;
- this.Sovanthang = sovanthang;
- this.Sovanthua = sovanthua;
- this.Tienvon = tienvon;
- }
- public String getName() {
- return Name;
- }
- public void setName(String name) {
- Name = name;
- }
- public String getPhonenumber() {
- return Phonenumber;
- }
- public void setPhonenumber(String phonenumber) {
- Phonenumber = phonenumber;
- }
- public String getAddress() {
- return Address;
- }
- public void setAddress(String address) {
- Address = address;
- }
- public double getSonguoichoi() {
- return Songuoichoi;
- }
- public void setSonguoichoi(double songuoichoi) {
- Songuoichoi = songuoichoi;
- }
- public double getSovanchoi() {
- return Sovanchoi;
- }
- public void setSovanchoi(double sovanchoi) {
- Sovanchoi = sovanchoi;
- }
- public double getSovanthua() {
- return Sovanthua;
- }
- public void setSovanthua(double sovanthua) {
- Sovanthua = sovanthua;
- }
- public double getSovanthang() {
- return Sovanthang;
- }
- public void setSovanthang(double sovanthang) {
- Sovanthang = sovanthang;
- }
- public double getTienvon() {
- return Tienvon;
- }
- public void setTienvon(double tienvon) {
- Tienvon = tienvon;
- }
- abstract double Tongtien();
- }
- package game;
- public class Bacay extends Game {
- private double Muoi;
- public Bacay() {
- }
- public Bacay(double muoi, String name, String phonenumber,
- String address, double songuoichoi, double sovanchoi,
- double sovanthua, double sovanthang, double tienvon) {
- super (name, phonenumber, address, songuoichoi, sovanthang, sovanthua, tienvon,sovanchoi);
- this.Muoi = muoi;
- }
- public double getMuoi() {
- return Muoi;
- }
- public void setMuoi(double muoi) {
- Muoi = muoi;
- }
- double Tongtien(){
- return getTienvon() + (getSovanthang()-getMuoi())*Thang + getMuoi()*2*Thang - getSovanthua()*Thua - getSovanchoi()*Tienga;
- }
- }
- package game;
- public class Lieng extends Game {
- private double Lieng, Sap;
- public Lieng(){
- }
- public Lieng(double lieng, double sap, String name, String phonenumber, String address, double songuoichoi, double sovanchoi, double sovanthua, double sovanthang, double tienvon){
- super(name, phonenumber, address, songuoichoi, sovanthang, sovanthua, tienvon,sovanchoi);
- this.Lieng = lieng;
- this.Sap = sap;
- }
- public double getLieng() {
- return Lieng;
- }
- public void setLieng(double lieng) {
- Lieng = lieng;
- }
- public double getSap() {
- return Sap;
- }
- public void setSap(double sap) {
- Sap = sap;
- }
- double Tongtien(){
- return getTienvon() + (getSovanthang() - getLieng() - getSap())*Thang + getLieng()*2*Thang + getSap()*3*Thang - getSovanthua()*Thua - getSovanchoi()*Tienga;
- }
- }
- package game;
- import java.util.ArrayList;
- import java.util.Scanner;
- public class Hoichoi {
- private ArrayList<Game> Gamestart;
- private Scanner reader;
- public Hoichoi(){
- Gamestart = new ArrayList<>();
- reader = new Scanner(System.in);
- }
- private Bacay taoBacay(){
- Bacay bc= new Bacay();
- System.out.println(" Nhap so nguoi choi : ");
- bc.setSonguoichoi(Double.parseDouble(reader.nextLine()));
- System.out.println(" Nhap ten nguoi choi : ");
- bc.setName(reader.nextLine());
- System.out.println(" Nhap So dien thoai : ");
- bc.setPhonenumber(reader.nextLine());
- System.out.println(" Nhap dia chi : ");
- bc.setAddress(reader.nextLine());
- System.out.println(" Nhap so van choi : ");
- bc.setSovanchoi(Double.parseDouble(reader.nextLine()));
- System.out.println(" Nhap so van thua : ");
- bc.setSovanthua(Double.parseDouble(reader.nextLine()));
- System.out.println(" Nhap so van thang : ");
- bc.setSovanthang(Double.parseDouble(reader.nextLine()));
- System.out.println(" nhap so van duoc muoi :");
- bc.setMuoi(Double.parseDouble(reader.nextLine()));
- return bc;
- }
- private Lieng taoLieng(){
- Lieng l = new Lieng();
- System.out.println(" Nhap so nguoi choi : ");
- l.setSonguoichoi(Double.parseDouble(reader.nextLine()));
- System.out.println(" Nhap ten nguoi choi : ");
- l.setName(reader.nextLine());
- System.out.println(" Nhap So dien thoai : ");
- l.setPhonenumber(reader.nextLine());
- System.out.println(" Nhap dia chi : ");
- l.setAddress(reader.nextLine());
- System.out.println(" Nhap so van choi : ");
- l.setSovanchoi(Double.parseDouble(reader.nextLine()));
- System.out.println(" Nhap so van thua : ");
- l.setSovanthua(Double.parseDouble(reader.nextLine()));
- System.out.println(" Nhap so van thang : ");
- l.setSovanthang(Double.parseDouble(reader.nextLine()));
- System.out.println(" Nhap so van duoc lieng ");
- l.setLieng(Double.parseDouble(reader.nextLine()));
- System.out.println(" Nhap so van sap : ");
- l.setSap(Double.parseDouble(reader.nextLine()));
- return l;
- }
- public void nhap(){
- System.out.println(" chon 1: choi Lieng ");
- System.out.println(" chon 2: choi Ba Cay");
- System.out.println(" chon 3: Finish");
- int Game;
- do{
- System.out.println(" Ban Chon !");
- Game = Integer.parseInt(reader.nextLine());
- switch(Game){
- case 1 :
- Gamestart.add(taoLieng());
- break;
- case 2 :
- Gamestart.add(taoBacay());
- }
- }while(Game!=3);
- }
- public void xuat(Game G){
- for(int i=0; i<Gamestart.size(); i++){
- System.out.println(" Nhap so nguoi choi : "+G.getSonguoichoi());
- System.out.println(" Nhap ten nguoi choi : "+G.getName());
- System.out.println(" Nhap so dien thoai nguoi choi : "+G.getPhonenumber());
- System.out.println(" Nhap Dia chi cua nguoi choi : "+G.getAddress());
- System.out.println(" nhap so van choi : "+G.getSovanchoi());
- System.out.println(" Nhap so van thang : "+G.getSovanthang());
- System.out.println(" Nhap so van thua : " +G.getSovanthua());
- if(G instanceof Lieng ){
- Lieng l =(Lieng ) G;
- System.out.println(" So van duoc sap : "+l.getSap());
- System.out.println(" So van duoc lieng : "+l.getLieng());
- System.out.println(" So tien sau khi choi : "+l.Tongtien());
- }else{
- Bacay bc = (Bacay) G;
- System.out.println(" So van duoc 10 : "+bc.getMuoi());
- System.out.println(" So tien sau khi choi : "+bc.Tongtien());
- }
- }
- }
- public void xuat(){
- for(Game G : Gamestart){
- xuat(G);
- }
- }
- public static void main(String[]args){
- Hoichoi choi = new Hoichoi();
- choi.nhap();
- choi.xuat();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement