By GokiSoft.com| 15:39 10/07/2023|
Java Advanced

Chương trình quản lý sinh viên bằng HashMap - Java Advanced

1. Tạo 1 lớp sinh viên gồm các thuộc tính (RollNo, Name, Sex, Age, Email, Address).

Tạo hàm tạo không đối và hàm tạo có đầy đủ tham số.

2. Tạo một HashMap quản lý danh sách sinh viên, dùng rollNo là key cho HashMap

3. Xây dựng menu chương trình

- Nhập N sinh viên

- In thông tin sv

- Tìm kiếm sinh viên (Yêu cầu nhập RollNo và hiển thị thông tin sv đó)

Phản hồi từ học viên

5

(Dựa trên đánh giá ngày hôm nay)

vuong huu phu [T2008A]
vuong huu phu

2021-03-10 10:32:08



/*
 * 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 sinh_vien;

import java.util.Scanner;

/**
 *
 * @author Admin
 */
public class Sinh_vien {
String RollNo,Name,Sex,Email,Address;
int Age;
Scanner scan = new Scanner(System.in);
    public Sinh_vien() {
    }

    public Sinh_vien(String RollNo, String Name, String Sex, String Email, String Address, int Age) {
        this.RollNo = RollNo;
        this.Name = Name;
        this.Sex = Sex;
        this.Email = Email;
        this.Address = Address;
        this.Age = Age;
    }
public void nhap(){
    System.out.println("RollNo");
    RollNo = scan.nextLine();
    System.out.println("Name");
    Name = scan.nextLine();
    System.out.println("Sex");
    Sex = scan.nextLine();
    System.out.println("Email");
    Email = scan.nextLine();
    System.out.println("Address");
    Address = scan.nextLine();
    System.out.println("Age");
    Age = Integer.parseInt(scan.nextLine());
    System.out.println("");
}

    @Override
    public String toString() {
        return "RollNo=" + RollNo + ", Name=" + Name + ", Sex=" + Sex + ", Email=" + Email + ", Address=" + Address + ", Age=" + Age;
    }

}



Nguyễn Tiến Đạt [T2008A]
Nguyễn Tiến Đạt

2021-03-10 10:14:44


#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 Java2.lesson1.QuanLiSinhVienHashMap;

import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

/**
 *
 * @author MyPC
 */
public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        Map<String, Student> studentList = new HashMap<>();
        int choose;
        do{
            showMenu();
            System.out.println("Lua chon chuong trinh:");
            choose = Integer.parseInt(scan.nextLine());
            switch(choose){
                case 1:
                    System.out.println("So luong sinh vien muon nhap:");
                    int select = Integer.parseInt(scan.nextLine());
                    for (int i = 0; i < select; i++) {
                        Student student = new Student();
                        student.input();
                        studentList.put(student.rollNo, student);
                    }
                    break;
                case 2:
                    studentList.entrySet().forEach((sinhVien) -> {
                        System.out.println(sinhVien);
                    });
                    break;
                case 3:
                    System.out.println("Nhap ma sinh vien can tim kiem:");
                    int check = 0;
                    String msv = scan.nextLine();
                    for (Map.Entry<String, Student> sinhVien : studentList.entrySet()) {
                        if(sinhVien.getKey().equalsIgnoreCase(msv)){
                            System.out.println("Da tim thay!!");
                            System.out.println(sinhVien);
                            check++;
                            break;
                        }
                    }
                    if(check == 0) System.out.println("Khong tim thay sinh vien!!");
                    break;
                case 4:
                    System.out.println("Tam biet!!");
                    break;
                default:
                    System.out.println("Nhap sai!!");
                    break;
            }
            
        }while(choose != 4 );
    }
    
    static void showMenu(){
        System.out.println("1.Nhap N sinh vien");
        System.out.println("2.In thong tin sinh vien");
        System.out.println("3.Tim kiem sinh vien theo Rollno");
        System.out.println("4.Thoat");
    }
}


#Student.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 Java2.lesson1.QuanLiSinhVienHashMap;

import java.util.Scanner;

/**
 *
 * @author MyPC
 */
