begin process at 2010 03 11 06:54:48
  Trouver un code source :
 
dans
 
Accueil > Forum > 

JAVA / J2EE / J2ME

 > 

Divers

 > 

Débutant(e)

 > 

optimisation d'un code


Derniers messages déposésPoser une question dans le forum ou lancer une discussion

optimisation d'un code

samedi 27 mai 2006 à 11:37:04 | optimisation d'un code

laurentbarbotin

je souhaiterais optimiser un code et faire le pseudo code correspondant svp aidez moi


import biputil.*;
import java.io.*;


/**
 * @com.register ( clsid=72CBC516-6741-430F-859D-779EDFF3864B, typelib=FC184FEC-B0C1-48D3-BA51-B09ED77BD30A )
 */
public class xxxxx
{
 
 public static void main (String[] args) throws Exception
              
 {
  boolean autreC = true ;
  boolean autreF = true ;
  int i = 0;
  int j = 0;
  int Montant =0;
  String strDate = new String();
  String strCodeRem = new String();
  String strTotal = new String();
  String strNClient = new String();
  String strNFact = new String();
  String strLine = new String ();
  String strMontant = new String();
  SequentialFile facture = new SequentialFile();
  IndexedFile client = new IndexedFile();
  try
  {
   do
   {
    System.out.print("Numero de Client ? :");
    strNClient = getString();
    
    client.open("fclient.txt");
    strLine = client.read(strNClient);
    if (client.InvalidKey == true)
    {
     System.err.println ("Err Client inconnu");
     if (autreF = false );
     
    }
    else
    {
     System.out.println (strLine);
     autreF = true;
     j = j + 1;
    }
    client.close();
    facture.open ("ffacture.txt",'w');
    while (autreF == true)
    {
     if (client.InvalidKey == false)
      

     do
     {
      System.out.print("Numero de Facture :");
      strNFact = getString();
      if (strNFact.length()!= 4)
      {
       System.err.println("Err Le Numero de facture doit etre compris entre 1000 et 9999.");
      }
     }while(strNFact.length()!= 4);
     
     do
     {
      System.out.print("Date :");
      strDate = VerifDate();
      
     }while (strDate.equals (""));
     
     do
     {
      System.out.print("Montant :");
      strMontant = getString();
      Integer nMontant = new Integer(strMontant);
      Montant = nMontant.intValue();
      if (Montant < 0)
      {
       System.out.println("Err Montant negatif");
      }
     }while(Montant < 0);

     String strRemise = new String();
     do
     {
      System.out.print("CodeRemise :");
      strCodeRem = getString();
      strRemise = getCode(strCodeRem);
     }while (strRemise.equals (""));
     
     Integer nRemise = new Integer(strRemise);
     int TotalRem = nRemise.intValue();
     strTotal = ((Montant-((Montant*TotalRem)/100)) + " euro(s)");
     System.out.println("Montant calcule : " + strTotal);
     System.out.print("Enregistrer la facture ? O / N :");
     boolean bEnrFact = getBoolean();
          
     
     {
      facture.write (strNClient + ","+strNFact + "," + strDate.substring(0,10) + "," + strCodeRem + "," +
        strTotal);
     }
     System.out.print("Autre facture ? O / N :");
     autreF = getBoolean();
     i = i  + 1;
     
     
    }if (client.InvalidKey == false)
    System.out.print("Autre client ? O / N :");
    autreC = getBoolean();
    
     
   }
    while (autreC == true);
   
   System.out.print("Edition Bordereaux O / N :");
   boolean bBord = getBoolean();
   facture.close();
   
   if (bBord == true)
   {
    facture.open ("ffacture.txt",'r') ;
    System.out.println("N°Client"+"\t"+"N°"+"\t"+"Date"+"\t"+" CodeRemise"+"\t"+
         "Montant Calcule");
    System.out.println("");
    String strControleur2 = "";
    
    while (! facture.EndOfFile)
    {
     int a = 1;
     int b = 2;
     int c = 3;
     int d = 4;
     int e = 5;
     
     strLine = facture.read();
     String strControleur1 = new String(facture.fieldOf(strLine,a));

     if (strLine != null)
     {
      if (strControleur1.equals (strControleur2))
      {
       System.out.println("\t"+"\t"+ facture.fieldOf(strLine,b)+"\t"+facture.fieldOf(strLine,c)+"\t"+facture.fieldOf(strLine,d)+"\t"+"\t"+facture.fieldOf(strLine,e));
      }
      else
      {
       System.out.println(facture.fieldOf(strLine,a)+"\t"+"\t"+ facture.fieldOf(strLine,b)+"\t"+facture.fieldOf(strLine,c)+"\t"+facture.fieldOf(strLine,d)+"\t"+"\t"+facture.fieldOf(strLine,e));
      }
      System.out.println("");
      strControleur2 = strControleur1;
     }
    }
    facture.close();
    System.out.println ("Total : "+ i + " factures saisie(s) pour "+
          j + " client(s)");
    System.out.println("");
    System.out.println("***** Fin Programme ***** (ENTREE pour Sortir)");
    System.in.read();
   }
  }

  catch (IOException ioe)
  {
   System.out.println (ioe);
   System.out.println ("Erreur de saisie clavier");
  }
  catch (NumberFormatException nfe)
  {
   System.out.println (nfe);
   System.out.println ("La valeur doit etre un entier");
  }
  System.out.print("Fin de programme");
 }
 public static String getString()
  throws IOException
 {
  byte bArray[] = new byte [20];
  System.in.read(bArray);
  String strSaisie = new String(bArray);
  return strSaisie.substring(0, strSaisie.indexOf("\r\n"));
 }
 public static boolean getBoolean()
  throws IOException, NumberFormatException
 {
  String strReponse = getString();
  boolean bReponse = true;
  
  if (strReponse.equals ("n") || strReponse.equals ("N"))
  {
   bReponse = false; 
  }
  else
  {
   if (strReponse.equals ("o")|| strReponse.equals ("O"))
   {
    return bReponse;
   }
   else
    
   {
    
    System.err.println("Attention, repondez par O ou N ! Le programme continu"); 
    return bReponse;
   }
  }
  return bReponse; 
 }
 public static String VerifDate ()
  throws Exception
 {
  byte Tab[] = new byte[20];
  System.in.read(Tab);
  String strGetDate = new String (Tab);
  String strControle = strGetDate.substring(0,strGetDate.indexOf("\r\n"));
  if (strControle.length() != 10)
  {
   System.err.println("Err Date");
   return strGetDate = "";
  }
  strControle = strGetDate.substring(0,strGetDate.indexOf("/"));
  Integer nControle = new Integer(strControle);
  int A = nControle.intValue();
  int JMax = 0;
  
  if (A < 2006)
  {
   System.err.println("Err Date");
   return strGetDate = "";
  }
  strControle = strGetDate.substring(5,7);
  nControle = new Integer(strControle);
  int M = nControle.intValue();
  strControle = strGetDate.substring(8,strGetDate.indexOf("\r\n"));
  nControle = new Integer(strControle);
  int J = nControle.intValue();
  JMax = 0;
  boolean VJ = false;
  boolean VM = false;
  
  if ((M >= 0) || (M <= 12))
  {
   VM = true;
   if ((A % 400) == 0 || (((A % 100) != 0 && (A % 4)== 0) && M == 02))
   {
    JMax = 29;
   }
   else if (M == 2)
    {
     JMax = 28;
    }
    else if (M == 4 || M ==6 || M == 9 || M == 11)
     {
      JMax = 30;
     }
     else
     {
      JMax = 31;
     }
  }
  if (J >= 1 && J <= JMax)
  {
   VJ = true;
  }
  if (VM != true || VJ != true)
  {
   System.out.println("Err Date");
   return strGetDate = "";
  }
     
  
  return strGetDate;
 }
 public static String getCode(String strCodeRem)
  throws Exception
 {
  if (strCodeRem.length() > 1)
  {
   System.out.println("Format Remise ");

  }
  String strCode = new String ();
  
  if (strCodeRem.equals ("A")||strCodeRem.equals ("a"))
  {
   strCode = "5";
  }
  if (strCodeRem.equals ("C")||strCodeRem.equals ("c"))
  {
   strCode = "15";
  }
  if (strCodeRem.equals ("E")||strCodeRem.equals ("e"))
  {
   strCode = "30";
  }
  if (strCodeRem.equals ("K")||strCodeRem.equals ("k"))
  {
   strCode = "40";
  }
  if (strCodeRem.equals ("R")||strCodeRem.equals ("r"))
  {
   strCode = "55";
  }
  if (strCode.equals (""))
  {
   System.err.println("Err Remise");
  }
  return  strCode;
 }
}

