//======================================================
// Thermodynamic Package in java
// Class Atom
// Properties of single atom
// -----------------------------------------------------
// Programmer : Dr. Turhan Coban
// TUBITAK Marmara Research Center
// Energy Systems and Environmental Reasearch Institute
// turhan@mam.gov.tr
// -----------------------------------------------------
// File Name   : Atom.java
// This file contains the atom class
// this class sets basic properties of requested atom
// required data is read from atom.txt
// atom.txt should be copied to the same directory as your
// atom.java file
// =====================================================

import java.io.*;
import java.util.*;
import Text;
import java.rmi;
import java.rmi.server.*;
import java.net.*;


class AtomURL extends UnicatsRemoteObject
{
public int  number;            // atomic number
public String name;            // name of the the atom
public String symbol;          // symbol of the atom
public double mass;            // mass of the atom
public double N;               // number of the atoms
URL url;
BufferedReader fina;

public AtomURL() throws RemoteException
{
//empty constructor
number=0;
symbol="";
name="";
mass=0;
N=1;
}

//=================================================================
public Atom(int anumber,double NN) throws RemoteException,IOException
{
//this constructor will load Atom data from a given atomic number
//and number of atoms
//type
 String atom_name;
 String atom_symbol;
 double atom_mass;
 int atom_number;
 url=new URL("http://www.mam.gov.tr/turhan/
    try{
       fina=new BufferedReader(new FileReader("Atom.txt"));
       } catch(IOException e)
       {
       System.err.println("Error Opening File Atom.dat\n"+e.toString());
       System.exit(1);
       }
 try   {
 while(fina != null)
   {
      atom_number=Text.readInt(fina);
      atom_name= Text.readString(fina);
      atom_symbol= Text.readString(fina);
      atom_mass=Text.readDouble(fina);
      if(atom_number==anumber)
      {
      N=NN;
      number=atom_number;
      name=atom_name;
      symbol=atom_symbol;
      mass=atom_mass*N;
      break;
      }
   }
          } catch(EOFException e_eof) {fina.close(); }
}

public Atom(String st1,double NN) throws IOException
{
// this constructor will load Atom data from a given atom name
// or atom symbol and number of atoms
// type
 String atom_name;
 String atom_symbol;
 double atom_mass;
 int atom_number;
  try{
       fina=new BufferedReader(new FileReader("Atom.txt"));
       } catch(IOException e)
       {
       System.err.println("Error Opening File Atom.dat\n"+e.toString());
       System.exit(1);
       }
 try      {
 while(fina != null)
   {
      atom_number=Text.readInt(fina);
      atom_name= Text.readString(fina);
      atom_symbol= Text.readString(fina);
      atom_mass=Text.readDouble(fina);
      if(st1.equals(atom_name) || st1.equals(atom_symbol))
      {
      N=NN;
      number=atom_number;
      name=atom_name;
      symbol=atom_symbol;
      mass=atom_mass*N;
      break;
      }
   }
   } catch(EOFException e_eof) {fina.close(); }
}

public Atom(String st1) throws IOException
{
// this constructor will load Atom data from a given atom name
// or atom symbol and number of atoms
// type
 double NN=1;
 String atom_name;
 String atom_symbol;
 double atom_mass;
 int atom_number;
  try{
       fina=new BufferedReader(new FileReader("Atom.txt"));
       } catch(IOException e)
       {
       System.err.println("Error Opening File Atom.dat\n"+e.toString());
       System.exit(1);
       }
 try      {
 while(fina != null)
   {
      atom_number=Text.readInt(fina);
      atom_name= Text.readString(fina);
      atom_symbol= Text.readString(fina);
      atom_mass=Text.readDouble(fina);
      if(st1.equals(atom_name) || st1.equals(atom_symbol))
      {
      N=NN;
      number=atom_number;
      name=atom_name;
      symbol=atom_symbol;
      mass=atom_mass*N;
      break;
      }
   }
          } catch(EOFException e_eof) {fina.close(); }
}

public Atom(Atom  a)
{
number=a.number;
name=a.name;
symbol=a.symbol;
mass=a.mass;
N=a.N;
}

public Atom(Atom  a, double NN)
{
number=a.number;
name=a.name;
symbol=a.symbol;
mass=a.mass;
N=NN;
}

//=================================================================
public void assign(Atom  a)
{
number=a.number;
name=a.name;
symbol=a.symbol;
mass=a.mass;
N=a.N;
}
//=================================================================
//boolean equals logical comparisons
public boolean equals(String s)
{
boolean b;
if(name.equals(s) || symbol.equals(s))
  return true;
else
  return false;
}

public boolean equals(int n)
{
boolean b;
if(number==n)
  return true;
else
  return false;
}
//=================================================================

//this ostream function will send the symbol+number of atoms to cout
public String toString()
{
String st=symbol;
if(N != 1.0)
   if(N==Math.floor(N))  st = st + (int)N;
   else                  st = st + N;
return st;
}

}

//=================================================================

