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



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

5

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

Trương Công Vinh [T1907A]
Trương Công Vinh

2020-04-10 08:44:45



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

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

/**
 *
 * @author DELL
 */
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 exam;

import java.util.Scanner;

/**
 *
 * @author DELL
 */
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);
    }
    
}



thienphu [T1907A]
thienphu

2020-04-10 08:38: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 Thi.ThienPhu;

import java.util.Scanner;

/**
 *
 * @author Thien Phu
 */
public class Person {

    String name;
    String email;
    String phone;

    public Person() {
    }

    public Person(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 name + " \t" + phone + " \t" + email;
    }

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

    public void input() {
        System.out.println("Nhap thong tin :");
        Scanner sc = new Scanner(System.in);
        System.out.println("Nhap ten: ");
        name = sc.nextLine();
        System.out.println("Nhap email:");
        email = sc.nextLine();
        System.out.println("Nhap phone: ");
        phone = sc.nextLine();
    }
}



/*
 * 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 Thi.ThienPhu;

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

/**
 *
 * @author Thien Phu
 */
public class ManagePerson {

    Map<String, Person> map = new HashMap<String, Person>();
    private static Scanner sc = new Scanner(System.in);

    public ManagePerson() {
    }

    public void addPerson() {
        while (true) {
            Person ps = new Person();
            ps.input();
            map.put(ps.getName(), ps);
            System.out.println("Ban co muon tiep tuc khong");
            System.out.println("Y");
            System.out.println("N");
            String choose = sc.nextLine();
            if (choose.equalsIgnoreCase("N")) {
                break;
            }
        }
    }

    public void display() {
        System.out.println("Name \t Phone");
        for (String key : map.keySet()) {
            Person value = map.get(key);
            System.out.println(value);
        }
    }

    public void findPerson() {
        boolean check = false;
        Person person = new Person();
        System.out.println("Nhap ten Person can tim");
        String find = sc.nextLine();
        for (String key : map.keySet()) {
            Person value = map.get(key);
            if (value.getName().equalsIgnoreCase(find)) {
                check = true;
                person = value;
                break;
            }
        }
        if (check) {
            person.display();
        } else {
            System.out.println("Khong tim thay Person co ten: " + find);
        }
    }
}



/*
 * 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 Thi.ThienPhu;

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

/**
 *
 * @author Thien Phu
 */
public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        ManagePerson managePerson = new ManagePerson();
        int choose;
        do {
            showmenu();
            choose = Integer.parseInt(sc.nextLine());
            switch (choose) {
                case 1:
                    managePerson.addPerson();
                    break;
                case 2:
                    managePerson.findPerson();
                    break;
                case 3:
                    managePerson.display();
                    break;
                case 4:
                    System.out.println("Exit thanh cong");
                    break;
                default:
                    System.out.println("Chon lai di");
                    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");
    }

}



NguyenHuuThanh [T1907A]
NguyenHuuThanh

2020-04-10 08:24:50



Em nộp lại ạ 
/*
 * 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 test02;

import java.util.Scanner;

/**
 *
 * @author abc
 */
public class Customer {
    String name , email , phonenumber;
    
    public Customer()
    {
        
    }

    public Customer(String name, String email, String phonenumer) {
        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 phonenumer) {
        this.phonenumber = phonenumer;
    }
    
    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 phonenumber :");
        phonenumber = scan.nextLine();
    }
    
    public void display()
    {
        System.out.println(toString());
    }

    @Override
    public String toString() {
        return "Customer{" + "name=" + name + ", email=" + email + ", phonenumber=" + phonenumber + '}';
    }
    public void display1()
    {
        System.out.println("Name : " + name);
        System.out.println("Phonenumber :" + phonenumber);
    }
}
/*
 * 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 test02;

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

/**
 *
 * @author abc
 */
public class CustomerRelationship {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        HashMap<Customer,String> Customer = new HashMap<Customer,String>();
        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("Nhap ten can tim :");
                    String name ;
                    name = scan.nextLine();
                    
                    for ( Customer i : Customer.keySet())
                    {
                        if(i.getName().equalsIgnoreCase(name))
                        {
                            i.display();
                        }
                        else 
                        {
                            System.out.println(" Not Found ");
                        }
                    }
                    break;
                
                case 3 : 
                    for( Customer i : Customer.keySet())
                    {
                        i.display1();
                    }
                    break;
                    
                case 4 :
                    System.out.println("Exit");
                    break;
                default :
                    System.out.println("Error");
                    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");
    }
}



NguyenHuuThanh [T1907A]
NguyenHuuThanh

2020-04-10 08:15: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 test02;

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

/**
 *
 * @author abc
 */
public class CustomerRelationship {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        HashMap<Customer,String> Customer = new HashMap<Customer,String>();
        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("Nhap ten can tim :");
                    String name ;
                    name = scan.nextLine();
                    
                    for ( Customer i : Customer.keySet())
                    {
                        if(i.getName().equalsIgnoreCase(name))
                        {
                            i.display();
                        }
                    }
                    break;
                
                case 3 : 
                    for( Customer i : Customer.keySet())
                    {
                        i.display();
                    }
                    break;
                    
                case 4 :
                    System.out.println("Exit");
                    break;
                default :
                    System.out.println("Error");
                    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");
    }
}
/*
 * 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 test02;

import java.util.Scanner;

/**
 *
 * @author abc
 */
public class Customer {
    String name , email , phonenumber;
    
    public Customer()
    {
        
    }

    public Customer(String name, String email, String phonenumer) {
        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 phonenumer) {
        this.phonenumber = phonenumer;
    }
    
    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 phonenumber :");
        phonenumber = scan.nextLine();
    }
    
    public void display()
    {
        System.out.println(toString());
    }

    @Override
    public String toString() {
        return "Customer{" + "name=" + name + ", email=" + email + ", phonenumber=" + phonenumber + '}';
    }
    
}



Đăng nhập để làm bài kiểm tra

Chưa có kết quả nào trước đó