By GokiSoft.com| 16:01 19/09/2022|
Java Basic

Quản lý phòng tập GYM - Java basic BT1167

Yêu cầu thiết kế phần mềm quản lý phòng tập GYM

Thực hiện quản lý các chức năng sau

- Quản lý dụng cụ : tên dụng cụ, trọng lượng, chiều dài, rộng, cao, trạng thái (mới, cũ), loại (mua hay mượn)

- Quản lý đồ uống : tên đồ uống, giá tiền

- Quản lý vé: Tên khách hàng, ngày mua, ngày hết hạn

- Tạo Interface đặt tên là : IInputOutput gồm 2 phương thức input() và display()

Yêu cầu tạo các lớp đối tượng trên + tạo hàm tạo hàm hiển thị + biết rằng lớp đối tượng dụng cụ, đồ uống, vé đều kế thừa IInputOutput

Tạo lớp DataMgr gồm danh sách IInputOutput

- Thực hiện nhập vào N đối tượng (ngẫu nhiên dụng cụ. đồ uống, vé) lưu vào mảng trong DataMgr

- Thực hiện hiển thị thông tin phòng gym trên

Liên kết rút gọn:

https://gokisoft.com/1167

Bình luận

avatar
Nguyễn Hữu Đạt [C1907L]
2020-04-10 09:33:12



/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package gym;

/**
 *
 * @author Laptop88
 */
interface  IInputOutput {
    public void input();
    public void display();
}