public class Student {
    String rollNo, name, sex, email, address;
    int age;

    public Student() {
        
    }

    public Student(String rollNo, String name, String sex, String email, String address, int age) {
        
        this.rollNo = rollNo;
        this.name = name;
        this.sex = sex;
        this.email = email;
        this.address = address;
        this.age = age;
    }
    
    public void input(){
        Scanner scan = new Scanner(System.in);
        System.out.println("Ma sinh vien:");
        rollNo = scan.nextLine();
        System.out.println("Ten:");
        name = scan.nextLine();
        System.out.println("Gioi tinh:");
        sex = scan.nextLine();
        System.out.println("Tuoi:");
        age = Integer.parseInt(scan.nextLine());
        System.out.println("Email:");
        email = scan.nextLine();
        System.out.println("Dia chi:");
        address = scan.nextLine();
    }

    @Override
    public String toString() {
        return "Student{" + "name=" + name + ", sex=" + sex + ", email=" + email + ", address=" + address + ", age=" + age + '}';
    }
    
    
}



Thành Lâm [T1907A]
Thành Lâm

2020-04-23 20:20:04



/*
 * 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 HashMap;

import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

/**
 *
 * @author Admin
 */
public class Main {
    public static void main(String[] args) {
        Map<String, Student> studentHashMap = new HashMap<>();
        
        Scanner input = new Scanner(System.in);
        int choose;
        
        do {
            showMenu();
            choose = Integer.parseInt(input.nextLine());
            
            switch(choose) {
                case 1:
                    System.out.println("Nhap N: ");
                    int n = Integer.parseInt(input.nextLine());
                    for (int i = 0; i < n; i++) {
                        Student std = new Student();
                        std.input();
                        
                        studentHashMap.put(std.getRollNo(), std);
                    }
                    break;
                case 2:
                    System.out.println("Thong tin sinh vien");
                    for (Map.Entry<String, Student> entry : studentHashMap.entrySet()) {
                        Student value = entry.getValue();
                        value.display();
                    }
                    break;
                case 3:
                    System.out.println("Nhap MSV can tim kiem: ");
                    String rollNo = input.nextLine();
                    
                    Student stdFind = studentHashMap.get(rollNo);
                    stdFind.display();
                    break;
                case 4:
                    System.out.println("Exit!!!");
                    break;
            }
        } while(choose != 4);
    }
    
    static void showMenu() {
        System.out.println("1. Nhap N sinh vien");
        System.out.println("2. In thong tin sinh vien");
        System.out.println("3. Tim kiem sinh vien theo RollNo");
        System.out.println("4. Thoat");
        System.out.println("Chon: ");
    }
}



/*
 * 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 HashMap;

import java.util.Scanner;

/**
 *
 * @author Admin
 */
public class Student {
    String name, rollNo, sex, email, address;
    int age;

    public Student() {
    }

    public Student(String name, String rollNo, String sex, String email, String address, int age) {
        this.name = name;
        this.rollNo = rollNo;
        this.sex = sex;
        this.email = email;
        this.address = address;
        this.age = age;
    }
    public void input() {
        Scanner input = new Scanner(System.in);
        System.out.println("Nhap ten: ");
        name = input.nextLine();
        
        System.out.println("Nhap MSV: ");
        rollNo = input.nextLine();
        
        System.out.println("Nhap gioi tinh: ");
        sex = input.nextLine();
        
        System.out.println("Nhap Email: ");
        email = input.nextLine();
        
        System.out.println("Nhap dia chi: ");
        address = input.nextLine();
        
        System.out.println("Nhap tuoi: ");
        age = Integer.parseInt(input.nextLine());
    }
    @Override
    public String toString() {
        return "Student{" + "name=" + name + ", rollNo=" + rollNo + ", sex=" + sex + ", email=" + email + ", address=" + address + ", age=" + age + '}';
    }
    public void display(){
        System.out.println(this);
    }
            
    public String getName() {
        return name;
    }

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

    public String getRollNo() {
        return rollNo;
    }

    public void setRollNo(String rollNo) {
        this.rollNo = rollNo;
    }

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        this.sex = sex;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

}



