chien2311 Enterprise Admin
Tổng số bài gửi : 1224 Sinh nhật : 23/11/1988
| Tiêu đề: Chia sẻ bài tập OOP2 của nhóm Chiến+KimAnh Sun Sep 13, 2009 9:47 pm | |
| Chia sẻ bài tập OOP2 của nhóm Chiến+KimAnhNhóm : Nguyễn Văn Chiến + Nguyễn Thị Kim Anh Bài tập lần 1 : OOP2 Các đặc điểm : + Nhập số sinh viên từ bàn phím + Nhập dữ liệu về sinh viên (Fullname-Birthday) từ bàn phím + Dữ liệu được chuẩn hóa khi thực hiện, tránh các lỗi sảy ra + Sử dụng phương thức phụ trong chương trình, tránh rườm rà cho main() Code : - Code:
-
package exerciseone; /** * Excercise One (OOP2); * Group : NGUYEN VAN CHIEN - NGUYEN THI KIM ANH * Class : K52A3 * Date : 12/09/2009 */ import java.io.*; import java.lang.*;
public class StringTester { public static int Max (int a[],int n) { int t=a[0]; int i,y=0; for (i=1;i<n;i++) if (t<=a[i]) { t=a[i];y=i;} return y; }
public static int CheckFirstname (String a[],int n,String b[]) { int i,j=0,counter=0; while (j<n-1) { for (i=j;i<n-1;i++) if (a[i].equalsIgnoreCase(a[++j])) { System.out.println((++counter)+" : \""+b[i]+"\" AND \""+b[j]+"\""); } } return counter; }
public static void main(String args[]) throws java.io.IOException { String Firstname[] =new String[10]; String Lastname[] =new String[10]; String ch[] =new String[10]; int Birth[] =new int[10]; int i,j,n; int maxindex; int Check;
BufferedReader inputObj=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter the Number Of Students (An Integer): "); n=Integer.valueOf(inputObj.readLine()).intValue();
System.out.println("Enter Information (Fullname-Birthday) (Ex : nguyen van a-23/09/1988): "); for (i=0;i<n;i++) { System.out.println("Student " +i+ " : "); ch[i]=inputObj.readLine(); String[] GetInfo=ch[i].split("-");
String Fullname=GetInfo[0].trim(); String Birthday=GetInfo[1].trim();
String[] SplitFullname=Fullname.split(" "); String[] SplitBirthday=Birthday.split("/");
int k=SplitFullname.length; Firstname[i]=SplitFullname[0].trim(); Lastname[i] =SplitFullname[k-1].trim();
String tmp=SplitBirthday[2]+SplitBirthday[1]+SplitBirthday[0]; Birth[i]=Integer.parseInt(tmp); }
System.out.println("----------------Section A-----------------"); System.out.println("Name of " +n+ " Student is : "); for (i=0;i<n;i++) System.out.println("Student "+i+" is "+Lastname[i]);
System.out.println("----------------Section B-----------------"); System.out.println("Boths of the Students have Firstnames in the same : "); Check=CheckFirstname(Firstname,n,ch); if (Check==0) System.out.println("List is Empty !");
System.out.println("----------------Section C-----------------"); maxindex=Max(Birth,n); System.out.println("The youngest student is "+ch[maxindex]);
}
}
Và đây là kết xuất của một trường hợp khi test : Công bố : 0h00 ngày 14/09/2009 | |
|