/*
     * To change this license header, choose License Headers in Project Properties.
     * To change this template file, choose Tools | Templates
     * and open the template in the editor.
     */
    package gym;

    import java.util.Scanner;

    /**
     *
     * @author Laptop88
     */
    public class toolmanagement implements IInputOutput{
        String name ;
        int weight,length,width,height;
        enum status{
            New, Old
        };
        enum species{
            Buy, Borrow
        };
        status status;
        species species;

        public toolmanagement() {
        }

        public toolmanagement(String name, int weight, int length, int width, int height, status status, species species) {
            this.name = name;
            this.weight = weight;
            this.length = length;
            this.width = width;
            this.height = height;
            this.status = status;
            this.species = species;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public int getWeight() {
            return weight;
        }

        public void setWeight(int weight) {
            this.weight = weight;
        }

        public int getLength() {
            return length;
        }

        public void setLength(int length) {
            this.length = length;
        }

        public int getWidth() {
            return width;
        }

        public void setWidth(int width) {
            this.width = width;
        }

        public int getHeight() {
            return height;
        }

        public void setHeight(int height) {
            this.height = height;
        }

        public status getStatus() {
            return status;
        }

        public void setStatus(status status) {
            this.status = status;
        }

        public species getSpecies() {
            return species;
        }

        public void setSpecies(species species) {
            this.species = species;
        }



        @Override
        public void input() {
            Scanner scan = new Scanner(System.in);
            System.out.println("Enter name: ");
            name = scan.nextLine();

            System.out.println("Enter weight: ");
            weight = Integer.parseInt(scan.nextLine());

            System.out.println("Enter length: ");
            length = Integer.parseInt(scan.nextLine());

            System.out.println("Enter width: ");
           width = Integer.parseInt(scan.nextLine());

            System.out.println("Enter height: ");
           height = Integer.parseInt(scan.nextLine());
        }
        public void inputStatus() {
            Scanner scan = new Scanner(System.in);
            System.out.println("1. New");
            System.out.println("2. Old");
            System.out.println("Choose: ");
            int choose = scan.nextInt();

            switch(choose) {
                case 1:
                    status = status.New;
                    break;
                case 2:
                    status = status.Old;
                    break;
            }
        }
        public void inputSpecies() {
            Scanner scan = new Scanner(System.in);
            System.out.println("1. Buy");
            System.out.println("2. Borrow");
            System.out.println("Choose: ");
            int choose = scan.nextInt();

            switch(choose) {
                case 1:
                    species = species.Buy;
                    break;
                case 2:
                    species = species.Borrow;
                    break;
            }
        }
        @Override
        public void display() {
             System.out.println(toString());
        }

        @Override
        public String toString() {
            return "toolmanagement{" + "name=" + name + ", weight=" + weight + ", length=" + length + ", width=" + width + ", height=" + height + ", status=" + status + ", species=" + species + '}';
        }

    }



/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package gym;

import java.util.Scanner;

/**
 *
 * @author Laptop88
 */
public class ticketmanagement implements IInputOutput{
    String CustomerName, BuyDate, ExpiredDate;

    public ticketmanagement() {
    }

    public ticketmanagement(String CustomerName, String BuyDate, String ExpiredDate) {
        this.CustomerName = CustomerName;
        this.BuyDate = BuyDate;
        this.ExpiredDate = ExpiredDate;
    }

    public String getCustomerName() {
        return CustomerName;
    }

    public void setCustomerName(String CustomerName) {
        this.CustomerName = CustomerName;
    }

    public String getBuyDate() {
        return BuyDate;
    }

    public void setBuyDate(String BuyDate) {
        this.BuyDate = BuyDate;
    }

    public String getExpiredDate() {
        return ExpiredDate;
    }

    public void setExpiredDate(String ExpiredDate) {
        this.ExpiredDate = ExpiredDate;
    }
    
    @Override
    public void input() {
        Scanner input = new Scanner(System.in);
        System.out.println("Enter Drink Name : ");
        CustomerName = input.nextLine();
        System.out.println(" Enter Buy Date :");
        BuyDate = input.nextLine();
        System.out.println(" Enter Expired Date :");
        ExpiredDate = input.nextLine();
    }

    @Override
    public void display() {
         System.out.println(toString()); 
    }

    @Override
    public String toString() {
        return "ticketmanagement{" + "CustomerName=" + CustomerName + ", BuyDate=" + BuyDate + ", ExpiredDate=" + ExpiredDate + '}';
    }
    
}



/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package gym;

import java.util.Scanner;

/**
 *
 * @author Laptop88
 */
public class drinkmanagement implements IInputOutput{
    String drinkname;
    float drinkprice;

    public drinkmanagement() {
    }

    public drinkmanagement(String drinkname, float drinkprice) {
        this.drinkname = drinkname;
        this.drinkprice = drinkprice;
    }

    public String getDrinkname() {
        return drinkname;
    }

    public void setDrinkname(String drinkname) {
        this.drinkname = drinkname;
    }

    public float getDrinkprice() {
        return drinkprice;
    }

    public void setDrinkprice(float drinkprice) {
        this.drinkprice = drinkprice;
    }
    
    @Override
    public void input() {
       Scanner input = new Scanner(System.in);
        System.out.println("Enter Drink Name : ");
        drinkname = input.nextLine();
        System.out.println(" Enter Drink Price :");
        drinkprice = Float.parseFloat(input.nextLine()); 
    }

    @Override
    public void display() {
       System.out.println(toString()); 
    }

    @Override
    public String toString() {
        return "drinkmanagement{" + "drinkname=" + drinkname + ", drinkprice=" + drinkprice + '}';
    }
    
}



/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package gym;

import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author Laptop88
 */
public class DataMgr {
    List<toolmanagement> tools;
    List<drinkmanagement> drinks;
    List<ticketmanagement> tickets;
    private static DataMgr instance = null;
    private DataMgr() {
        tools = new ArrayList<>();
        drinks = new ArrayList<>();
        tickets = new ArrayList<>();
        System.out.println("Init object from class object DataMgr");
    }
    public static DataMgr getInstance() {
        if(instance == null) {
            instance = new DataMgr();
        }
        return instance;
    }
    public List<toolmanagement> getTools() {
        return tools;
    }

    public void setTools(List<toolmanagement> tools) {
        this.tools = tools;
    }

    public List<drinkmanagement> getDrinks() {
        return drinks;
    }

    public void setDrinks(List<drinkmanagement> drinks) {
        this.drinks = drinks;
    }

    public List<ticketmanagement> getTickets() {
        return tickets;
    }

    public void setTickets(List<ticketmanagement> tickets) {
        this.tickets = tickets;
    }
    
}



/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package gym;

import java.util.Scanner;

/**
 *
 * @author Laptop88
 */
public class GYM {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        System.out.println("Enter number of tools :");
        int tools = Integer.parseInt(input.nextLine());
        for (int i = 0; i < tools; i++) {
            toolmanagement tool = new toolmanagement();
            tool.input();
            DataMgr.getInstance().getTools().add(tool);
        }
        System.out.println("Enter number of tickets :");
        int ticks = Integer.parseInt(input.nextLine());
        for (int i = 0; i < ticks; i++) {
            ticketmanagement tickets = new ticketmanagement();
            tickets.input();
            DataMgr.getInstance().getTickets().add(tickets);
        }
        System.out.println("Enter number of drinks :");
        int drinks = Integer.parseInt(input.nextLine());
        for (int i = 0; i < drinks; i++) {
            drinkmanagement drinksz = new drinkmanagement();
            drinksz.input();
            DataMgr.getInstance().getDrinks().add(drinksz);
        }
        System.out.println("Show Tools:");
        for( toolmanagement tmp : DataMgr.getInstance().getTools()) {
            tmp.display();
        }
        System.out.println("Show Tickets:");
        for( ticketmanagement tmp : DataMgr.getInstance().getTickets()) {
            tmp.display();
        }
        System.out.println("Show Drinks:");
        for( drinkmanagement tmp : DataMgr.getInstance().getDrinks()) {
            tmp.display();
        }
        
    }
    }
    