Phan Bạch Tùng Dương [T1907A]
Phan Bạch Tùng Dương

2020-04-23 12:47:39



/*
 * 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 QLSVHashMap;

import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

/**
 *
 * @author Admin
 */
public class Main {

    public static void main(String[] args) {
        Map<String, Student> studentHashMap = new HashMap<>();

        Scanner input = new Scanner(System.in);
        int choose;

        do {
            showMenu();
            choose = Integer.parseInt(input.nextLine());

            switch (choose) {
                case 1:
                    System.out.println("Enter number: ");
                    int n = Integer.parseInt(input.nextLine());
                    for (int i = 0; i < n; i++) {
                        Student std = new Student();
                        std.input();

                        studentHashMap.put(std.getRollNo(), std);
                    }
                    break;
                case 2:
                    System.out.println("Student information: ");
                    for (Map.Entry<String, Student> entry : studentHashMap.entrySet()) {
                        Student value = entry.getValue();
                        value.display();
                    }
                    break;
                case 3:
                    System.out.println("Enter student code:  ");
                    String rollNo = input.nextLine();

                    Student stdFind = studentHashMap.get(rollNo);
                    stdFind.display();
                    break;
                case 4:
                    System.out.println("Exit!!!");
                    break;
            }
        } while (choose != 4);
    }

    static void showMenu() {
        System.out.println("1. Enter the number of students:");
        System.out.println("2. Display students information: ");
        System.out.println("3. Search students by roll no: ");
        System.out.println("4. Quit.");
        System.out.println("Choose(1 -> 4)1: ");
    }
}



/*
 * 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 QLSVHashMap;

import java.util.Scanner;

/**
 *
 * @author Admin
 */
public class Student {

    String name, rollNo, sex, email, address;
    int age;

    public Student() {
    }

    public Student(String name, String rollNo, String sex, String email, String address, int age) {
        this.name = name;
        this.rollNo = rollNo;
        this.sex = sex;
        this.email = email;
        this.address = address;
        this.age = age;
    }

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

        System.out.println("Enter student code: ");
        rollNo = input.nextLine();

        System.out.println("Enter sex: ");
        sex = input.nextLine();

        System.out.println("Enter email: ");
        email = input.nextLine();

        System.out.println("Enter address: ");
        address = input.nextLine();

        System.out.println("Enter age: ");
        age = Integer.parseInt(input.nextLine());
    }

    @Override
    public String toString() {
        return "Student{" + "name=" + name + ", rollNo=" + rollNo + ", sex=" + sex + ", email=" + email + ", address=" + address + ", age=" + age + '}';
    }

    public void display() {
//        System.out.println(toString());
        System.out.println(this);
    }

    public String getName() {
        return name;
    }

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

    public String getRollNo() {
        return rollNo;
    }

    public void setRollNo(String rollNo) {
        this.rollNo = rollNo;
    }

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        this.sex = sex;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }
}



Nguyễn Hoàng Anh [C1907L]
Nguyễn Hoàng Anh

2020-04-23 07:54:17



