By GokiSoft.com|
17:20 29/10/2021|
Java Advanced
[Examination] Kiểm tra 60 phút - Đề 2
Kiểm Tra Thực Hành Java Nâng Cao
Tags:
Phản hồi từ học viên
5
(Dựa trên đánh giá ngày hôm nay)
![Võ Như Việt [C2010L]](https://www.gravatar.com/avatar/fb93c99beb23339eb21f4d4ffe8981af.jpg?s=80&d=mm&r=g)
Võ Như Việt
2021-08-31 14:05:21
#Customer.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 Java2Buoi9.BT1174;
import java.util.Scanner;
/**
*
* @author ADMIN
*/
public class Customer {
String name, email, phone;
public Customer() {
}
public Customer(String name, String email, String phone) {
this.name = name;
this.email = email;
this.phone = phone;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getEmail() {
return email;
}
public boolean setEmail(String email) {
if (email.contains("@")) {
this.email = email;
return true;
} else {
System.out.println("Email wrong...");
}
return false;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public void input() {
Scanner sc = new Scanner(System.in);
System.out.println("Enter name: ");
name = sc.nextLine();
System.out.println("Enter Email: ");
while (!setEmail(sc.nextLine())) {
System.out.println("Email must have @...");
}
System.out.println("Enter Phone: ");
phone = sc.nextLine();
}
@Override
public String toString() {
return name + " " + phone ;
}
public void display(){
System.out.println(this);
}
}
#Program.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 Java2Buoi9.BT1174;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
/**
*
* @author ADMIN
*/
public class Program {
static Scanner sc = new Scanner(System.in);
public static void main(String args[]) {
Map<String, Customer> maps = new HashMap<>();
int choose;
do {
showMenu();
choose = Integer.parseInt(sc.nextLine());
switch(choose){
case 1:
System.out.println("Enter N customer: ");
int n = Integer.parseInt(sc.nextLine());
for (int i = 0; i < n; i++) {
System.out.println("Customer is " +(i+1));
Customer c = new Customer();
c.input();
maps.put(c.getName(), c);
}
break;
case 2:
System.out.println("Enter the name u want to search : ");
String nameSearch = sc.nextLine();
for (Map.Entry<String, Customer> check : maps.entrySet()) {
if (check.getKey().equalsIgnoreCase(nameSearch)) {
System.out.println("Customer name found is " + check);
break;
}else{
System.out.println("Not found..");
break;
}
}
break;
case 3:
System.out.println(" CRM ");
System.out.println("Name Phone nummber");
for (Map.Entry<String, Customer> entry : maps.entrySet()) {
Customer val = entry.getValue();
System.out.println(val);
}
break;
case 4:
System.out.println("Exit program");
break;
default:
System.out.println("Again....");
break;
}
} while (choose != 4);
}
static void showMenu(){
System.out.println("++=================++");
System.out.println("1.Add new customer");
System.out.println("2.Find by name");
System.out.println("3.Display all");
System.out.println("4.Exit");
System.out.println("Chosse: ");
}
}
![PHẠM VĂN LIÊM [C2010G]](https://www.gravatar.com/avatar/dd86ba4e56b73bc1514e889b2ac18c6d.jpg?s=80&d=mm&r=g)
PHẠM VĂN LIÊM
2021-08-30 04:14:37
#customer.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 Assigament;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
* @author ASUS
*/
public class customer {
String name,email,phone,address;
public customer() {
}
public customer(String name, String email, String phone, String address) {
this.name = name;
this.email = email;
this.phone = phone;
this.address = address;
}
public void input() {
InputStreamReader reader = new InputStreamReader(System.in);
BufferedReader bufferedReader = new BufferedReader(reader);
try {
System.out.println("Nhap ten khach hang");
name = bufferedReader.readLine();
System.out.println("Nhap email khach hang");
email = bufferedReader.readLine();
System.out.println("Nhap dien thoai khach hang");
phone = bufferedReader.readLine();
System.out.println("Nhap dia chi");
address = bufferedReader.readLine();
} catch (IOException ex) {
Logger.getLogger(customer.class.getName()).log(Level.SEVERE, null, ex);
}
}
public void display() {
System.out.println(this);
}
@Override
public String toString() {
return "customer{" + "name=" + name + ", email=" + email + ", phone=" + phone + ", address=" + address + '}';
}
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 getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
}
#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 Assigament;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Scanner;
/**
*
* @author ASUS
*/
public class Main {
public static void main(String[] args) {
HashMap<String, customer> hash = new HashMap<>();
int choose;
Scanner sc = new Scanner(System.in);
do {
showMenu();
choose = Integer.parseInt(sc.nextLine());
switch(choose) {
case 1:
System.out.println("Nhap so khach hang muon them");
int n = Integer.parseInt(sc.nextLine());
for(int i = 0; i < n; i++) {
customer ct = new customer();
ct.input();
hash.put(ct.getName(), ct);
}
break;
case 2:
System.out.println("Nhap ten khach hang can tim");
String name = sc.nextLine();
if(hash.containsKey(name)) {
System.out.println(hash.get(name));
} else {
System.out.println("Khach hang tren khong ton tai");
}
break;
case 3:
for(String i : hash.keySet()) {
System.out.println(hash.get(i));
}
break;
case 4:
System.out.println("Seee you again");
break;
default:
System.out.println("Please input again");
break;
}
} while(choose != 4);
}
static void showMenu() {
System.out.println("1:Add new Customer.");
System.out.println("2:Find by name");
System.out.println("3:Display all");
System.out.println("4:Exit");
}
}
![nguyễn Sử [T2008A]](https://www.gravatar.com/avatar/47487be2776ac2ec915b0936ef7ab5ae.jpg?s=80&d=mm&r=g)
nguyễn Sử
2021-03-25 09:19:49
/*
* 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 qhkh;
import java.util.Scanner;
/**
*
* @author WIN10
*/
public class quanhekhachhang {
String name, email;
int phonenumber;
public quanhekhachhang() {
}
public quanhekhachhang(String name, String email, int phonenumber) {
this.name = name;
this.email = email;
this.phonenumber = phonenumber;
}
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 int getPhonenumber() {
return phonenumber;
}
public void setPhonenumber(int phonenumber) {
this.phonenumber = phonenumber;
}
@Override
public String toString() {
return "quanhekhachhang{" + "name=" + name + ", email=" + email + ", phonenumber=" + phonenumber + '}';
}
public void input(){
Scanner scan = new Scanner(System.in);
System.out.println("nhap ten: ");
name = scan.nextLine();
System.out.println("nhap email: ");
email = scan.nextLine();
System.out.println("nhap so dien thoai: ");
phonenumber = scan.nextInt();
}
public void display(){
System.out.println("toString");
}
}
![nguyễn Sử [T2008A]](https://www.gravatar.com/avatar/47487be2776ac2ec915b0936ef7ab5ae.jpg?s=80&d=mm&r=g)
nguyễn Sử
2021-03-25 09:19:05
/*
* 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 qhkh;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
/**
*
* @author WIN10
*/
public class main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
Map<String, quanhekhachhang> xxx = new HashMap<>();
int choose;
do {
showMenu();
choose = Integer.parseInt(scan.nextLine());
switch (choose) {
case 1:
System.out.println("nhap ten khach hang: ");
int n;
n = Integer.parseInt(scan.nextLine());
for (int i = 0; i < n; i++) {
quanhekhachhang qhkh = new quanhekhachhang();
qhkh.input();
xxx.put(qhkh.getName(), qhkh);
}
break;
case 2:
System.out.println("tim theo ten khach hang: ");
String nameFind = scan.nextLine();
for (Map.Entry<String, quanhekhachhang> entry : xxx.entrySet()) {
if (entry.getKey().equalsIgnoreCase(nameFind)) {
System.out.println("entry");
} else {
System.out.println("khong tim thay khach hang!!!!");
}
}
break;
case 3:
System.out.println("hien thi tat ca khach hang: ");
for (Map.Entry<String, quanhekhachhang> entryxxx : xxx.entrySet()) {
String key = entryxxx.getKey();
quanhekhachhang value = entryxxx.getValue();
value.display();
}
break;
case 4:
System.out.println("thoat!!!!");
break;
default:
System.out.println("nhap lai!!!!!");
break;
}
} while (choose != 4);
}
public static void showMenu() {
System.out.println("==================================");
System.out.println("xin moi chon: ");
System.out.println("1: them khach hang: ");
System.out.println("2: tìm theo ten khach hang: ");
System.out.println("3: hien thi tat ca: ");
System.out.println("4: thoat: ");
}
}
![Nguyễn Tiến Đạt [T2008A]](https://www.gravatar.com/avatar/b5819cd0adc95c727c7ad0c2bcf6098b.jpg?s=80&d=mm&r=g)
Nguyễn Tiến Đạt
2021-03-25 03:50:52
#Customer.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.lesson6.Customer;
import static Java2.lesson6.Customer.CustomerRelationship.customerList;
import java.util.Map;
import java.util.Scanner;
/**
*
* @author MyPC
*/
public class Customer {
String name, phoneNumber, email;
public Customer() {
}
public Customer(String name, String phoneNumber, String email) {
this.name = name;
this.phoneNumber = phoneNumber;
this.email = email;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPhoneNumber() {
return phoneNumber;
}
public void setPhoneNumber(String phoneNumber) {
this.phoneNumber = phoneNumber;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public void add(String a, String b){
CustomerRelationship.customerList.put(a, b);
}
public void search(){
Scanner scan = new Scanner(System.in);
System.out.println("Nhap ten:");
String nameSearch = scan.nextLine();
int check = 0;
for (Map.Entry<String, String> entry : customerList.entrySet()) {
if(entry.getKey().equalsIgnoreCase(nameSearch)){
check++;
String a = "Name";
String b = "Phone number";
String c = "CRM";
System.out.format("%15s",c);
System.out.println("");
System.out.format("%-20s%-20s",a,b);
System.out.println("");
System.out.format("%-20s%-20s",entry.getKey(),entry.getValue());
System.out.println("");
break;
}
}
if(check == 0) System.out.println("Khong tim thay nhan vien nao");
}
public void show(){
String a = "Name";
String b = "Phone number";
String c = "CRM";
System.out.format("%15s",c);
System.out.println("");
System.out.format("%-20s%-20s",a,b);
System.out.println("");
customerList.entrySet().stream().map((entry) -> {
System.out.format("%-20s%-20s",entry.getKey(),entry.getValue());
return entry;
}).forEachOrdered((_item) -> {
System.out.println("");
});
}
@Override
public String toString() {
return "Customer{" + "name=" + name + ", phoneNumber=" + phoneNumber + ", email=" + email + '}';
}
}
#CustomerRelationship.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.lesson6.Customer;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
/**
*
* @author MyPC
*/
public class CustomerRelationship {
static HashMap<String,String> customerList = new HashMap<>();
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
Customer csm = new Customer();
int choose;
do{
showMenu();
System.out.println("Lua chon chuong trinh:");
choose = Integer.parseInt(scan.nextLine());
switch(choose){
case 1:
Customer customer = new Customer();
System.out.println("Nhap ten:");
customer.name = scan.nextLine();
System.out.println("Nhap so dien thoai:");
customer.phoneNumber = scan.nextLine();
System.out.println("Nhap email:");
customer.email = scan.nextLine();
customer.add(customer.name, customer.phoneNumber);
break;
case 2:
csm.search();
break;
case 3:
csm.show();
break;
case 4:
System.out.println("Tam biet");
break;
default:
System.out.println("Loi");
break;
}
}while(choose !=4);
}
static void showMenu(){
System.out.println("1.Add new customer");
System.out.println("2.Find by name");
System.out.println("3.Display all");
System.out.println("4.Exit");
}
}
![Do Trung Duc [T2008A]](https://www.gravatar.com/avatar/2973ac07124f066b4605c535e8d39a99.jpg?s=80&d=mm&r=g)
Do Trung Duc
2021-03-25 03:21:26
/*
* 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 ex.test;
import java.util.Scanner;
/**
*
* @author TrungDuc
*/
public class Customer {
String name;
String email;
String phoneNumber;
public Customer() {
}
public Customer(String name, String email, String phoneNumber) {
this.name = name;
this.email = email;
this.phoneNumber = phoneNumber;
}
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 getPhoneNumber() {
return phoneNumber;
}
public void setPhoneNumber(String phoneNumber) {
this.phoneNumber = phoneNumber;
}
public void input() {
Scanner scan = new Scanner(System.in);
System.out.println("Nhap Name:");
name = scan.nextLine();
System.out.println("Nhap Email:");
email = scan.nextLine();
System.out.println("Nhap PhoneNumber:");
phoneNumber = scan.nextLine();
}
@Override
public String toString() {
return "Customer{" + "name=" + name + ", email=" + email + ", phoneNumber=" + phoneNumber + '}';
}
}
![Do Trung Duc [T2008A]](https://www.gravatar.com/avatar/2973ac07124f066b4605c535e8d39a99.jpg?s=80&d=mm&r=g)
Do Trung Duc
2021-03-25 03:21: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 ex.test;
import java.util.HashMap;
import java.util.Scanner;
import java.util.Set;
/**
*
* @author TrungDuc
*/
public class Main {
static HashMap<String, Object> customerList = new HashMap<>();
public static void main(String[] agrs) {
int choose;
do {
Menu();
Scanner scan = new Scanner(System.in);
choose = Integer.parseInt(scan.nextLine());
switch (choose) {
case 1:
addCustomer();
break;
case 2:
findByName();
break;
case 3:
displayAll();
break;
case 4:
Exit();
break;
default:
System.out.println("Nhap choose sai!!!!");
break;
}
} while (choose != 4);
}
static void Menu() {
System.out.println("1.Add new customer");
System.out.println("2.Find by name");
System.out.println("3.Display All");
System.out.println("4.Exit");
System.out.println("Choose: ");
}
private static void addCustomer() {
Scanner scan = new Scanner(System.in);
System.out.println("Nhap so luong khach hang muon nhap: ");
int num = Integer.parseInt(scan.nextLine());
for (int i = 0; i < num; i++) {
Customer cus = new Customer();
cus.input();
customerList.put(cus.getName(), cus);
}
}
private static void findByName() {
Scanner scan = new Scanner(System.in);
System.out.println("Nhap ten khach hang muon tim: ");
String findName = scan.nextLine();
for (String i : customerList.keySet()) {
if (i.equalsIgnoreCase(findName)) {
System.out.println(customerList.get(i));
}
}
}
private static void displayAll() {
for(Object i : customerList.values()){
System.out.println(i);
}
}
private static void Exit() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
}
![Trần Văn Lâm [T2008A]](https://www.gravatar.com/avatar/cfc15c8cb7781ad669b013e01f9f1a6b.jpg?s=80&d=mm&r=g)
Trần Văn Lâm
2021-03-24 16:56:16
#Customer.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.test.CustomerRelationship;
import java.util.Scanner;
/**
*
* @author Administrator
*/
public class Customer {
String name,email,phone;
public Customer() {
}
public Customer(String name, String email, String phone) {
this.name = name;
this.email = email;
this.phone = phone;
}
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 getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public void input(){
System.out.println("Nhap thong tin Sinh Vien:");
Scanner scan = new Scanner(System.in);
System.out.println("Nhap ten:");
name = scan.nextLine();
System.out.println("Nhap email:");
email = scan.nextLine();
System.out.println("Nhap sdt:");
phone = scan.nextLine();
}
public void display(){
System.out.println(this);
}
@Override
public String toString() {
return "Customer{" + "name=" + name + ", email=" + email + ", phone=" + phone + '}';
}
}
#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.test.CustomerRelationship;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
/**
*
* @author Administrator
*/
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
Map<String, Customer> map = new HashMap<>();
int choose;
do{
showMenu();
choose = Integer.parseInt(scan.nextLine());
switch(choose){
case 1:
System.out.println("Input number customer:");
int select = Integer.parseInt(scan.nextLine());
for (int i = 0; i < select; i++) {
Customer customer = new Customer();
customer.input();
map.put(customer.name, customer);
}
break;
case 2:
break;
case 3:
map.entrySet().forEach((entry) -> {
System.out.println(entry);
});
break;
case 4:
System.out.println("Exit!!!");
break;
default:
System.out.println("Nhap sai!!!");
break;
}
}while(choose !=4);
}
static void showMenu(){
System.out.println("1. Add new customer");
System.out.println("2. Find by name");
System.out.println("3. Display all");
System.out.println("4.Exit");
}
}
![Triệu Văn Lăng [T2008A]](https://www.gravatar.com/avatar/1348e3562c6492c26f796cb1f45982a1.jpg?s=80&d=mm&r=g)
Triệu Văn Lăng
2021-03-24 10:16: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 baithi1174;
import java.util.Scanner;
/**
*
* @author MTLS
*/
public class Customer {
String name, email, phone;
public Customer() {
}
public Customer(String name, String email, String phone) {
this.name = name;
this.email = email;
this.phone = phone;
}
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 getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
@Override
public String toString() {
return "Customer{" + "name=" + name + ", phone=" + phone + '}';
}
public void input() {
Scanner sc = new Scanner(System.in);
System.out.println("Input name: ");
name = sc.nextLine();
System.out.println("Input Email: ");
email = sc.nextLine();
System.out.println("Input Phone Number: ");
phone = sc.nextLine();
}
public void display() {
System.out.println(this);
}
}
![Triệu Văn Lăng [T2008A]](https://www.gravatar.com/avatar/1348e3562c6492c26f796cb1f45982a1.jpg?s=80&d=mm&r=g)
Triệu Văn Lăng
2021-03-24 10:16:18
/*
* 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 baithi1174;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
/**
*
* @author MTLS
*/
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
Map<String, Customer> ctmMap = new HashMap<>();
int choose;
do {
showMenu();
choose = Integer.parseInt(sc.nextLine());
switch(choose) {
case 1:
int n;
System.out.println("Input N customer: ");
n = Integer.parseInt(sc.nextLine());
for (int i = 0; i < n; i++) {
Customer ctm = new Customer();
ctm.input();
ctmMap.put(ctm.getName(), ctm);
}
break;
case 2:
System.out.println("Enter the name you want to find: ");
String nameFind = sc.nextLine();
for (Map.Entry<String, Customer> entry : ctmMap.entrySet()) {
if(entry.getKey().equalsIgnoreCase(nameFind)) {
System.out.println(entry);
} else {
System.out.println("The name is not found");
}
}
break;
case 3:
System.out.println("Information Customer: ");
for (Map.Entry<String, Customer> entry : ctmMap.entrySet()) {
String key = entry.getKey();
Customer value = entry.getValue();
value.display();
}
break;
case 4:
System.out.println("exit");
break;
default:
System.out.println("retype");
break;
}
} while(choose != 4);
}
private static void showMenu() {
System.out.println("1. Add new customer");
System.out.println("2. Find by name");
System.out.println("3. Display all");
System.out.println("4. Exit");
System.out.println("Choose: ");
}
}