bai tap
package com.Main;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Scanner;
public class FormMain {
/**
* @param args
*/
static ArrayList<Employee> lstEmployee;
public static void main(String[] args) {
// TODO Auto-generated method stub
//nhap
Scanner can=new Scanner(new InputStreamReader(System.in));
System.out.println("Menu");
System.out.println("Nhap n nhap");
System.out.println("Nhap x de xuat");
System.out.println("Nhap t tim kiem");
System.out.println("Nhap m de tinh max");
System.out.println("Nhap e de thoat");
String key=can.nextLine();
switch (key) {
case "n":
addds();
break;
case "x":
showds();
break;
case "t":
Search();
break;
case "m":
maxsalary();
break;
case "e":
break;
}
// xuat
//tim kiem
//max
}
public static void addds()
{
lstEmployee=new ArrayList<Employee>();
Scanner can=new Scanner(new InputStreamReader(System.in));
int coutEmployee;
System.out.println("Nhap so luong nhan vien:");
coutEmployee=can.nextInt();
for (int i = 0; i < coutEmployee; i++) {
System.out.println("Nhan vien thu :"+(i+1));
Employee em=new Employee();
em.nhap();
lstEmployee.add(em);
}
// System.out.println("Danh sach nhan vien la:");
// for (Employee em : lstEmployee) {
// em.show();
// }
}
public static void showds()
{
System.out.println("Danh sach nhan vien la:");
for (Employee em : lstEmployee) {
em.show();
}
}
public static void Search()
{
Scanner can=new Scanner(new InputStreamReader(System.in));
System.out.println("Tim kiem nhan vien theo ma:");
String idEmployee;
System.out.print("Nhap ma nhan vien can tim kiem:");
idEmployee=can.nextLine();
for (Employee ek : lstEmployee) {
if(ek.getIdEmployee().equals(idEmployee))
{
System.out.print(" nhan vien co ma la:"+idEmployee);
ek.show();
}
}
}
public static void maxsalary()
{
Double maxsl=lstEmployee.get(0).getSalaryEmployee();
for (int i = 1; i < lstEmployee.size(); i++) {
if(maxsl<lstEmployee.get(i).getSalaryEmployee())
{
maxsl=lstEmployee.get(i).getSalaryEmployee();
}
}
System.out.println("Gia tri max cua mang la:");
for (Employee ek : lstEmployee) {
if(ek.getSalaryEmployee()==maxsl)
{
ek.show();
}
}
}
}
package com.Main;
import java.io.InputStreamReader;
import java.util.Scanner;
public class Employee {
String idEmployee;
String nameEmployee;
String mobileEmployee;
Double salaryEmployee;
public Double getSalaryEmployee() {
return salaryEmployee;
}
public void setSalaryEmployee(Double salaryEmployee) {
this.salaryEmployee = salaryEmployee;
}
public String getIdEmployee() {
return idEmployee;
}
public void setIdEmployee(String idEmployee) {
this.idEmployee = idEmployee;
}
public String getNameEmployee() {
return nameEmployee;
}
public void setNameEmployee(String nameEmployee) {
this.nameEmployee = nameEmployee;
}
public String getMobileEmployee() {
return mobileEmployee;
}
public void setMobileEmployee(String mobileEmployee) {
this.mobileEmployee = mobileEmployee;
}
public Employee(String idEmployee, String nameEmployee, String mobileEmployee) {
super();
this.idEmployee = idEmployee;
this.nameEmployee = nameEmployee;
this.mobileEmployee = mobileEmployee;
}
public Employee() {
super();
}
public void nhap()
{
Scanner can=new Scanner(new InputStreamReader(System.in));
System.out.println("Nhap id:");
idEmployee=can.nextLine();
System.out.println("Nhap Name:");
nameEmployee=can.nextLine();
System.out.println("Nhap Mobile:");
mobileEmployee=can.nextLine();
System.out.println("Nhap Luong:");
salaryEmployee=can.nextDouble();
}
public void show()
{
System.out.println(idEmployee+"\t"+nameEmployee+"\t"+mobileEmployee+"\t"+salaryEmployee);
}
}
2013/11/22 Dương Văn Khoát <webboyk@gmail.com>
interfacepackage com.myinterface;public interface ISharp {//dien tichDouble getArea();//chu viDouble getPermeter();}package com.myinterface;public class Square implements ISharp {@Overridepublic Double getArea() {// TODO Auto-generated method stubreturn Double.parseDouble("400");}@Overridepublic Double getPermeter() {// TODO Auto-generated method stubreturn Double.parseDouble("400");}}2013/11/22 Dương Văn Khoát <webboyk@gmail.com>
truu tuongpackage com.abstraction;public abstract class Shape {//dien tichpublic abstract Double getArea();//chu vipublic abstract Double getPermeter();public void displaySharpCategory(){System.out.println("These : Circlse,");}}package com.abstraction;public class Ractangle extends Shape {@Overridepublic Double getArea() {// TODO Auto-generated method stubreturn Double.parseDouble("4000");}@Overridepublic Double getPermeter() {// TODO Auto-generated method stubreturn Double.parseDouble("400");}}package com.abstraction;public class Circle extends Shape {@Overridepublic Double getArea() {// TODO Auto-generated method stubreturn Double.valueOf("1000");}@Overridepublic Double getPermeter() {// TODO Auto-generated method stubreturn Double.valueOf("100");}}Circle cl=new Circle();// System.out.println("Dieen tich la:"+cl.getArea());// //c2// Shape sh=new Circle();// System.out.println("Dien tich laf :"+sh.getArea());//// //c3// sh=new Ractangle();// System.out.println("Dien tich laf :"+sh.getArea());// sh.displaySharpCategory();2013/11/20 Vu Tung Lam <vutunglampro@gmail.com>
package com.puple;public class Emloyyee {String name;public String getName() {return name;}public void setName(String name) {this.name = name;}public String getMobile() {return mobile;}public void setMobile(String mobile) {this.mobile = mobile;}String mobile;public Emloyyee(String name, String mobile) {public Emloyyee() {super();}}package com.puple;public class Course {String idCourse;String nameCourse;public String getIdCourse() {return idCourse;}public void setIdCourse(String idCourse) {this.idCourse = idCourse;}public String getNameCourse() {return nameCourse;}public void setNameCourse(String nameCourse) {this.nameCourse = nameCourse;}public Course(String idCourse, String nameCourse) {super();this.idCourse = idCourse;this.nameCourse = nameCourse;}public Course() {super();}}package com.main;import java.util.ArrayList;import java.util.LinkedList;import java.util.ListIterator;import javax.swing.plaf.SliderUI;import com.puple.Course;import com.puple.Emloyyee;public class FormMain {/*** @param args*/public static void main(String[] args) {// TODO Auto-generated method stubThread newThr1=new Thread(doCourse);newThr1.start();Thread newThr2=new Thread(doEmloyyee);newThr2.start();}private static Runnable doEmloyyee=new Runnable() {@Overridepublic void run() {// TODO Auto-generated method stubtry {Thread.sleep(3000);} catch (InterruptedException e) {// TODO Auto-generated catch blocke.printStackTrace();}ArrayList<Emloyyee> listEmloyee=new ArrayList<Emloyyee>();listEmloyee.add(new Emloyyee("khoat", "012344"));listEmloyee.add(new Emloyyee("Huy", "0124434"));listEmloyee.add(new Emloyyee("Duong", "63636535"));listEmloyee.add(new Emloyyee("khuyen", "3242424"));listEmloyee.add(new Emloyyee("Tuan", "45325454"));System.out.println("Danh sach sinh vien la");int d=1;for (Emloyyee em : listEmloyee) {System.out.print(em.getName()+"\t");System.out.println("So dien thoai nhan vien la "+d+" :"+em.getMobile());}}};private static Runnable doCourse=new Runnable() {@Overridepublic void run() {// TODO Auto-generated method stubArrayList<Course> listCourse=new ArrayList<Course>();listCourse.add(new Course("id01", "tk72"));listCourse.add(new Course("id02", "tk71"));listCourse.add(new Course("id03", "tk73"));listCourse.add(new Course("id04", "tk74"));listCourse.add(new Course("id05", "tk75"));System.out.println("Danh sach lop hoc la:");int d=1;for (Course em : listCourse) {System.out.print("Ma id :"+em.getIdCourse()+"\t");System.out.println("Ten lop hoc la: "+em.getNameCourse());}}};private static Runnable linkCourse=new Runnable() {@Overridepublic void run() {// TODO Auto-generated method stubtry {Thread.sleep(1000);} catch (InterruptedException e) {// TODO Auto-generated catch blocke.printStackTrace();}LinkedList<Course> listLink=new LinkedList<Course>();listLink.add(new Course("linkid01", "tk72"));listLink.add(new Course("linkid01", "tk72"));listLink.add(new Course("linkid01", "tk72"));listLink.add(new Course("linkid01", "tk72"));ListIterator iter=listLink.listIterator();while(iter.hasNext()){System.out.println(iter.next());}}};}On Wed, Nov 20, 2013 at 7:17 PM, Vu Tung Lam <vutunglampro@gmail.com> wrote:
package com.main2;public class Employee {private String name;public String getName() {return name;}public void setName(String name) {this.name = name;}private String mobile;public String getMobile() {return mobile;}public void setMobile(String mobile) {this.mobile = mobile;}public Employee(String name, String mobile) {super();this.name = name;this.mobile = mobile;}}package com.main;import java.awt.List;import java.util.ArrayList;import com.main2.Employee;
public class mainform {public static void main(String[] args){ArrayList<Employee> listemployee=new ArrayList<Employee>();listemployee.add(new Employee("khoat duong", "01232321"));listemployee.add(new Employee("khoat duong1", "01232322"));listemployee.add(new Employee("khoat duong2", "01232323"));listemployee.add(new Employee("khoat duong3", "01232324"));listemployee.add(new Employee("khoat duong4", "01232325"));listemployee.add(new Employee("khoat duong5", "01232326"));listemployee.add(new Employee("khoat duong6", "01232327"));listemployee.add(new Employee("khoat duong7", "01232328"));listemployee.add(new Employee("khoat duong8", "01232329"));listemployee.add(new Employee("khoat duong9", "012323222"));listemployee.add(new Employee("khoat duong10", "01232322"));for (Employee em : listemployee) {System.out.println(em.getName()+"-"+em.getMobile());}}}On Wed, Nov 20, 2013 at 6:57 PM, Vu Tung Lam <vutunglampro@gmail.com> wrote:
package com.main;import java.util.ArrayList;public class mainform {/*** @param args*/public static void main(String[] args) {// TODO Auto-generated method stubThread newth=new Thread(doSomeThing);newth.start();ArrayList<String> namelist;namelist=new ArrayList<>();namelist.add("sdff");namelist.add("adfaf");namelist.add("adfasdf");for (String k : namelist) {System.out.println(k);}namelist.remove(1);for (String k : namelist) {System.out.println(k);}}private static Runnable doSomeThing =new Runnable() {@Overridepublic void run() {// TODO Auto-generated method stubfor (int i = 0; i < 300; i++) {System.out.print("dday la rieng");}}};}On Wed, Nov 20, 2013 at 5:14 PM, Dương Văn Khoát <webboyk@gmail.com> wrote:
package Inet;import java.io.InputStreamReader;import java.util.Scanner;public class baisonguyen {/*** @param args*/static int countPhanTu;static int []mang;public static void main(String[] args) {// TODO Auto-generated method stubScanner scan=new Scanner(new InputStreamReader(System.in));System.out.println("Nhap so phan tu:");countPhanTu=scan.nextInt();mang=new int[countPhanTu];System.out.println("Nhap vao cac gia tri cho phan tu:");for(int i=0;i<countPhanTu;i++){System.out.print("mang["+i+"]=");mang[i]=scan.nextInt();}System.out.println();System.out.println();System.out.println();System.out.println();System.out.println();System.out.println("---------------------------------------");System.out.println("Menu");System.out.println("Nhap T truy suat pt");System.out.println("Nhap N de them 1 so pt");System.out.println("Nhap X de xoa 1 phan tu");System.out.println("Nhap L de liet ke");System.out.println("Nhap TK de tim kiem");System.out.println("Nhap S de sap xep");System.out.println("Nhap E de thoat chuong trinh");while(true){String strMenu=scan.nextLine().toUpperCase();switch (strMenu) {case "T":System.out.print("Nhap vi tri pt can truy suat :");int intSelec=scan.nextInt();truyxuatphantu(intSelec);System.out.print("Nhap cac phim de tiep tuc ");break;case "N":System.out.print("Nhap pt can them :");int intadd=scan.nextInt();themmotpt(intadd);System.out.print("Nhap cac phim de tiep tuc ");break;case "X":System.out.print("Nhap vi pt ca xoa :");int intxoa=scan.nextInt();xoaphantuthui(intxoa);break;case "L":break;case "TK":break;case "S":break;case "E":break;}}}public static void truyxuatphantu(int i){System.out.println("phan tu thu "+i+" cua mang la "+mang[i]);}public static void xoaphantuthui(int i){int []tmp=new int[mang.length-1];if(i==0){for (int j = 0; j < tmp.length; j++) {tmp[j]=mang[j+1];}}else if(i==mang.length-1){for (int j = 0; j < tmp.length; j++) {tmp[j]=mang[j];}}else{for (int j = 0; j < tmp.length; j++) {if(j<i){tmp[j]=mang[j];}else if(j>=i){tmp[j]=mang[j+1];}}}System.out.println("mang sau khi xoa phan tu thuw "+i+" la:");for (int j = 0; j < tmp.length; j++) {System.out.print(tmp[j]+" ");}}public static void themmotpt(int a){int []m=new int[mang.length+1];for (int i = 0; i < mang.length; i++) {m[i]=mang[i];}m[mang.length]=a;System.out.println("mang sau khi them phan tu "+a+" la:");for (int j = 0; j < m.length; j++) {System.out.print(m[j]+" ");}}}
Không có nhận xét nào:
Đăng nhận xét