/*
 * 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 HashMap;

import java.util.Scanner;

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

    String RollNo, Name, Email, Address;

    enum SEX {
        MALE, FEMALE
    }
    SEX Sex;
    int Age;

    public Student(String RollNo, String Name, String Email, String Address, int Age) {
        this.RollNo = RollNo;
        this.Name = Name;
        this.Email = Email;
        this.Address = Address;
        this.Age = Age;
    }

    public Student() {
    }

    public String getRollNo() {
        return RollNo;
    }

    public String getName() {
        return Name;
    }

    public String getEmail() {
        return Email;
    }

    public String getAddress() {
        return Address;
    }

    public int getAge() {
        return Age;
    }

    public void setRollNo(String RollNo) {
        this.RollNo = RollNo;
    }

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

    public void setEmail(String Email) {
        this.Email = Email;
    }

    public void setAddress(String Address) {
        this.Address = Address;
    }

    public void setAge(int Age) {
        this.Age = Age;
    }

    public void input() {
        Scanner input = new Scanner(System.in);
        System.out.println("Enter rollNo :");
        RollNo = input.nextLine();
        System.out.println("Enter Name :");
        Name = input.nextLine();
        System.out.println("Enter Email :");
        Email = input.nextLine();
        System.out.println("Enter Address :");
        Address = input.nextLine();
        System.out.println("Enter Age :");
        try {
            String StrAge = input.nextLine();
            Age = Integer.parseInt(StrAge);
        } catch (NumberFormatException ex) {
            System.err.println("Age must be a number!");
            return;
        }

        System.out.println("Choose sex :");
        System.out.println("1.Male ");
        System.out.println("2.Female ");
        int choice = Integer.parseInt(input.nextLine());
        switch (choice) {
            case 1:
                Sex = Sex.MALE;
                break;
            case 2:
                Sex = Sex.FEMALE;
                break;

        }
    }

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

    @Override
    public String toString() {
        return "HashMap{" + "RollNo=" + RollNo + ", Name=" + Name + ", Email=" + Email + ", Address=" + Address + ", Sex=" + Sex + ", Age=" + Age + '}';
    }

}



/*
 * 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 HashMap;

import java.util.HashMap;
import java.util.Scanner;

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

    public static void menu() {
        System.out.println("1.Enter students");
        System.out.println("2.Show students");
        System.out.println("3.Find students");
        System.out.println("4.Exit");
    }

    public static void main(String[] args) {
        HashMap map = new HashMap();
        Scanner input = new Scanner(System.in);
        while (true) {
            menu();
            int choice = Integer.parseInt(input.nextLine());
            switch (choice) {
                case 1:
                    Student student = new Student();
                    student.input();
                    map.put(student.RollNo, student);
                    break;
                case 2:
                    for (Object value : map.values()) {
                        System.out.println(value);
                    }
                    break;
                case 3:
                    System.out.println("Enter RollNo :");
                    String Roll = input.nextLine();
                    if(map.containsKey(Roll)){
                        System.out.println(map.get(Roll));
                    }else{
                        System.out.println("Student rollNo ins't exists!");
                    }
                    break;
            }
        }
    }
}



Ngô Quang Huy [C1907L]
Ngô Quang Huy

2020-04-22 14:23:00



/*
 * 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 April22StringBuilder;

import java.util.HashMap;
import java.util.Scanner;

/**
 *
 * @author Administrator
 */
public class Hashmap {
    public static void main(String[] args) {
        HashMap<String,Student> stdHM = new HashMap<>();
        Scanner input = new Scanner(System.in);
        while(true){
            showMenu();
            System.out.print("choose: ");
            int choose = Integer.parseInt(input.nextLine());
            switch(choose){
                case 1 :
                    System.out.print("Enter number: ");
                    int n = Integer.parseInt(input.nextLine());
                    for(int i=0;i<n;i++){
                        Student std = new Student();
                        System.out.println("\nStudent "+(i+1));
                        std.input();
                        stdHM.put(std.getRollNo(), std);
                    }
                    break;
                case 2:
                    for (Student i : stdHM.values()) {
                        System.out.println("\n");
                        i.output();
                    }
                    break;
                case 3:
                    String rnb = input.nextLine();
                    stdHM.get(rnb).output();
                    break;
                default:
                    System.exit(0);
            }
        }
    }
    
    static void showMenu(){
        System.out.println("\n1.Nhập N sinh viên");
        System.out.println("2.In thông tin sv");
        System.out.println("3.Tìm kiếm sinh viên");
        System.out.println("4.Exit.");
    }
}



/*
 * 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 April22StringBuilder;

import java.util.Scanner;

/**
 *
 * @author Administrator
 */
public class Student {
    String RollNo, Name, Sex, Email, Address;
    int Age;

    public Student() {
    }

    public Student(String RollNo, String Name, String Sex, String Email, String Address, int Age) {
        this.RollNo = RollNo;
        this.Name = Name;
        this.Sex = Sex;
        this.Email = Email;
        this.Address = Address;
        this.Age = Age;
    }

    public String getRollNo() {
        return RollNo;
    }

    public void setRollNo(String RollNo) {
        this.RollNo = RollNo;
    }

    public String getName() {
        return Name;
    }

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