avatar
Hoàng Quang Huy [C1907L]
2020-04-09 15:33:22



// INTERFACE IInputOutput
package Gym;

public interface IInputOutput {
    public void input();
    public void output();
}
-------------------------------------------------------------------------------------
//TOOL
package Gym;

import java.util.Scanner;

public class Tools implements IInputOutput{
    private String name;
    private int weight,length,width,height;

    static enum CONDITION{
        OLD,NEW
    };
    static enum TYPE{
        BUY,BORROW
    }
    CONDITION condition;
    TYPE type;

    public Tools(String name, int weight, int length, int width, int height, CONDITION condition, TYPE type) {
        this.name = name;
        this.weight = weight;
        this.length = length;
        this.width = width;
        this.height = height;
        this.condition = CONDITION.NEW;
        this.type = TYPE.BUY;
    }

    public Tools() {
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getWeight() {
        return weight;
    }

    public void setWeight(int weight) {
        this.weight = weight;
    }

    public int getLength() {
        return length;
    }

    public void setLength(int length) {
        this.length = length;
    }

    public int getWidth() {
        return width;
    }

    public void setWidth(int width) {
        this.width = width;
    }

    public int getHeight() {
        return height;
    }

    public void setHeight(int height) {
        this.height = height;
    }

    public CONDITION getCondition() {
        return condition;
    }

    public void setCondition(CONDITION condition) {
        this.condition = condition;
    }

    public TYPE getType() {
        return type;
    }

    public void setType(TYPE type) {
        this.type = type;
    }
    
    @Override
    public void input() {
        Scanner scan = new Scanner(System.in);
        System.out.println("Input Name: ");
        this.name = scan.nextLine();
        System.out.println("Input Weight: ");
        this.weight = Integer.parseInt(scan.nextLine());
        System.out.println("Input Length: ");
        this.length = Integer.parseInt(scan.nextLine());
        System.out.println("Input Width: ");
        this.width = Integer.parseInt(scan.nextLine());
        System.out.println("Input Height: ");
        this.height = Integer.parseInt(scan.nextLine());
        System.out.println("Input Condition: ");
        System.out.println("1. NEW");
        System.out.println("2. OLD");
        int condition = Integer.parseInt(scan.nextLine());
        switch(condition){
            case 1:
                this.condition = CONDITION.NEW;
                break;
            case 2:
                this.condition = CONDITION.OLD;
                break;
            default:
                System.out.println("Invalid");
                break;
        }
        System.out.println("Input Condition: ");
        System.out.println("1. BUY");
        System.out.println("2. BORROw");
        int type = Integer.parseInt(scan.nextLine());
        switch(type){
            case 1:
                this.type = TYPE.BUY;
                break;
            case 2:
                this.type = TYPE.BORROW;
                break;
            default:
                System.out.println("Invalid");
                break;
        }
    }

    @Override
    public String toString() {
        return "Tools{" + "name=" + name + ", weight=" + weight + ", length=" + length + ", width=" + width + ", height=" + height + ", condition=" + condition + ", type=" + type + '}';
    }

    
    @Override
    public void output() {
        System.out.println(toString());
    }
    
    
}
-------------------------------------------------------------------------------------
//DRINK
package Gym;
import java.util.Scanner;

public class Drink implements IInputOutput{
    private String name;
    private double price;

    public Drink() {
    }

    public Drink(String name, double price) {
        this.name = name;
        this.price = price;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public double getPrice() {
        return price;
    }

    public void setPrice(double price) {
        this.price = price;
    }
    
    
    @Override
    public void input() {
        Scanner scan = new Scanner(System.in);
        System.out.println("Input Drink's name: ");
        this.name = scan.nextLine();
        System.out.println("Input Drink's price: ");
        this.price = Double.parseDouble(scan.nextLine());
    }

    @Override
    public String toString() {
        return "Drink{" + "name=" + name + ", price=" + price + '}';
    }

    @Override
    public void output() {
        System.out.println(toString());
    }
    
}
-------------------------------------------------------------------------------------
//TICKET
package Gym;

import java.util.Scanner;

public class Ticket implements IInputOutput{
    private String customerName,bought,expire;

