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)
![Đường Thanh Bình [T1907A]](https://www.gravatar.com/avatar/c2ef7c316acb82467912bf5677b52a8b.jpg?s=80&d=mm&r=g)
Đường Thanh Bình
2020-04-10 08:58:06
/*
* 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 KiemtraJava;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
/**
*
* @author Administrator
*/
public class Main {
public static void main(String[] args) {
Map<String, Customer> customerHashMap = new HashMap<>();
Scanner input = new Scanner(System.in);
int choose;
do {
showMenu();
choose = Integer.parseInt(input.nextLine());
switch (choose) {
case 1 :
System.out.println("N : ");
int n = Integer.parseInt(input.nextLine());
for (int i = 0; i < n; i++) {
Customer cus = new Customer();
cus.input();
customerHashMap.put(cus.getName(), cus);
}
break;
case 2:
System.out.println("Enter the name to search");
String name = input.nextLine();
Customer customerFind = customerHashMap.get(name);
customerFind.display();
break;
case 3 :
System.out.println("Thong tin sinh vien");
for (Map.Entry<String, Customer> entry : customerHashMap.entrySet()) {
Customer value = entry.getValue();
value.display();
}
break;
case 4 :
System.out.println("Exit");
break;
default :
System.out.println("Error!!");
break;
}
} while (choose != 4);
}
static void showMenu() {
System.out.println("Menu (Choose)");
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 : ");
}
}
/*
* 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 KiemtraJava;
import java.util.Scanner;
/**
*
* @author Administrator
*/
public class Customer {
String name, email;
int phone;
public Customer() {
}
public Customer(String name, String email, int 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 int getPhone() {
return phone;
}
public void setPhone(int phone) {
this.phone = phone;
}
public void input(){
Scanner scan = new Scanner(System.in);
System.out.println("Enter Name: ");
name = scan.nextLine();
System.out.println("Enter Email: ");
email = scan.nextLine();
System.out.println("Enter Phone: ");
phone = Integer.parseInt(scan.nextLine());
}
public void display(){
System.out.println(toString());
}
@Override
public String toString() {
return "Customer{" + "name=" + name + ", email=" + email + ", phone=" + phone + '}';
}
}
![Trần Anh Quân [T1907A]](https://www.gravatar.com/avatar/7e3a8fe30cedd711f426fc59a9d48efc.jpg?s=80&d=mm&r=g)
Trần Anh Quân
2020-04-10 08:57:26
package ADF2;
import java.util.HashMap;
import java.util.Scanner;
/**
*
* @author Anh Quan
*/
public class Main {
public static void main(String[] args) {
HashMap<Customer, String> Customer = new HashMap<>();
Scanner scan = new Scanner(System.in);
int choice;
do {
showMenu();
choice = Integer.parseInt(scan.nextLine());
switch (choice) {
case 1:
Customer customer = new Customer();
customer.input();
Customer.put(customer, customer.getName());
break;
case 2:
System.out.println("Enter name :");
String name ;
name = scan.nextLine();
Customer.keySet().forEach((W) -> {
if(W.getName().equalsIgnoreCase(name))
{
W.display();
}
else
{
System.out.println("N/A!");
}
});
break;
case 3:
Customer.keySet().forEach((W) -> {
W.display();
});
break;
case 4:
System.out.println("Exit.");
break;
default:
System.out.println("!!!YOU PICK THE WRONG HOUSE FOOL!!!");
break;
}
} while (choice != 4);
}
public static void showMenu() {
System.out.println("Menu :");
System.out.println("1. Add a customer.");
System.out.println("2. Find by name.");
System.out.println("3. Display all.");
System.out.println("4. Exit.");
}
}
package ADF2;
import java.util.Scanner;
/**
*
* @author Anh Quan
*/
public class Customer {
String name, email, phone_Number;
public Customer() {
}
public Customer(String name, String email, String phonenumer) {
this.name = name;
this.email = email;
this.phone_Number = phone_Number;
}
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 phone_Number;
}
public void setPhonenumber(String phonenumer) {
this.phone_Number = phonenumer;
}
public void input() {
Scanner scan = new Scanner(System.in);
System.out.println("Enter name: ");
name = scan.nextLine();
System.out.println("Enter email: ");
email = scan.nextLine();
System.out.println("Enter phone number: ");
phone_Number = scan.nextLine();
}
public void display() {
System.out.println(toString());
}
@Override
public String toString() {
return "Customer{" + "name = " + name + ", email = " + email + ", phonenumber = " + phone_Number + '}';
}
}
![Đỗ Văn Huấn [T1907A]](https://www.gravatar.com/avatar/04c40301dd027839d265b3c3c9dc6e6b.jpg?s=80&d=mm&r=g)
Đỗ Văn Huấn
2020-04-10 08:57:04
package java2_Advanced.KiemTra_Java2;
import java.util.Scanner;
public class Customer {
String name, email;
int phone;
public Customer() {
}
public Customer(String name, String email, int 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 int getPhone() {
return phone;
}
public void setPhone(int phone) {
this.phone = phone;
}
public void input() {
Scanner scan = new Scanner(System.in);
System.out.println("Enter name: ");
name = scan.nextLine();
System.out.println("Enter email: ");
email = scan.nextLine();
System.out.println("Enter phone: ");
phone = Integer.parseInt(scan.nextLine());
}
public void display() {
System.out.println("Name: " + name);
System.out.println("Email: " + email);
System.out.println("Phone: " + phone);
System.out.println("");
}
}
package java2_Advanced.KiemTra_Java2;
import java.util.HashMap;
import java.util.Scanner;
public class CustomerRelationshipManagement {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
HashMap<String, Customer> ma = new HashMap<>();
int choose;
do {
showMenu();
System.out.println("Enter choose: ");
choose = Integer.parseInt(scan.nextLine());
switch (choose) {
case 1:
Customer cus = new Customer();
cus.input();
ma.put(cus.getName(), cus);
break;
case 2:
System.out.println("Enter the name to search: ");
String name = scan.nextLine();
for (String s : ma.keySet()) {
if (ma.get(s).name.equalsIgnoreCase(name)) {
ma.get(name).display();
} else {
System.out.println("No customer found");
}
}
break;
case 3:
for (String s : ma.keySet()) {
Customer customer = ma.get(s);
customer.display();
}
break;
case 4:
System.out.println("Exit");
break;
default:
System.err.println("error");
break;
}
} while (choose != 4);
}
public 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");
}
}
![Lê Minh Bắc [T1907A]](https://www.gravatar.com/avatar/22abcac77d8ca5e01144e240abb48d22.jpg?s=80&d=mm&r=g)
Lê Minh Bắc
2020-04-10 08:56:52
Customer:
/*
* 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 ThiJava2;
import java.util.Scanner;
/**
*
* @author lemin
*/
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(){
Scanner input = new Scanner(System.in);
System.out.print("Nhập tên:");
name = input.nextLine();
System.out.print("Nhập Email:");
email = input.nextLine();
System.out.print("Nhập Phone:");
phone = input.nextLine();
}
public void display() {
System.out.println("Tên: " + name);
System.out.println("Email: " + email);
System.out.println("Phone: " + phone);
System.out.println("======================");
}
}
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 ThiJava2;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
/**
*
* @author lemin
*/
public class Main {
public static void main(String[] args) {
Map<String, Customer> cusHashMap = new HashMap<>();
Scanner input = new Scanner(System.in);
int choose;
do {
showMenu();
choose = Integer.parseInt(input.nextLine());
switch(choose) {
case 1:
System.out.println("How many customers you want to add?: ");
int n = Integer.parseInt(input.nextLine());
for (int i = 0; i < n; i++) {
Customer cus = new Customer();
cus.input();
cusHashMap.put(cus.getName(), cus);
}
break;
case 2:
System.out.println("Insert name by search: ");
String name = input.nextLine();
cusHashMap.keySet().forEach((str) -> {
if(cusHashMap.get(str).name.equalsIgnoreCase(name)) {
cusHashMap.get(str).display();
} else {
System.out.println("Not found!");
}
});
break;
case 3:
System.out.println("Display All:");
cusHashMap.keySet().stream().map((str) -> cusHashMap.get(str)).forEachOrdered((cus) -> {
cus.display();
});
break;
case 4:
System.out.println("Exit!!!");
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");
System.out.print("Choose: ");
}
}
![Minh Nghia [T1907A]](https://www.gravatar.com/avatar/ecca255d725eed36a872105205af1b8e.jpg?s=80&d=mm&r=g)
Minh Nghia
2020-04-10 08:54:31
/*
* 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 java2EX;
import java.util.Scanner;
/**
*
* @author Administrator
*/
public class customer {
String name, email;
int phone;
public customer() {
}
public customer(String name, String email, int 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 int getPhone() {
return phone;
}
public void setPhone(int phone) {
this.phone = phone;
}
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 :");
phone = Integer.parseInt(scan.nextLine());
}
public void display(){
System.out.println(toString());
}
@Override
public String toString() {
return "customer{" + "name=" + name + ", email=" + email + ", phone=" + phone + '}';
}
}
/*
* 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 java2EX;
import java.util.HashMap;
import java.util.Scanner;
/**
*
* @author Administrator
*/
public class main {
public static void main(String[] args) {
HashMap<String, customer> hashMap = new HashMap();
Scanner scan = new Scanner(System.in);
int choose, n;
do{
showMenu();
choose = Integer.parseInt(scan.nextLine());
switch(choose){
case 1:
System.out.println("Add new customer");
customer cus = new customer();
cus.input();
hashMap.put(cus.getName(),cus);
break;
case 2:
System.out.println("Find by name");
String name = scan.nextLine();
for (String str : hashMap.keySet()) {
if(hashMap.get(str).name.equalsIgnoreCase(name)){
hashMap.get(str).display();
}
}
break;
case 3:
System.out.println("Display all");
for (String str : hashMap.keySet()) {
customer cuss = hashMap.get(str);
cuss.display();
}
break;
case 4:
System.out.println("Exit!!!");
break;
default:
System.out.println("Input fail!!!");
break;
}
}while(choose != 4);
}
public 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 :");
}
}
![Phan Bạch Tùng Dương [T1907A]](https://www.gravatar.com/avatar/e74e3ec62fe3a191929e12eecbe01edf.jpg?s=80&d=mm&r=g)
Phan Bạch Tùng Dương
2020-04-10 08:53:51
/*
* 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 ExamII;
import java.util.HashMap;
import java.util.Scanner;
/**
*
* @author Admin
*/
public class Main {
public static void main(String[] args) {
HashMap<Customer, String> Customer = new HashMap<>();
Scanner scan = new Scanner(System.in);
int choice;
do {
showMenu();
choice = Integer.parseInt(scan.nextLine());
switch (choice) {
case 1:
Customer customer = new Customer();
customer.input();
Customer.put(customer, customer.getName());
break;
case 2:
System.out.println("Enter name :");
String name ;
name = scan.nextLine();
Customer.keySet().forEach((W) -> {
if(W.getName().equalsIgnoreCase(name))
{
W.display();
}
else
{
System.out.println("N/A!");
}
});
break;
case 3:
Customer.keySet().forEach((W) -> {
W.display();
});
break;
case 4:
System.out.println("Exit.");
break;
default:
System.out.println("!!!YOU PICK THE WRONG HOUSE FOOL!!!");
break;
}
} while (choice != 4);
}
public static void showMenu() {
System.out.println("Menu :");
System.out.println("1. Add a customer.");
System.out.println("2. Find by name.");
System.out.println("3. Display all.");
System.out.println("4. Exit.");
}
}
Customer:
/*
* 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 ExamII;
import java.util.Scanner;
/**
*
* @author Admin
*/
public class Customer {
String name, email, phone_Number;
public Customer() {
}
public Customer(String name, String email, String phonenumer) {
this.name = name;
this.email = email;
this.phone_Number = phone_Number;
}
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 phone_Number;
}
public void setPhonenumber(String phonenumer) {
this.phone_Number = phonenumer;
}
public void input() {
Scanner scan = new Scanner(System.in);
System.out.println("Enter name: ");
name = scan.nextLine();
System.out.println("Enter email: ");
email = scan.nextLine();
System.out.println("Enter phone number: ");
phone_Number = scan.nextLine();
}
public void display() {
System.out.println(toString());
}
@Override
public String toString() {
return "Customer{" + "name = " + name + ", email = " + email + ", phonenumber = " + phone_Number + '}';
}
}
![nguyễn văn huy [T1907A]](https://www.gravatar.com/avatar/b107d14d7d43c142b68c12c377262371.jpg?s=80&d=mm&r=g)
nguyễn văn huy
2020-04-10 08:51:42
/*
* 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 QLkhachhang;
import java.util.*;
/**
*
* @author ASUS
*/
public class Main {
public static void main(String[] args) {
HashMap<String,khachhang> khackMap=new HashMap<>();
khachhang hangt=new khachhang();
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 khach hang");
for (int i = 0; i < 10; i++) {
khachhang thao = new khachhang();
thao.input();
khackMap.put(thao.getName(), thao);
}
break;
case 2:
System.out.println("nhap sdt kh can tim:");
int phone=Integer.parseInt(scan.nextLine());
if(phone==hangt.getPhone()){
khachhang thaobeou = khackMap.get(phone);
thaobeou.display();
} else{
System.out.println("so dien thoai ko phu hop>>..");
}
break;
case 3:
System.out.println("thong tin khach hang");
for (Map.Entry<String,khachhang> entry:khackMap.entrySet()) {
khachhang hang=entry.getValue();
hang.display();
}
break;
case 4:
System.out.println("Exit>>>");
break;
default:
break;
}
} while (choise!=4);
}
static void menu(){
System.out.println("1.them khach hang:");
System.out.println("2.tim theo ten");
System.out.println("3.hien thi tat ca");
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 QLkhachhang;
import java.util.Scanner;
/**
*
* @author ASUS
*/
public class khachhang {
String name,email;
int phone;
public khachhang() {
}
public khachhang(String name, String email, int phone) {
this.name = name;
this.email = email;
this.phone = phone;
}
public void display(){
System.out.println(toString());
}
@Override
public String toString() {
return "Main{" + "name=" + name + ", email=" + email + ", phone=" + phone + '}';
}
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");
phone=Integer.parseInt(scan.nextLine());
}
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 getPhone() {
return phone;
}
public void setPhone(int phone) {
this.phone = phone;
}
}
![Trần Ngọc Hải [T1907A]](https://www.gravatar.com/avatar/9f7a27af52cbf0d52c32019e1354d60a.jpg?s=80&d=mm&r=g)
Trần Ngọc Hải
2020-04-10 08:51:25
/*
* 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 H.exam;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
/**
*
* @author HAI
*/
public class main {
public static void main(String[] args) {
Map<String, customer> cusHashMap = new HashMap<>();
Scanner scan = new Scanner(System.in);
int c;
do {
menu();
c= Integer.parseInt(scan.nextLine());
switch(c){
case 1:
System.out.println("Nhap ten khach hang can tim kiem: ");
String fullname = scan.nextLine();
for (Map.Entry<String, customer> entry : cusHashMap.entrySet()) {
customer cusFind = cusHashMap.get(fullname);
cusFind.display();
}
break;
case 2:
System.out.println("Thong tin khach hang");
for (Map.Entry<String, customer> entry : cusHashMap.entrySet()) {
customer value = entry.getValue();
value.display();
}
break;
case 3:
System.out.println("Nhap N: ");
int n = Integer.parseInt(scan.nextLine());
for (int i = 0; i < n; i++) {
customer cus = new customer();
cus.input();
cusHashMap.put(cus.getName(), cus);
}
break;
case 4:
default:
break;
}
} while (c!=4);
}
public static void menu(){
System.out.println("1.Search Customer.");
System.out.println("2.Show all Customer.");
System.out.println("3.Add Customer.");
System.out.println("4.end.");
System.out.println("Choose : ");
}
}
/*
* 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 H.exam;
import java.util.Scanner;
/**
*
* @author HAI
*/
public class customer {
String name , email ;
long phone;
public customer() {
}
public customer(String name, String email, long 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 long getPhone() {
return phone;
}
public void setPhone(long phone) {
this.phone = phone;
}
public void input(){
Scanner scan = new Scanner(System.in);
System.out.println("enter name : ");
name = scan.nextLine();
while (true) {
System.out.println("enter email : ");
email= scan.nextLine();
if (email.contains("@") && !email.contains(" ")) {
break;
}else{
System.err.println("email --> '@' && !''");
}
}
System.out.println("enter Phone number : ");
phone = Long.parseLong(scan.nextLine());
}
public void display(){
System.out.println("Customer's name : "+name);
System.out.println("Customer's Email : "+email);
System.out.println("Customer's Telephone Number : "+phone);
}
}
![Phí Văn Long [T1907A]](https://www.gravatar.com/avatar/5db166b7b74443c5c221e4c0068d6da9.jpg?s=80&d=mm&r=g)
Phí Văn Long
2020-04-10 08:49:28
/*
* 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 BaiThiThucHanh;
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, Customer> customerHashMap = new HashMap<>();
Scanner input = new Scanner(System.in);
int choose;
do {
showMenu();
choose = Integer.parseInt(input.nextLine());
switch (choose) {
case 1 :
System.out.println("N : ");
int n = Integer.parseInt(input.nextLine());
for (int i = 0; i < n; i++) {
Customer cus = new Customer();
cus.input();
customerHashMap.put(cus.getName(), cus);
}
break;
case 2:
System.out.println("Enter the name to search");
String name = input.nextLine();
Customer cusFind = customerHashMap.get(name);
cusFind.display();
break;
case 3 :
System.out.println("Thong tin sinh vien");
for (Map.Entry<String, Customer> entry : customerHashMap.entrySet()) {
Customer value = entry.getValue();
value.display();
}
break;
case 4 :
System.out.println("Exittt");
break;
default :
System.out.println("Error!!!");
break;
}
} while (choose != 4);
}
static void showMenu() {
System.out.println("Menu (Choose)");
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 : ");
}
}
/*
* 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 BaiThiThucHanh;
import java.util.Scanner;
/**
*
* @author Admin
*/
public class Customer {
String name , email;
int number;
public Customer() {
}
public Customer(String name, String email, int number) {
this.name = name;
this.email = email;
this.number = number;
}
public void input (){
Scanner scan = new Scanner(System.in);
System.out.println("Add Name : ");
name = scan.nextLine();
System.out.println("Add Email : ");
email = scan.nextLine();
System.out.println("Add Phone Number :");
number = Integer.parseInt(scan.nextLine());
}
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 getNumber() {
return number;
}
public void setNumber(int number) {
this.number = number;
}
@Override
public String toString() {
return "Customer{" + "name=" + name + ", email=" + email + ", number=" + number + '}';
}
public void display(){
System.out.println(toString());
//System.out.println("this");
}
}
![Trần Mạnh Dũng [T1907A]](https://www.gravatar.com/avatar/ee4661d1f9133c241d6c8287c7ea8ceb.jpg?s=80&d=mm&r=g)
Trần Mạnh Dũng
2020-04-10 08:49:11
/*
* 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 examination_java2;
import java.util.HashMap;
import java.util.Scanner;
/**
*
* @author admin
*/
public class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int c;
HashMap<Customer,String> Customer = new HashMap<Customer,String>();
do {
ShowMenu();
c = Integer.parseInt(input.nextLine());
switch(c){
case 1:
Customer cus = new Customer();
cus.input();
Customer.put(cus, cus.getName());
break;
case 2:
System.out.println("Search a name:");
String Name = input.nextLine();
for (Customer i : Customer.keySet()) {
if (i.getName().equalsIgnoreCase(Name))
i.output();
}
break;
case 3:
for (Customer i : Customer.keySet()) {
i.output();
}
break;
case 4:
System.out.println("Exit!");
break;
default:
System.err.println("ERROR!");
}
}while(c != 4);
}
public static void ShowMenu(){
System.out.println("=====================");
System.out.println("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.print("Enter: ");
}
}
/*
* 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 examination_java2;
import java.util.Scanner;
/**
*
* @author admin
*/
public class Customer {
String Name, Email;
int Phone;
public Customer() {
}
public Customer(String Name, String Email, int 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 int getPhone() {
return Phone;
}
public void setPhone(int Phone) {
this.Phone = Phone;
}
@Override
public String toString() {
return "Customer{" + "Name=" + Name + ", Email=" + Email + ", Phone=" + Phone + '}';
}
public void input(){
Scanner input = new Scanner(System.in);
System.out.println("------------------");
System.out.println("Enter a name:");
Name = input.nextLine();
System.out.println("Enter a phone:");
Phone = Integer.parseInt(input.nextLine());
System.out.println("Enter a email:");
Email = input.nextLine();
}
public void output(){
System.out.println(toString());
}
}