Chương trình quản lý sinh viên bằng HashMap - Java Advanced
/*
* 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 com.gokisoft.bt1058;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
/**
*
* @author teacher
*/
public class Main {
public static void main(String[] args) {
//rollNo -> key -> String, key => value, key = rollNo, value = Student
HashMap<String, Student> maps = new HashMap<>();
Scanner scan = new Scanner(System.in);
int choose;
do {
showMenu();
choose = Integer.parseInt(scan.nextLine());
switch (choose) {
case 1: {
System.out.println("Nhap so sinh vien can them: ");
int n = Integer.parseInt(scan.nextLine());
for (int i = 0; i < n; i++) {
Student std = new Student();
std.input();
maps.put(std.getRollNo(), std);
}
break;
}
case 2:
System.out.println("Danh sach sinh vien");
for (Map.Entry<String, Student> entry : maps.entrySet()) {
Student std = entry.getValue();
std.display();
}
break;
case 3:
System.out.println("Nhap MSV can tim kiem: ");
String rollNo = scan.nextLine();
if(maps.containsKey(rollNo)) {
Student std = maps.get(rollNo);
std.display();
}
break;
case 4:
System.out.println("Thoat!!!");
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 sv");
System.out.println("3. Tim kiem");
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 com.gokisoft.bt1058;
import java.util.Scanner;
/**
*
* @author teacher
*/
public class Student {
String rollNo;
String sex;
String name;
int age;
String email;
String address;
public Student() {
}
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 getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
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;
}
@Override
public String toString() {
return "rollNo=" + rollNo + ", sex=" + sex + ", name=" + name + ", age=" + age + ", email=" + email + ", address=" + address;
}
public void display() {
System.out.println(this);
}
public void input() {
Scanner scan = new Scanner(System.in);
System.out.println("Nhap MSV: ");
rollNo = scan.nextLine();
System.out.println("Nhap gioi tinh: ");
sex = scan.nextLine();
System.out.println("Nhap ten: ");
name = scan.nextLine();
System.out.println("Nhap tuoi: ");
age = Integer.parseInt(scan.nextLine());
System.out.println("Nhap email: ");
email = scan.nextLine();
System.out.println("Nhap dia chi: ");
address = scan.nextLine();
}
}
Ứng Dụng Học
Theo dõi cập nhật nội dung học trên Youtube & Facebook
Thông Tin Liên Hệ
Công Ty Cổ Phần Công nghệ ZicZac Việt Nam.
Website: https://gozic.vn
SĐT: 096 - 70 25 996
Email: ziczacgroup@gmail.com
Thiết kế webiste chuyên nghiệp
Thiết kế phần mềm quản trị
Thiết kế ứng dụng Android
Thiết kế ứng dụng IOS
Thiết kế Web App
Hỗ trợ Digital Marketing
Hỗ trợ quảng cáo Google Ads
Hỗ trợ quảng cáo Facebook Ads
Hỗ trợ SEO Website