※ 此程式碼並非優化版本,僅供個人學習用途,若有任何問題請告知。
功能:分成姓和名,區分性別以隨機產生。 ※ 準備4個txt檔,分別是: Female_Frist.txt、Female.txt、Male_Frist.txt、Male.txt。(加上_Frist為姓,沒加則是名)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main.common; | |
import java.io.File; | |
import java.io.FileNotFoundException; | |
import java.io.FileReader; | |
import java.util.ArrayList; | |
import java.util.List; | |
import java.util.Scanner; | |
class name { | |
List namelist; | |
String Name, Fristname; | |
name() { | |
namelist = new ArrayList(); | |
Name = null; | |
Fristname = null; | |
} | |
Scanner sc = null; | |
void add(Scanner sc) { //add data into list | |
while(sc.hasNext()) { | |
String s = sc.next(); | |
namelist.add(s); | |
} | |
} | |
String random() { //random get one num to select one word | |
return (String)namelist.get((int)(Math.random()*(namelist.size()-1)+0)); | |
} | |
String get(String firstname, String name) { | |
String finalname = firstname + " " + name; | |
return finalname; | |
} | |
} | |
class Female extends name { | |
Female() { | |
try { | |
FileReader fin = new FileReader("src\\main\\common\\Name\\Female_Frist.txt"); | |
add(sc = new Scanner(fin)) | |
Fristname = random(); | |
FileReader fin2 = new FileReader("src\\main\\common\\Name\\Female.txt"); | |
add(sc = new Scanner(fin2)); | |
Name = random(); | |
} catch (FileNotFoundException e) { | |
System.out.println ("File not found!"); | |
System.exit(0); | |
} | |
} | |
} | |
class Male extends name { | |
Male() { | |
try { | |
FileReader fin = new FileReader("src\\main\\common\\Name\\Male_Frist.txt"); | |
add(sc = new Scanner(fin)); | |
Fristname = random(); | |
FileReader fin2 = new FileReader("src\\main\\common\\Name\\Male.txt"); | |
add(sc = new Scanner(fin2)); | |
Name = random(); | |
} catch (FileNotFoundException e) { | |
System.out.println ("File not found!"); | |
System.exit (0); | |
} | |
} | |
} | |
public class allname { | |
public static void main(String[] args) { | |
Female f = new Female(); | |
Male m = new Male(); | |
System.out.println("Female:"+f.get(f.Fristname,f.Name)); | |
System.out.println("Male:"+m.get(m.Fristname,m.Name)); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
知美 | |
景子 | |
佳那 | |
みほ | |
美代 | |
玲菜 | |
真世 | |
朱実 | |
祐貴子 | |
更紗 | |
紗衣 | |
公恵 | |
麻穂 | |
亜香里 | |
奈留美 | |
淑乃 | |
莉花 | |
奈子 | |
悦美 | |
益代 | |
佐登子 | |
千果 | |
萌加 | |
越子 | |
祐奈 | |
公実子 | |
朱子 | |
梨里 | |
麻絵 | |
佑芽 | |
志寿香 | |
悠喜 | |
和花奈 | |
緋沙子 | |
媛媛 | |
まさ代 | |
結美 | |
美沙姫 | |
ことり | |
奈都代 | |
麻李 | |
康葉 | |
美輝子 | |
眞知 | |
紗耶未 | |
玲未 | |
麻里名 | |
真紗代 | |
伶美 | |
桂代子 | |
清可 | |
暖香 | |
みほり | |
淑香 | |
由愛 | |
なな恵 | |
裕樹 | |
豊香 | |
幸惠 | |
寧音 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
中田 | |
岩見 | |
山之内 | |
宇井 | |
八尾 | |
北畠 | |
今本 | |
信岡 | |
浅賀 | |
長妻 | |
森近 | |
善本 | |
布田 | |
菊山 | |
才川 | |
下池 | |
德田 | |
相崎 | |
大舘 | |
伊月 | |
宮竹 | |
海堂 | |
下斗米 | |
下西 | |
市位 | |
梁取 | |
三ッ木 | |
齋川 | |
飯笹 | |
見並 | |
神出 | |
小佐古 | |
角埜 | |
納戸 | |
古郷 | |
喜久 | |
外 | |
間下 | |
米 | |
砂原 | |
船越 | |
渕江 | |
多留 | |
内坂 | |
迫野 | |
冨久 | |
武津 | |
葉畑 | |
奈古 | |
千綾 | |
上遠野 | |
灰佐 | |
小神 | |
中明 | |
小田元 | |
植永 | |
初 | |
乙川 | |
樽澤 | |
法 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
幸一 | |
勇輝 | |
拓真 | |
俊宏 | |
信雄 | |
勝則 | |
雅章 | |
一将 | |
一成 | |
弘典 | |
裕平 | |
康正 | |
佑紀 | |
桂 | |
辰弥 | |
彰洋 | |
祥二 | |
尚志 | |
海渡 | |
孝生 | |
寛司 | |
紀章 | |
不二夫 | |
錬 | |
由浩 | |
勝平 | |
成明 | |
育也 | |
重文 | |
和亮 | |
茂太 | |
昌功 | |
信正 | |
洋信 | |
隆之 | |
邦臣 | |
和高 | |
亮磨 | |
満也 | |
敬司 | |
繁人 | |
安隆 | |
万寿夫 | |
楊 | |
盛和 | |
保美 | |
大介 | |
徳洋 | |
宗光 | |
知男 | |
美成 | |
輝充 | |
博善 | |
哲範 | |
公 | |
健右 | |
兼義 | |
邦朗 | |
ヤス | |
正哲 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
新井 | |
藤崎 | |
川久保 | |
伊奈 | |
倉岡 | |
奥間 | |
花山 | |
中馬 | |
村下 | |
可知 | |
井沢 | |
浜井 | |
蘭 | |
門松 | |
中崎 | |
江島 | |
畑村 | |
尾林 | |
栖原 | |
大網 | |
儀武 | |
笠田 | |
鴻上 | |
植島 | |
下藤 | |
八村 | |
八十 | |
入木田 | |
伊差川 | |
堆 | |
神井 | |
太原 | |
森蔭 | |
沢津橋 | |
交告 | |
片宗 | |
松野尾 | |
白矢 | |
鳥村 | |
横家 | |
藁谷 | |
渡引 | |
高向 | |
阪木 | |
坂ノ下 | |
宇治谷 | |
大聖 | |
二階堂 | |
小石沢 | |
腰高 | |
霧隠 | |
中農 | |
小馬 | |
天藤 | |
風俗 | |
商崎 | |
与沢 | |
松金 | |
丸見 | |
角戸 |
結果如下:
[第一次] 女性:奈古 由愛 男性:八十 鳥村 [第二次] 女性:植永 紗衣 男性:花山 幸一 [第三次] 女性:三ッ木 梨里 男性:伊差川 鳥村
沒有留言:
張貼留言