    public String getSex() {
        return Sex;
    }

    public void setSex(String Sex) {
        this.Sex = Sex;
    }

    public String getEmail() {
        return Email;
    }

    public void setEmail(String Email) {
        this.Email = Email;
    }

    public String getAddress() {
        return Address;
    }

    public void setAddress(String Address) {
        this.Address = Address;
    }
    
    public void input(){
        Scanner input = new Scanner(System.in);
        System.out.print("Insert Rollnumber: ");
        RollNo = input.nextLine();
        System.out.print("Insert Name: ");
        Name = input.nextLine();
        System.out.println("Choose Sex: ");
        System.out.println("1.Male\n2.Female");
        int choose = Integer.parseInt(input.nextLine());
        switch(choose){
            case 1:
                Sex = "Male";
                break;
            case 2:
                Sex = "Female";
                break;
        }
        System.out.print("Insert Age: ");
        Age = Integer.parseInt(input.nextLine());
        System.out.print("Insert Email: ");
        Email = input.nextLine();
        System.out.print("Insert Address: ");
        Address = input.nextLine();
    }

    @Override
    public String toString() {
        return "Student{" + "RollNo=" + RollNo + ", Name=" + Name + ", Sex=" + Sex + ", Email=" + Email + ", Address=" + Address + ", Age=" + Age + '}';
    }
    
    
    
    public void output(){
        System.out.println(toString());
    }
}



Đường Thanh Bình [T1907A]
Đường Thanh Bình

2020-03-25 10:59:43



/*
 * 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 QliSvMap;

import static Bt81.Main.showMenu;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

/**
 *
 * @author Administrator
 */
public class Main {
    public static void main(String[] agrs){
        Map<String, Student> studentHashMap = new HashMap<>();
        
        Scanner input = new Scanner(System.in);
        int choose;
        
        do {
            showMenu();
            choose = Integer.parseInt(input.nextLine());
            
            switch(choose){
                case 1:
                    System.out.println("Nhập N: ");
                    int n = Integer.parseInt(input.nextLine());
                    for (int i = 0; i < n; i++){
                        Student std = new Student();
                        std.input();
                        
                        studentHashMap.put(std.getRollNo(), std);
                    }
                    break;
                case 2:
                    System.out.println("Thông tin sinh viên:");
                     for (Map.Entry<String, Student> entry : studentHashMap.entrySet()) {
                        Student value = entry.getValue();
                        value.display();
                    }
                     case 3:
                    System.out.println("Nhap MSV can tim kiem: ");
                    String rollNo = input.nextLine();
                    
                    Student stdFind = studentHashMap.get(rollNo);
                    stdFind.display();
                    break;
                case 4:
                    System.out.println("Exit!!!");
                    break;
            }
        } while(choose != 4);
    }
    
    static void showMenu() {
        System.out.println("1. Nhap N sinh vien");
        System.out.println("2. In thong tin sinh vien");
        System.out.println("3. Tim kiem sinh vien theo RollNo");
        System.out.println("4. Thoat");
        System.out.println("Chon: ");
    }
}



/*
 * 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 QliSvMap;

import java.util.Scanner;

/**
 *
 * @author Administrator
 */
public class Student {
    String RollNo, Name, Email, Sex, Address;
    int Age;

    public Student() {
    }

    public Student(String RollNo, String Name, String Email, String Sex, String Address, int Age) {
        this.RollNo = RollNo;
        this.Name = Name;
        this.Email = Email;
        this.Sex = Sex;
        this.Address = Address;
        this.Age = Age;
    }
    public void input(){
        Scanner input = new Scanner(System.in);
        System.out.println("NHập tên:");
        Name = input.nextLine();
        
        System.out.println("Nhập MSv: ");
        RollNo = input.nextLine();
        
        System.out.println("Nhập giới tính:");
        Sex = input.nextLine();
        
        System.out.println("Nhập Email: ");
        Email = input.nextLine();
        
        System.out.println("Nhập địa chỉ:");
        Address = input.nextLine();
        
        System.out.println("Nhập tuổi: ");
        Age = Integer.parseInt(input.nextLine());
    }