mercredi 31 mai 2006 à 12:08:50 | Re : optimisation d'un code

HSylvio

Ton pseudo-code est simplement le dérouement du pgm :
-demande de un truc
-lecture d'une ligne entrée
-verif données
-enregistre

Sinon pour optimiser, par exemple tes dernieres lignes seraient ptetr mieux avec un toLowerCase sur StrCodeRem puis un switch peut etre...
mardi 17 avril 2007 à 23:39:19 | Re : optimisation d'un code

anadeveloppeur

Bonsoir laurentbarbotin, qu'en est il de ton code ? ;-) On veut bien voir à ce que t'es arrivé :)


Cette discussion est classée dans : string, system, out, println, facture


Répondre à ce message

Sujets en rapport avec ce message

compatibilité argument File String [ par sido722 ] Mon erreurMafenetre4.java:181: tests(java.io.File) in Mafenetre4 cannot be applied to (java.lang.String) tests(file.getAbsolutePath()); acces au contenu d'un message avec javamail [ par amine hayat ] Bonjour. Voici mon problème.Je suis en train de faire une appli qui doit recevoire et envoyer des emails dans une boîte mail. mon probléme est que je AIDE sur Connexion BDD MySQL [ par zeldoi5 ] Bonjour tout le monde!Je sais que le problème dont je vais parler a déjà été traité plusieurs fois... Mais impossible de me connecter à ma base de don JPANEL [ par LeNeutrino ] je suis en projet et je souhaiterais faire un formulaire et pour les insertions de données et pour les consultations. j'utilise un jdbnavcombox relié Surcharge : aide [ par Tachag ] Bonjour,Alors, j'ai essayé de faire une surcharge.  Ma question est : pourquoi lorsque je fais execute file, l'information n'apparaît pas?Je vous tran problème d'affichage d'une chaine dans un servlet [ par 2tsiris ] Bonjour à tous, j'ai créer un servlet qui récupère une valeur dans une table mysql.J'ai donc créer une méthode qui se connect à la base et effectue Reseau et internet [ par felouss ] bonjour,j ai un probleme pour envoyer un gros fichier via UDP,udp ne permet l envoie de paquet > 65kilo,pour cela du coté serveur j ai decoupé le fich ajout dans un tableau en java [ par samanona ] slt, j'ai un probleme au java et j'aimerai le resoudre  voila la methode que j'ai ecrit: String tab[][]=new String[80][4];Scanner s=new Scanner(Syst probléme d'execution [ par itafomis ] bonjour tout le monde.je veux me connecter a une base de donnée sql 2000 a partir d'eclipse et voila le code que j'ai utiliséimport java.*;<font color gros probleme [ par romainbisson ] j'ai un gros soucis, j'ai une classe qui permet de se connecter sur le serveur pop de gmail, maintenant j'aimerais crée une autre classe avec une JFr


Nos sponsors


Sondage...

CalendriCode

Mars 2010
LMMJVSD
1234567
891011121314
15161718192021
22232425262728
293031    

Consulter la suite du CalendriCode

 
Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils.
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés

Google Coop CodeS-SourceS Google Coop CodeS-SourceS
Temps d'éxécution de la page : 0,265 sec (4)

Nous contacter | Annoncer sur CodeS-SourceS | Mentions légales