    public Ticket() {
    }

    public Ticket(String customerName, String bought, String expire) {
        this.customerName = customerName;
        this.bought = bought;
        this.expire = expire;
    }

    public String getCustomerName() {
        return customerName;
    }

    public void setCustomerName(String customerName) {
        this.customerName = customerName;
    }

    public String getBought() {
        return bought;
    }

    public void setBought(String bought) {
        this.bought = bought;
    }

    public String getExpire() {
        return expire;
    }

    public void setExpire(String expire) {
        this.expire = expire;
    }

    @Override
    public String toString() {
        return "Ticket{" + "customerName=" + customerName + ", bought=" + bought + ", expire=" + expire + '}';
    }

    @Override
    public void input() {
        Scanner scan = new Scanner(System.in);
        System.out.println("Input customer's name: ");
        this.customerName = scan.nextLine();
        System.out.println("Input bought date: ");
        this.bought = scan.nextLine();
        System.out.println("Input expire date: ");
        this.expire = scan.nextLine();
    }

    @Override
    public void output() {
        System.out.println(toString());
    }
    
    
}
-------------------------------------------------------------------------------------
// DATA MGR
package Gym;

import java.util.ArrayList;
import java.util.List;

public class DataMgr {
    List<IInputOutput> list;
    
    private static DataMgr instance = null;

    public DataMgr() {
        list = new ArrayList<>();
    }
    
    public static DataMgr getInstance() {
        if(instance == null) {
            instance = new DataMgr();
        }
        return instance;
    }

    public List<IInputOutput> getList() {
        return list;
    }

    public void setList(List<IInputOutput> list) {
        this.list = list;
    }
    
    
}
-------------------------------------------------------------------------------------
// Main 
package Gym;

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);  
        System.out.println("Number of tools: ");
        int toolnumber = Integer.parseInt(scan.nextLine());
        for (int i = 0; i < toolnumber; i++) {
            Tools tool = new Tools();
            tool.input();
            DataMgr.getInstance().getList().add(tool);
        }
        System.out.println("Number of drink: ");
        int drinknumber = Integer.parseInt(scan.nextLine());
        for (int i = 0; i < drinknumber; i++) {
            Drink drink = new Drink();
            drink.input();
            DataMgr.getInstance().getList().add(drink);
        }
        System.out.println("Number of ticket: ");
        int ticketnumber = Integer.parseInt(scan.nextLine());
        for (int i = 0; i < ticketnumber; i++) {
            Ticket ticket = new Ticket();
            ticket.input();
            DataMgr.getInstance().getList().add(ticket);
        }
        
        for (IInputOutput iInputOutput : DataMgr.getInstance().getList()) {
            iInputOutput.output();
        }
    }
}


avatar
trung [C1907L]
2020-04-09 15:32:03



/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package gym;

/**
 *
 * @author prdox
 */
public interface IInputOutput {
    public void input();
    public void display();
}



/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package gym;

import java.util.Scanner;

/**
 *
 * @author prdox
 */
public class Tool implements IInputOutput{
    String name;
    Float weight,height,length,width;
    //status : 0 (new)
    //status : 1 (old)
    //type : buy
    //type : borrow
    Integer status,type;

    public Tool(String name, Float weight, Float height, Float length, Float width, Integer status, Integer type) {
        this.name = name;
        this.weight = weight;
        this.height = height;
        this.length = length;
        this.width = width;
        this.status = status;
        this.type = type;
    }

    public Tool() {
    }

    public String getName() {
        return name;
    }

    public Float getWeight() {
        return weight;
    }

    public Float getHeight() {
        return height;
    }

    public Float getLength() {
        return length;
    }

    public Float getWidth() {
        return width;
    }

    public Integer getStatus() {
        return status;
    }

