Telefon simülasyonu Eclipse 3.2 ile derlenmştir.Bilgisayarın atadığı random numaralarla hattın dolu olup olmadığını tayin eder, alan kodlarını gösterir ve numara girmenizi ve girdiğiniz numarayı console da görmenizi sağlar.
//CallControl.java
//KAYWINSOFT
package telephone;
import javax.swing.*;
public class CallControl {
boolean checkAvailability()
{
JOptionPane.showMessageDialog(null,"Telephone Numbers Simulation","KAYWINSOFT",
JOptionPane.INFORMATION_MESSAGE);
double random = 0;
for(int i = 0; i<10 ; i++)
random = 5 + Math.random() % 100;
return random>5?true:false;
}
**** areaCodeCheckList()
{
JOptionPane.showMessageDialog(null,"Telephone Numbers Simulation","KAYWINSOFT",
JOptionPane.INFORMATION_MESSAGE);
FileInput info = new FileInput();
info.areaCode();
}
**** getting(String number)
{
FileInput info = new FileInput();
info.getNumber(number);
}
**** showing()
{
FileInput info = new FileInput();
info.showNumber();
}
}
//FileInput.java
//KAYWINSOFT
package telephone;
/**
* This program reads a text file line by line and print to the console. It uses
* FileOutputStream to read the file.
* */
import java.io.*;
public class FileInput extends CallControl {
public **** areaCode(){
try {
BufferedReader in;
in = new BufferedReader(new FileReader("telephone\\AreaCode.txt"));
// dosya bir stream halinde alınır
String str;
// döngü içerisinde satır satır okunur.
while ((str = in.readLine()) != null)
System.out.println(str);
// başta açılan stream kapatılır
in.close();}
catch (IOException e){
System.out.println("Hata oluştu.");
}
}//end areaCode
public **** getNumber(String number)
{
try {
FileWriter yaz;
yaz = new FileWriter("telephone\\User.txt");
PrintWriter okut;
okut = new PrintWriter(yaz);
okut.write(number);
yaz.close();
}//end try
catch(IOException e) {
System.out.println("An error has occured");
}//end catch
}//end getNumber
public **** showNumber()
{
try {
BufferedReader yaz;
yaz = new BufferedReader(new FileReader("telephone\\User.txt"));
String str;
// döngü içerisinde satır satır okunur.
while ((str = yaz.readLine()) != null)
System.out.println(str);
// başta açılan stream kapatılır
yaz.close();}
catch (IOException e){
System.out.println("Hata oluştu.");
}
}//end showNumber
}//end class FileInput
//TelephoneTest.java
//KAYWINSOFT
package telephone;
import javax.swing.*;
public class TelephoneTest {
public static **** main(String[] args) {
// TODO Auto-generated method stub
String gets;
CallControl sub = new CallControl();
boolean checks;
checks = sub.checkAvailability();
if(checks){
sub.areaCodeCheckList();
gets = JOptionPane.showInputDialog("Please Enter the phone number");
sub.getting(gets);
sub.showing();
}//end if
else {
System.out.println("The server is unavaiable , Please try again later");
System.exit(0);
}//end else
}//end main
}
//CallControl.java
//KAYWINSOFT
package telephone;
import javax.swing.*;
public class CallControl {
boolean checkAvailability()
{
JOptionPane.showMessageDialog(null,"Telephone Numbers Simulation","KAYWINSOFT",
JOptionPane.INFORMATION_MESSAGE);
double random = 0;
for(int i = 0; i<10 ; i++)
random = 5 + Math.random() % 100;
return random>5?true:false;
}
**** areaCodeCheckList()
{
JOptionPane.showMessageDialog(null,"Telephone Numbers Simulation","KAYWINSOFT",
JOptionPane.INFORMATION_MESSAGE);
FileInput info = new FileInput();
info.areaCode();
}
**** getting(String number)
{
FileInput info = new FileInput();
info.getNumber(number);
}
**** showing()
{
FileInput info = new FileInput();
info.showNumber();
}
}
//FileInput.java
//KAYWINSOFT
package telephone;
/**
* This program reads a text file line by line and print to the console. It uses
* FileOutputStream to read the file.
* */
import java.io.*;
public class FileInput extends CallControl {
public **** areaCode(){
try {
BufferedReader in;
in = new BufferedReader(new FileReader("telephone\\AreaCode.txt"));
// dosya bir stream halinde alınır
String str;
// döngü içerisinde satır satır okunur.
while ((str = in.readLine()) != null)
System.out.println(str);
// başta açılan stream kapatılır
in.close();}
catch (IOException e){
System.out.println("Hata oluştu.");
}
}//end areaCode
public **** getNumber(String number)
{
try {
FileWriter yaz;
yaz = new FileWriter("telephone\\User.txt");
PrintWriter okut;
okut = new PrintWriter(yaz);
okut.write(number);
yaz.close();
}//end try
catch(IOException e) {
System.out.println("An error has occured");
}//end catch
}//end getNumber
public **** showNumber()
{
try {
BufferedReader yaz;
yaz = new BufferedReader(new FileReader("telephone\\User.txt"));
String str;
// döngü içerisinde satır satır okunur.
while ((str = yaz.readLine()) != null)
System.out.println(str);
// başta açılan stream kapatılır
yaz.close();}
catch (IOException e){
System.out.println("Hata oluştu.");
}
}//end showNumber
}//end class FileInput
//TelephoneTest.java
//KAYWINSOFT
package telephone;
import javax.swing.*;
public class TelephoneTest {
public static **** main(String[] args) {
// TODO Auto-generated method stub
String gets;
CallControl sub = new CallControl();
boolean checks;
checks = sub.checkAvailability();
if(checks){
sub.areaCodeCheckList();
gets = JOptionPane.showInputDialog("Please Enter the phone number");
sub.getting(gets);
sub.showing();
}//end if
else {
System.out.println("The server is unavaiable , Please try again later");
System.exit(0);
}//end else
}//end main
}