    @Override
    public String toString() {
        return "Student{" + "RollNo=" + RollNo + ", Name=" + Name + ", Email=" + Email + ", Sex=" + Sex + ", Address=" + Address + ", Age=" + Age + '}';
    }
    public void display(){
        System.out.println("this");
    }

    public String getRollNo() {
        return RollNo;
    }

    public void setRollNo(String RollNo) {
        this.RollNo = RollNo;
    }

    public String getName() {
        return Name;
    }

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

    public String getEmail() {
        return Email;
    }

    public void setEmail(String Email) {
        this.Email = Email;
    }

    public String getSex() {
        return Sex;
    }

    public void setSex(String Sex) {
        this.Sex = Sex;
    }

    public String getAddress() {
        return Address;
    }

    public void setAddress(String Address) {
        this.Address = Address;
    }

    public int getAge() {
        return Age;
    }

    public void setAge(int Age) {
        this.Age = Age;
    }
    
    
}



nguyễn văn huy [T1907A]
nguyễn văn huy

2020-03-24 14:16:14



/*
 * 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 qlsvhashmap;

import java.util.*;

/**
 *
 * @author ASUS
 */
public class main {

    public static void main(String[] args) {
        Map<String, sinhvien> sinhmap = new HashMap<>();
        Scanner scan = new Scanner(System.in);
        int choise, n;
        do {
            menu();
            choise = Integer.parseInt(scan.nextLine());
            switch (choise) {
                case 1:
                    System.out.println("nhap so sv.....");
                    n = Integer.parseInt(scan.nextLine());
                    for (int i = 0; i < n; i++) {
                        sinhvien thao = new sinhvien();
                        thao.input();
                        sinhmap.put(thao.getRollNo(), thao);
                    }
                    break;
                case 2:
                    System.out.println("tt sinh vien");
                    for (Map.Entry<String, sinhvien> entry : sinhmap.entrySet()) {
                        sinhvien thaoxinh = entry.getValue();
                        thaoxinh.display();
                    }
                    break;
                case 3:
                    System.out.println("nhap ma sv can tim");
                    String RollNo = scan.nextLine();
                    sinhvien thaobeou = sinhmap.get(RollNo);
                    thaobeou.display();
                    break;
                case 4:
                    System.out.println("thoat");
                    break;
                default:
                    System.out.println("nhap sai!!!!");
                    break;

            }

        } while (choise != 4);
    }

    static void menu() {
        System.out.println("1. Nhap N sinh vien");
        System.out.println("2. In thong tin sinh vien");
        System.out.println("3. Tim kiem sinh vien theo RollNo");
        System.out.println("4. Thoat");
        System.out.println("Chon: ");
    }
}
//////
/*
 * 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 virut;

import java.util.*;

/**
 *
 * @author ASUS
 */
public class thao {

    static enum thaovirut {
        binhthuong, theodoi, benh;
    }
    String name, cmt, gioitinh, diachi, dctamchu;
    int tuoi;
    thaovirut virut;
    ArrayList<String> addList = new ArrayList<>();

    public thao() {
        virut = thaovirut.binhthuong;
        ArrayList<String> add = new ArrayList<>();
    }

    public void input() {
        Scanner scan = new Scanner(System.in);
        System.out.println("nhap ten:");
        name = scan.nextLine();
        System.out.println("nhap Cmt");
        cmt = scan.nextLine();
        System.out.println("nhao gioi tinh:");
        gioitinh = scan.nextLine();
        System.out.println("nhap dia chi:");
        diachi = scan.nextLine();
        System.out.println("nhap dia chi thuong chu");
        dctamchu = scan.nextLine();
        System.out.println("nhap tuoi:");
        tuoi = Integer.parseInt(scan.nextLine());
    }

    public void display() {
        System.out.format("ten:%s,cmt:%s,gioitinh:%s,diachi:%s,dctamchu:%s,tuoi:%s", name, cmt, gioitinh, diachi, dctamchu, tuoi);
        switch (virut) {
            case binhthuong:
                System.out.println("binh thuong");
                break;
            case theodoi:
                System.out.println("dang theo doi");
                break;
            case benh:
                System.out.println("bi duong tinh");
                break;
        }
        if (addList.size() > 0) {
            System.out.println("lo trinh benh nhan");
            for (String add : addList) {
                System.out.println(add);
            }
        }
    }