    public Integer getType() {
        return type;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void setWeight(Float weight) {
        this.weight = weight;
    }

    public void setHeight(Float height) {
        this.height = height;
    }

    public void setLength(Float length) {
        this.length = length;
    }

    public void setWidth(Float width) {
        this.width = width;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public void setType(Integer type) {
        this.type = type;
    }

    @Override
    public void input() {
        Scanner inp = new Scanner(System.in);
        System.out.println("Tool name:");
        name = inp.nextLine();
        System.out.println("Weight: ");
        weight = Float.parseFloat(inp.nextLine());
        System.out.println("Height: ");
        height = Float.parseFloat(inp.nextLine());
        System.out.println("Width: ");
        width = Float.parseFloat(inp.nextLine());
        System.out.println("Length: ");
        length = Float.parseFloat(inp.nextLine());
        System.out.println("Status: (0: new, 1: old)");
        status = Integer.parseInt(inp.nextLine());
        System.out.println("Type: (0: buy, 1: borrow)");
        type = Integer.parseInt(inp.nextLine());
    }

    @Override
    public String toString() {
        return "Tool{" + "name=" + name + ", weight=" + weight + ", height=" + height + ", length=" + length + ", width=" + width + ", status=" + status + ", type=" + type + '}';
    }

    @Override
    public void display() {
        System.out.println(this);
    }
    
}



/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package gym;

import java.util.Scanner;

/**
 *
 * @author prdox
 */
public class Beverage implements IInputOutput{
    String name;
    Float price;

    public Beverage() {
    }

    public Beverage(String name, Float price) {
        this.name = name;
        this.price = price;
    }

    public String getName() {
        return name;
    }

    public Float getPrice() {
        return price;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void setPrice(Float price) {
        this.price = price;
    }

    @Override
    public void input() {
        Scanner inp = new Scanner(System.in);
        System.out.println("Name: ");
        name = inp.nextLine();
        System.out.println("Price");
        price = Float.parseFloat(inp.nextLine());
    }

    @Override
    public String toString() {
        return "Beverage{" + "name=" + name + ", price=" + price + '}';
    }

    @Override
    public void display() {
        System.out.println(this);
    }
}



/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package gym;

import java.util.Scanner;

/**
 *
 * @author prdox
 */
public class Ticket implements IInputOutput{
    String cusName,bDate,vDate;

    public Ticket() {
    }

    public Ticket(String cusName, String bDate, String sDate) {
        this.cusName = cusName;
        this.bDate = bDate;
        this.vDate = sDate;
    }

    public String getCusName() {
        return cusName;
    }

    public String getbDate() {
        return bDate;
    }

    public String getsDate() {
        return vDate;
    }

    public void setCusName(String cusName) {
        this.cusName = cusName;
    }

    public void setbDate(String bDate) {
        this.bDate = bDate;
    }

    public void setsDate(String sDate) {
        this.vDate = sDate;
    }

    @Override
    public void input() {
        Scanner inp = new Scanner(System.in);
        System.out.println("Customer name: ");
        cusName = inp.nextLine();
        System.out.println("Bought date");
        bDate = inp.nextLine();
        System.out.println("Valid date");
        vDate = inp.nextLine();
    }
    
    @Override
    public void display() {
        System.out.println(this);
    }

    @Override
    public String toString() {
        return "Ticket{" + "cusName=" + cusName + ", bDate=" + bDate + ", vDate=" + vDate + '}';
    }

    
}



/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package gym;

import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author prdox
 */
public class DataMgr {
    List<IInputOutput> listObj;
    private static DataMgr instance = null;
    
    private DataMgr() {
        listObj = new ArrayList<>();
    }
    
    public static synchronized DataMgr getInstance() {
        if (instance == null) {
            instance = new DataMgr();
        }
        return instance;
    }

    public List<IInputOutput> getListObj() {
        return listObj;
    }

    public void setListObj(List<IInputOutput> listObj) {
        this.listObj = listObj;
    }

    public void addObj(IInputOutput obj) {
        instance.addObj(obj);
    }
    
    public void showList() {
        listObj.forEach((obj) -> {
            obj.display();
        });
    }
}



/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package gym;

import java.util.Scanner;
/**
 *
 * @author prdox
 */
public class Main {
    public static void main(String[] args) {
        DataMgr mgr = DataMgr.getInstance();
        int n;
        Scanner inp = new Scanner(System.in);
        System.out.println("Tool number: ? ");
        n = Integer.parseInt(inp.nextLine());
        for (int i = 0; i < n; i++) {
            Tool tl = new Tool();
            tl.input();
            mgr.getListObj().add(tl);
        }
        System.out.println("Beverage number: ? ");
        n = Integer.parseInt(inp.nextLine());
        for (int i = 0; i < n; i++) {
            Beverage bvr = new Beverage();
            bvr.input();
            mgr.getListObj().add(bvr);
        }
        System.out.println("Ticket number: ? ");
        n = Integer.parseInt(inp.nextLine());
        for (int i = 0; i < n; i++) {
            Ticket tk = new Ticket();
            tk.input();
            mgr.getListObj().add(tk);
        }
        mgr.showList();
    }
    
}


avatar
Nguyễn Hoàng Anh [C1907L]
2020-04-09 08:26:40



/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package april9;

/**
 *
 * @author Redmibook 14
 */
interface IInputOutput {
    void input();
    void display();
}



/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package april9;

import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author Redmibook 14
 */
public class DataMgr {
    List<IInputOutput> gym;
    public static DataMgr instance = null;
    private DataMgr(){
        gym = new ArrayList<>();
    }
    public static synchronized  DataMgr getInstance(){
        if( instance == null){
            instance = new DataMgr();
        }
        return instance;
    }

    public void setGym(List<IInputOutput> gym) {
        this.gym = gym;
    }
    public List<IInputOutput> getGym() {
        return gym;
    }
}



/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package april9;

import java.util.Scanner;

/**
 *
 * @author Redmibook 14
 */
public class ToolManager implements IInputOutput {

    String ToolName;
    float ToolWeight, ToolLength, ToolHeight, ToolWidth;

    static enum status {
        New, Old
    }

    static enum kind {
        buy, borrow
    }
    status status;
    kind kind;

    @Override
    public void input() {
        Scanner input = new Scanner(System.in);
        System.out.println("Tool Name : ");
        ToolName = input.nextLine();
        System.out.println("Tool Weight :");
        ToolWeight = Float.parseFloat(input.nextLine());
        System.out.println("Tool Length :");
        ToolLength = Float.parseFloat(input.nextLine());
        System.out.println("Tool Height :");
        ToolHeight = Float.parseFloat(input.nextLine());
        System.out.println("Tool Width :");
        ToolWidth = Float.parseFloat(input.nextLine());
        inputStatus();
        inputKind();
    }

    private void inputStatus() {
        Scanner input = new Scanner(System.in);
        System.out.println("1. New");
        System.out.println("2. Old");
        System.out.println("Choose: ");
        int choose = input.nextInt();

        switch (choose) {
            case 1:
                status = status.New;
                break;
            case 2:
                status = status.Old;
                break;
        }
    }
      private void inputKind() {
        Scanner input = new Scanner(System.in);
        System.out.println("1. Buy");
        System.out.println("2. Borrow");
        System.out.println("Choose: ");
        int choose = input.nextInt();

        switch (choose) {
            case 1:
                kind = kind.buy;
                break;
            case 2:
                kind = kind.borrow;
                break;
        }
    }

    @Override
    public void display() {
        System.out.println(toString());
    }

    @Override
    public String toString() {
        return "ToolManager{" + "ToolName=" + ToolName + ", ToolWeight=" + ToolWeight + ", ToolLength=" + ToolLength + ", ToolHeight=" + ToolHeight + ", ToolWidth=" + ToolWidth + ", status=" + status + ", kind=" + kind + '}';
    }

}



/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package april9;

import java.util.Scanner;

/**
 *
 * @author Redmibook 14
 */
public class DrinkManager implements IInputOutput {

    String DrinkName;
    float DrinkPrice;

    @Override
    public void input() {
        Scanner input = new Scanner(System.in);
        System.out.println("Drink Name : ");
        DrinkName = input.nextLine();
        System.out.println("Drink Price :");
        DrinkPrice = Float.parseFloat(input.nextLine());

    }

    @Override
    public void display() {
       System.out.println(toString());
    }

    @Override
    public String toString() {
        return "DrinkManager{" + "DrinkName=" + DrinkName + ", DrinkPrice=" + DrinkPrice + '}';
    }

}



/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package april9;

import java.util.Scanner;

/**
 *
 * @author Redmibook 14
 */
public class TicketManager implements IInputOutput {

    String ClientName;
    String ApplyDate, ExpiredDate;

    @Override
    public void input() {
        Scanner input = new Scanner(System.in);
        System.out.println("Client Name : ");
        ClientName = input.nextLine();
        System.out.println("Apply Date :");
        ApplyDate = input.nextLine();
        System.out.println("Expired Date :");
        ExpiredDate = input.nextLine();
    }

    @Override
    public void display() {
        System.out.println(toString());
    }

    @Override
    public String toString() {
        return "TicketManager{" + "ClientName=" + ClientName + ", ApplyDate=" + ApplyDate + ", ExpiredDate=" + ExpiredDate + '}';
    }
    
}



/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package april9;

import java.util.Scanner;

/**
 *
 * @author Redmibook 14
 */
public class Main {

    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        System.out.println("Enter number of tools :");
        int tools = Integer.parseInt(input.nextLine());
        for (int i = 0; i < tools; i++) {
            ToolManager toolm = new ToolManager();
            toolm.input();
            DataMgr.getInstance().getGym().add(toolm);
        }
        System.out.println("Enter number of tickets :");
        int ticks = Integer.parseInt(input.nextLine());
        for (int i = 0; i < ticks; i++) {
            TicketManager tickets = new TicketManager();
            tickets.input();
            DataMgr.getInstance().getGym().add(tickets);
        }
         System.out.println("Enter number of drinks :");
        int drinks = Integer.parseInt(input.nextLine());
        for (int i = 0; i < drinks; i++) {
            DrinkManager drinksz = new DrinkManager();
            drinksz.input();
            DataMgr.getInstance().getGym().add(drinksz);
        }
        for (IInputOutput in : DataMgr.getInstance().getGym()) {
            in.display();
        }

    }
}


avatar
Ngô Quang Huy [C1907L]
2020-04-09 02:53:47



package April8GYM;

public interface IInputOutput {
    public void input();
    public void output();
}



package April8GYM;

import java.util.Scanner;

public class Tools implements IInputOutput{
    String Name;
    float Weight;
    float Length;
    float Height;
    STATUS stat;
    TYPE type;

    @Override
    public void input() {
        Scanner inp = new Scanner(System.in);
        System.out.print("Insert Name: ");
        Name = inp.nextLine();
        System.out.print("Insert Weight: ");
        Weight = Float.parseFloat(inp.nextLine());
        System.out.print("Insert Length: ");
        Length = Float.parseFloat(inp.nextLine());
        System.out.print("Insert Height: ");
        Height = Float.parseFloat(inp.nextLine());
        System.out.println("Choose STATUS:");
        System.out.println("\t1.New\n\t2.Old");
        int choose = Integer.parseInt(inp.nextLine());
        switch(choose){
            case 1:
                stat = STATUS.NEW;
                break;
            default:
                stat = STATUS.OLD;
                break;
        }
        System.out.println("Choose TYPE:");
        System.out.println("\t1.Buy\n\t2.Borrow");
        choose = Integer.parseInt(inp.nextLine());
        switch(choose){
            case 1:
                type = TYPE.BUY;
                break;
            default:
                type = TYPE.BORROW;
                break;
        }
    }

    @Override
    public void output() {
        System.out.println("Name is: "+Name);
        System.out.println("Weight is: "+Weight);
        System.out.println("Length is: "+Length);
        System.out.println("Height is: "+Height);
        System.out.println("Status is: "+stat);
        System.out.println("Type is: "+type);
    }
    
    enum STATUS {
        NEW,OLD
    };
    enum TYPE {
        BUY,BORROW
    };

    public Tools() {
    }

    public Tools(String Name, float Weight, float Length, float Height) {
        this.Name = Name;
        this.Weight = Weight;
        this.Length = Length;
        this.Height = Height;
    }

    public String getName() {
        return Name;
    }

    public void setName(String Name) {
        this.Name = Name;
    }

    public float getWeight() {
        return Weight;
    }

    public void setWeight(float Weight) {
        this.Weight = Weight;
    }

    public float getLength() {
        return Length;
    }

    public void setLength(float Length) {
        this.Length = Length;
    }

    public float getHeight() {
        return Height;
    }

    public void setHeight(float Height) {
        this.Height = Height;
    }

    public STATUS getStat() {
        return stat;
    }

    public void setStat(STATUS stat) {
        this.stat = stat;
    }

    public TYPE getType() {
        return type;
    }

    public void setType(TYPE type) {
        this.type = type;
    }
    
}



/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package April8GYM;

import java.util.Scanner;

/**
 *
 * @author Administrator
 */
public class Drink implements IInputOutput{
    String Drink;
    float Cost;

    @Override
    public void input() {
        Scanner inp = new Scanner(System.in);
        System.out.print("Insert Drink: ");
        Drink = inp.nextLine();
        System.out.print("Insert Cost: ");
        Cost = Float.parseFloat(inp.nextLine());
    }

    @Override
    public void output() {
        System.out.println("Drink is: "+Drink);
        System.out.println("Cost is: "+Cost);
        
    }

    public Drink() {
    }

    public Drink(String Drink, float Cost) {
        this.Drink = Drink;
        this.Cost = Cost;
    }

    public String getDrink() {
        return Drink;
    }

    public void setDrink(String Drink) {
        this.Drink = Drink;
    }

    public float getCost() {
        return Cost;
    }

    public void setCost(float Cost) {
        this.Cost = Cost;
    }
    
    
}



/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package April8GYM;

import java.util.Scanner;

/**
 *
 * @author Administrator
 */
public class Ticket implements IInputOutput{
    String CustumerName;
    String BuyDate;
    String ExpiredDate;
    
    @Override
    public void input() {
        Scanner inp = new Scanner(System.in);
        System.out.print("Insert CustumerName: ");
        CustumerName = inp.nextLine();
        System.out.print("Insert BuyDate: ");
        BuyDate = inp.nextLine();
        System.out.print("Insert ExpiredDate: ");
        ExpiredDate = inp.nextLine();
    }

    @Override
    public void output() {
        System.out.println("CustumerName is: "+CustumerName);
        System.out.println("BuyDate is: "+BuyDate);
        System.out.println("ExpiredDate is: "+ExpiredDate);
    }

    public Ticket() {
    }

    public Ticket(String CustumerName, String BuyDate, String ExpiredDate) {
        this.CustumerName = CustumerName;
        this.BuyDate = BuyDate;
        this.ExpiredDate = ExpiredDate;
    }

    public String getCustumerName() {
        return CustumerName;
    }

    public void setCustumerName(String CustumerName) {
        this.CustumerName = CustumerName;
    }

    public String getBuyDate() {
        return BuyDate;
    }

    public void setBuyDate(String BuyDate) {
        this.BuyDate = BuyDate;
    }

    public String getExpiredDate() {
        return ExpiredDate;
    }

    public void setExpiredDate(String ExpiredDate) {
        this.ExpiredDate = ExpiredDate;
    }
    
}



/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package April8GYM;

import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author Administrator
 */
public class DataMgr {
    List<Tools> tools;
    List<Drink> drink;
    List<Ticket> ticket;
    
    private static DataMgr instance = null;
    
    private DataMgr() {
        tools = new ArrayList<>();
        drink = new ArrayList<>();
        ticket = new ArrayList<>();
    }
    
    public synchronized static DataMgr getInstance() {
        if(instance == null) {
            instance = new DataMgr();
        }
        return instance;
    }
    

    public List<Tools> getTools() {
        return tools;
    }

    public void setTools(List<Tools> tools) {
        this.tools = tools;
    }

    public List<Drink> getDrink() {
        return drink;
    }

    public void setDrink(List<Drink> drink) {
        this.drink = drink;
    }

    public List<Ticket> getTicket() {
        return ticket;
    }

    public void setTicket(List<Ticket> ticket) {
        this.ticket = ticket;
    }
    
    
}



/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package April8GYM;

import aptech.Product;
import java.util.Scanner;

/**
 *
 * @author Administrator
 */
public class Main {
    public static void main(String[] args) {
        Scanner inp = new Scanner(System.in);
        System.out.println("Number of Tools: ");
        int productNumber = Integer.parseInt(inp.nextLine());
        for(int i=0;i<productNumber;i++){
            Tools toolTemp =new Tools();
            toolTemp.input();
            DataMgr.getInstance().getTools().add(toolTemp);
        }
        
        System.out.println("Number of Drink: ");
        int drinkNumber = Integer.parseInt(inp.nextLine());
        for(int i=0;i<drinkNumber;i++){
            Drink drinkTemp =new Drink();
            drinkTemp.input();
            DataMgr.getInstance().getDrink().add(drinkTemp);
        }
        
        System.out.println("Number of Ticket: ");
        int ticketNumber = Integer.parseInt(inp.nextLine());
        for(int i=0;i<ticketNumber;i++){
            Ticket ticketTemp =new Ticket();
            ticketTemp.input();
            DataMgr.getInstance().getTicket().add(ticketTemp);
        }
        System.out.println("\nAll Tools:");
        for( Tools tmp : DataMgr.getInstance().getTools()) {
            tmp.output();
        }
        System.out.println("\nAll Drink:");
        for( Drink tmp : DataMgr.getInstance().getDrink()) {
            tmp.output();
        }
        System.out.println("\nAll Ticket:");
        for( Ticket tmp : DataMgr.getInstance().getTicket()) {
            tmp.output();
        }
    }
}