Tạo bởi Trắc Nghiệm Việt|
[Source Code] Quản lý phòng tập GYM - Java basic - C2108L
Java Basic
[Source Code] Quản lý phòng tập GYM - Java basic - C2108L
Quản lý phòng tập GYM - Java basic
#Ve.java
/*
* 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 bt1167;
import java.util.Scanner;
/**
*
* @author Diep.Tran
*/
public class Ve implements IInputOutput{
String customerName, buyDate, expiredDate;
public Ve() {
}
@Override
public void input() {
Scanner scan = new Scanner(System.in);
System.out.println("Nhap ten KH: ");
customerName = scan.nextLine();
System.out.println("Nhap ngay mua: ");
buyDate = scan.nextLine();
System.out.println("Nhap ngay het han: ");
expiredDate = scan.nextLine();
}
@Override
public void display() {
System.out.println(this);
}
@Override
public String toString() {
return "customerName=" + customerName + ", buyDate=" + buyDate + ", 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;
}
}
#Main.java
/*
* 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 bt1167;
/**
*
* @author Diep.Tran
*/
public class Main {
public static void main(String[] args) {
DataMgr dataMgr = new DataMgr();
dataMgr.input();
dataMgr.display();
}
}
#IInputOutput.java
/*
* 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 bt1167;
/**
*
* @author Diep.Tran
*/
public interface IInputOutput {
void input();
void display();
}
#DungCu.java
/*
* 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 bt1167;
import java.util.Scanner;
/**
*
* @author Diep.Tran
*/
public class DungCu implements IInputOutput{
String name, status, type;
public DungCu() {
}
@Override
public void input() {
Scanner scan = new Scanner(System.in);
System.out.println("Nhap ten: ");
name = scan.nextLine();
System.out.println("Nhap trang thai: ");
status = scan.nextLine();
System.out.println("Nhap loai: ");
type = scan.nextLine();
}
@Override
public void display() {
System.out.println(this);
}
@Override
public String toString() {
return "name=" + name + ", status=" + status + ", type=" + type;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
}
#DoUong.java
/*
* 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 bt1167;
import java.util.Scanner;
/**
*
* @author Diep.Tran
*/
public class DoUong implements IInputOutput{
String name;
float price;
public DoUong() {
}
@Override
public void input() {
Scanner scan = new Scanner(System.in);
System.out.println("Nhap ten: ");
name = scan.nextLine();
System.out.println("Nhap gia: ");
price = Float.parseFloat(scan.nextLine());
}
@Override
public void display() {
System.out.println(this);
}
@Override
public String toString() {
return "name=" + name + ", price=" + price;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public float getPrice() {
return price;
}
public void setPrice(float price) {
this.price = price;
}
}
#DataMgr.java
/*
* 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 bt1167;
import java.util.ArrayList;
import java.util.Random;
import java.util.Scanner;
/**
*
* @author Diep.Tran
*/
public class DataMgr implements IInputOutput{
ArrayList<IInputOutput> dataList;
public DataMgr() {
dataList = new ArrayList<>();
}
public ArrayList<IInputOutput> getDataList() {
return dataList;
}
public void setDataList(ArrayList<IInputOutput> dataList) {
this.dataList = dataList;
}
@Override
public void input() {
Scanner scan = new Scanner(System.in);
System.out.println("Nhap so doi tuong can them: ");
int N = Integer.parseInt(scan.nextLine());
Random random = new Random();
for (int i = 0; i < N; i++) {
int rad = random.nextInt(2);
IInputOutput io;
switch(rad) {
case 0:
System.out.println("Nhap thong tin dung cu: ");
io = new DungCu();
break;
case 1:
System.out.println("Nhap thong tin do uong: ");
io = new DoUong();
break;
default:
System.out.println("Nhap thong tin ve: ");
io = new Ve();
break;
}
io.input();
dataList.add(io);
}
}
@Override
public void display() {
System.out.println("Thong tin dung cu: ");
for (IInputOutput io : dataList) {
io.display();
}
}
}