    public void dichuyen() {
        Scanner scan = new Scanner(System.in);
        for(;;){
            System.out.println("nhap dia chi di chuyen");
            String newdiachi=scan.nextLine();
            if(!addList.contains(newdiachi)){
                addList.add(newdiachi);
            }
            System.out.println("nhap them dia chi di chuyen ko???");
            String newthao=scan.nextLine();
            if(newthao.equalsIgnoreCase("No")){
                break;
            }
        }
    }

    public thao(String name, String cmt, String gioitinh, String diachi, String dctamchu, int tuoi, thaovirut virut) {
        this.name = name;
        this.cmt = cmt;
        this.gioitinh = gioitinh;
        this.diachi = diachi;
        this.dctamchu = dctamchu;
        this.tuoi = tuoi;
        this.virut = virut;
    }

    public String getName() {
        return name;
    }

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

    public String getCmt() {
        return cmt;
    }

    public void setCmt(String cmt) {
        this.cmt = cmt;
    }

    public String getGioitinh() {
        return gioitinh;
    }

    public void setGioitinh(String gioitinh) {
        this.gioitinh = gioitinh;
    }

    public String getDiachi() {
        return diachi;
    }

    public void setDiachi(String diachi) {
        this.diachi = diachi;
    }

    public String getDctamchu() {
        return dctamchu;
    }

    public void setDctamchu(String dctamchu) {
        this.dctamchu = dctamchu;
    }

    public int getTuoi() {
        return tuoi;
    }

    public void setTuoi(int tuoi) {
        this.tuoi = tuoi;
    }

    public thaovirut getVirut() {
        return virut;
    }

    public void setVirut(thaovirut virut) {
        this.virut = virut;
    }

}





Phí Văn Long [T1907A]
Phí Văn Long

2020-03-24 13:05:24

Main:



/*
 * 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 HashMap;

import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

/**
 *
 * @author Admin
 */
public class Main {
    public static void main(String[] args) {
        Map<String, Student> studentHashMap = new HashMap<>();
        
        Scanner input = new Scanner(System.in);
        int choose;
        
        do {
            showMenu();
            choose = Integer.parseInt(input.nextLine());
            
            switch(choose) {
                case 1:
                    System.out.println("Nhap N: ");
                    int n = Integer.parseInt(input.nextLine());
                    for (int i = 0; i < n; i++) {
                        Student std = new Student();
                        std.input();
                        
                        studentHashMap.put(std.getRollNo(), std);
                    }
                    break;
                case 2:
                    System.out.println("Thong tin sinh vien");
                    for (Map.Entry<String, Student> entry : studentHashMap.entrySet()) {
                        Student value = entry.getValue();
                        value.display();
                    }
                    break;
                case 3:
                    System.out.println("Nhap MSV can tim kiem: ");
                    String rollNo = input.nextLine();
                    
                    Student stdFind = studentHashMap.get(rollNo);
                    stdFind.display();
                    break;
                case 4:
                    System.out.println("Exit!!!");
                    break;
            }
        } while(choose != 4);
    }
    
    static void showMenu() {
        System.out.println("1. Nhap N sinh vien");
        System.out.println("2. In thong tin sinh vien");
        System.out.println("3. Tim kiem sinh vien theo RollNo");
        System.out.println("4. Thoat");
        System.out.println("Chon: ");
    }
}

Student:




/*
 * 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 HashMap;

import java.util.Scanner;

/**
 *
 * @author Admin
 */
public class Student {
    String name, rollNo, sex, email, address;
    int age;

    public Student() {
    }

    public Student(String name, String rollNo, String sex, String email, String address, int age) {
        this.name = name;
        this.rollNo = rollNo;
        this.sex = sex;
        this.email = email;
        this.address = address;
        this.age = age;
    }
    public void input() {
        Scanner input = new Scanner(System.in);
        System.out.println("Nhap ten: ");
        name = input.nextLine();
        
        System.out.println("Nhap MSV: ");
        rollNo = input.nextLine();
        
        System.out.println("Nhap gioi tinh: ");
        sex = input.nextLine();
        
        System.out.println("Nhap Email: ");
        email = input.nextLine();
        
        System.out.println("Nhap dia chi: ");
        address = input.nextLine();
        
        System.out.println("Nhap tuoi: ");
        age = Integer.parseInt(input.nextLine());
    }
    @Override
    public String toString() {
        return "Student{" + "name=" + name + ", rollNo=" + rollNo + ", sex=" + sex + ", email=" + email + ", address=" + address + ", age=" + age + '}';
    }
    public void display(){
        System.out.println(this);
    }
            
    public String getName() {
        return name;
    }

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

    public String getRollNo() {
        return rollNo;
    }

    public void setRollNo(String rollNo) {
        this.rollNo = rollNo;
    }

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        this.sex = sex;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

}



Trần Văn Điệp [C1803L,JavaFree]
Trần Văn Điệp

2020-03-23 07:26:26

Source Code


/*
 * 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 java2.lession2.student;

import java.util.Scanner;

/**
 *
 * @author Diep.Tran
 */
public class Student {
    String name, rollNo, sex, email, address;
    int age;

    public Student() {
    }

    public Student(String name, String rollNo, String sex, String email, String address, int age) {
        this.name = name;
        this.rollNo = rollNo;
        this.sex = sex;
        this.email = email;
        this.address = address;
        this.age = age;
    }
    
    public void input() {
        Scanner input = new Scanner(System.in);
        System.out.println("Nhap ten: ");
        name = input.nextLine();
        
        System.out.println("Nhap MSV: ");
        rollNo = input.nextLine();
        
        System.out.println("Nhap gioi tinh: ");
        sex = input.nextLine();
        
        System.out.println("Nhap Email: ");
        email = input.nextLine();
        
        System.out.println("Nhap dia chi: ");
        address = input.nextLine();
        
        System.out.println("Nhap tuoi: ");
        age = Integer.parseInt(input.nextLine());
    }

    @Override
    public String toString() {
        return "Student{" + "name=" + name + ", rollNo=" + rollNo + ", sex=" + sex + ", email=" + email + ", address=" + address + ", age=" + age + '}';
    }
    
    public void display() {
//        System.out.println(toString());
        System.out.println(this);
    }

    public String getName() {
        return name;
    }

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

    public String getRollNo() {
        return rollNo;
    }

    public void setRollNo(String rollNo) {
        this.rollNo = rollNo;
    }

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        this.sex = sex;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }
}



/*
 * 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 java2.lession2.student;

import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

/**
 *
 * @author Diep.Tran
 */
public class Main {
    public static void main(String[] args) {
        Map<String, Student> studentHashMap = new HashMap<>();
        
        Scanner input = new Scanner(System.in);
        int choose;
        
        do {
            showMenu();
            choose = Integer.parseInt(input.nextLine());
            
            switch(choose) {
                case 1:
                    System.out.println("Nhap N: ");
                    int n = Integer.parseInt(input.nextLine());
                    for (int i = 0; i < n; i++) {
                        Student std = new Student();
                        std.input();
                        
                        studentHashMap.put(std.getRollNo(), std);
                    }
                    break;
                case 2:
                    System.out.println("Thong tin sinh vien");
                    for (Map.Entry<String, Student> entry : studentHashMap.entrySet()) {
                        Student value = entry.getValue();
                        value.display();
                    }
                    break;
                case 3:
                    System.out.println("Nhap MSV can tim kiem: ");
                    String rollNo = input.nextLine();
                    
                    Student stdFind = studentHashMap.get(rollNo);
                    stdFind.display();
                    break;
                case 4:
                    System.out.println("Exit!!!");
                    break;
            }
        } while(choose != 4);
    }
    
    static void showMenu() {
        System.out.println("1. Nhap N sinh vien");
        System.out.println("2. In thong tin sinh vien");
        System.out.println("3. Tim kiem sinh vien theo RollNo");
        System.out.println("4. Thoat");
        System.out.println("Chon: ");
    }
}