I am using QuickFixJ with SpringBoot to publish market price data to Bloomberg. When publishing prices, everything is working well. However, I cannot see any prices published on Bloomberg when I hit ALLQ.
Event log files :
8=FIXT.1.1^A9=60^A35=0^A34=617^A49=ARHGPROD^A52=20211110-16:16:44.472^A56=BBGPROD^A10=223^A
8=FIXT.1.1^A9=60^A35=0^A49=BBGPROD^A56=ARHGPROD^A34=603^A52=20211110-16:16:58.566^A10=227^A
8=FIXT.1.1^A9=60^A35=0^A34=618^A49=ARHGPROD^A52=20211110-16:17:14.472^A56=BBGPROD^A10=222^A
8=FIXT.1.1^A9=60^A35=0^A49=BBGPROD^A56=ARHGPROD^A34=604^A52=20211110-16:17:28.573^A10=224^A
8=FIXT.1.1^A9=60^A35=0^A34=619^A49=ARHGPROD^A52=20211110-16:17:44.472^A56=BBGPROD^A10=226^A
8=FIXT.1.1^A9=60^A35=0^A49=BBGPROD^A56=ARHGPROD^A34=605^A52=20211110-16:17:58.576^A10=231^A
8=FIXT.1.1^A9=89^A35=A^A34=1^A49=ARHGPROD^A52=20211110-16:18:45.788^A56=BBGPROD^A98=0^A108=30^A141=Y^A789=1^A1137=9^A10=059^A
8=FIXT.1.1^A9=83^A35=A^A49=BBGPROD^A56=ARHGPROD^A34=1^A52=20211110-16:18:46.082^A98=0^A108=30^A141=Y^A1137=9^A10=018^A
8=FIXT.1.1^A9=161^A35=X^A34=2^A49=ARHGPROD^A52=20211110-16:18:49.492^A56=BBGPROD^A1022=KPIS^A268=2^A279=0^A269=0^A48=XS2269741729^A22=4^A270=99.59^A279=0^A269=1^A48=XS2269741729^A22=4^A270=100.59^A10=192^A
8=FIXT.1.1^A9=161^A35=X^A34=3^A49=ARHGPROD^A52=20211110-16:18:49.496^A56=BBGPROD^A1022=KPIS^A268=2^A279=0^A269=0^A48=XS2269741729^A22=4^A270=99.59^A279=0^A269=1^A48=XS2269741729^A22=4^A270=100.59^A10=197^A
8=FIXT.1.1^A9=160^A35=X^A34=4^A49=ARHGPROD^A52=20211110-16:18:49.499^A56=BBGPROD^A1022=KPIS^A268=2^A279=0^A269=0^A48=XS2343341074^A22=4^A270=98.39^A279=0^A269=1^A48=XS2343341074^A22=4^A270=99.39^A10=128^A
8=FIXT.1.1^A9=160^A35=X^A34=5^A49=ARHGPROD^A52=20211110-16:18:49.500^A56=BBGPROD^A1022=KPIS^A268=2^A279=0^A269=0^A48=XS2343341074^A22=4^A270=98.39^A279=0^A269=1^A48=XS2343341074^A22=4^A270=99.39^A10=112^A
8=FIXT.1.1^A9=58^A35=0^A49=BBGPROD^A56=ARHGPROD^A34=2^A52=20211110-16:19:16.585^A10=129^A
8=FIXT.1.1^A9=58^A35=0^A34=6^A49=ARHGPROD^A52=20211110-16:19:19.609^A56=BBGPROD^A10=133^A
8=FIXT.1.1^A9=58^A35=0^A49=BBGPROD^A56=ARHGPROD^A34=3^A52=20211110-16:19:46.587^A10=135^A
8=FIXT.1.1^A9=58^A35=0^A34=7^A49=ARHGPROD^A52=20211110-16:19:49.609^A56=BBGPROD^A10=137^A
8=FIXT.1.1^A9=58^A35=0^A49=BBGPROD^A56=ARHGPROD^A34=4^A52=20211110-16:20:16.595^A10=124^A
8=FIXT.1.1^A9=58^A35=0^A34=8^A49=ARHGPROD^A52=20211110-16:20:19.609^A56=BBGPROD^A10=127^A
8=FIXT.1.1^A9=58^A35=0^A49=BBGPROD^A56=ARHGPROD^A34=5^A52=20211110-16:20:46.597^A10=130^A
8=FIXT.1.1^A9=58^A35=0^A34=9^A49=ARHGPROD^A52=20211110-16:20:49.609^A56=BBGPROD^A10=131^A
8=FIXT.1.1^A9=58^A35=0^A49=BBGPROD^A56=ARHGPROD^A34=6^A52=20211110-16:21:16.603^A10=117^A
8=FIXT.1.1^A9=59^A35=0^A34=10^A49=ARHGPROD^A52=20211110-16:21:19.609^A56=BBGPROD^A10=170^A
8=FIXT.1.1^A9=58^A35=0^A49=BBGPROD^A56=ARHGPROD^A34=7^A52=20211110-16:21:46.610^A10=119^A
8=FIXT.1.1^A9=59^A35=0^A34=11^A49=ARHGPROD^A52=20211110-16:21:49.609^A56=BBGPROD^A10=174^A
8=FIXT.1.1^A9=58^A35=0^A49=BBGPROD^A56=ARHGPROD^A34=8^A52=20211110-16:22:16.616^A10=124^A
8=FIXT.1.1^A9=59^A35=0^A34=12^A49=ARHGPROD^A52=20211110-16:22:19.609^A56=BBGPROD^A10=173^A
8=FIXT.1.1^A9=58^A35=0^A49=BBGPROD^A56=ARHGPROD^A34=9^A52=20211110-16:22:46.621^A10=124^A
8=FIXT.1.1^A9=59^A35=0^A34=13^A49=ARHGPROD^A52=20211110-16:22:49.609^A56=BBGPROD^A10=177^A
8=FIXT.1.1^A9=59^A35=0^A49=BBGPROD^A56=ARHGPROD^A34=10^A52=20211110-16:23:16.626^A10=168^A
8=FIXT.1.1^A9=59^A35=0^A34=14^A49=ARHGPROD^A52=20211110-16:23:19.609^A56=BBGPROD^A10=176^A
8=FIXT.1.1^A9=59^A35=0^A49=BBGPROD^A56=ARHGPROD^A34=11^A52=20211110-16:23:46.632^A10=169^A
8=FIXT.1.1^A9=59^A35=0^A34=15^A49=ARHGPROD^A52=20211110-16:23:49.609^A56=BBGPROD^A10=180^A
8=FIXT.1.1^A9=59^A35=0^A49=BBGPROD^A56=ARHGPROD^A34=12^A52=20211110-16:24:16.636^A10=172^A
8=FIXT.1.1^A9=59^A35=0^A34=16^A49=ARHGPROD^A52=20211110-16:24:19.609^A56=BBGPROD^A10=179^A
8=FIXT.1.1^A9=59^A35=0^A49=BBGPROD^A56=ARHGPROD^A34=13^A52=20211110-16:24:46.643^A10=174^A
8=FIXT.1.1^A9=59^A35=0^A34=17^A49=ARHGPROD^A52=20211110-16:24:49.609^A56=BBGPROD^A10=183^A
8=FIXT.1.1^A9=59^A35=0^A49=BBGPROD^A56=ARHGPROD^A34=14^A52=20211110-16:25:16.647^A10=177^A
8=FIXT.1.1^A9=59^A35=0^A34=18^A49=ARHGPROD^A52=20211110-16:25:19.609^A56=BBGPROD^A10=182^A
8=FIXT.1.1^A9=59^A35=0^A49=BBGPROD^A56=ARHGPROD^A34=15^A52=20211110-16:25:46.654^A10=179^A
Message log files :
8=FIXT.1.1^A9=59^A35=0^A49=BBGPROD^A56=ARHGPROD^A34=30^A52=20211110-16:33:16.726^A10=172^A
8=FIXT.1.1^A9=59^A35=0^A34=34^A49=ARHGPROD^A52=20211110-16:33:19.609^A56=BBGPROD^A10=179^A
8=FIXT.1.1^A9=59^A35=0^A49=BBGPROD^A56=ARHGPROD^A34=31^A52=20211110-16:33:46.731^A10=172^A
8=FIXT.1.1^A9=59^A35=0^A34=35^A49=ARHGPROD^A52=20211110-16:33:49.609^A56=BBGPROD^A10=183^A
8=FIXT.1.1^A9=59^A35=0^A49=BBGPROD^A56=ARHGPROD^A34=32^A52=20211110-16:34:16.733^A10=173^A
8=FIXT.1.1^A9=59^A35=0^A34=36^A49=ARHGPROD^A52=20211110-16:34:19.609^A56=BBGPROD^A10=182^A
8=FIXT.1.1^A9=59^A35=0^A49=BBGPROD^A56=ARHGPROD^A34=33^A52=20211110-16:34:46.739^A10=183^A
8=FIXT.1.1^A9=59^A35=0^A34=37^A49=ARHGPROD^A52=20211110-16:34:49.609^A56=BBGPROD^A10=186^A
8=FIXT.1.1^A9=59^A35=0^A49=BBGPROD^A56=ARHGPROD^A34=34^A52=20211110-16:35:16.742^A10=176^A
8=FIXT.1.1^A9=59^A35=0^A34=38^A49=ARHGPROD^A52=20211110-16:35:19.609^A56=BBGPROD^A10=185^A
8=FIXT.1.1^A9=59^A35=0^A49=BBGPROD^A56=ARHGPROD^A34=35^A52=20211110-16:35:46.750^A10=179^A
8=FIXT.1.1^A9=59^A35=0^A34=39^A49=ARHGPROD^A52=20211110-16:35:49.609^A56=BBGPROD^A10=189^A
8=FIXT.1.1^A9=59^A35=0^A49=BBGPROD^A56=ARHGPROD^A34=36^A52=20211110-16:36:16.757^A10=185^A
8=FIXT.1.1^A9=59^A35=0^A34=40^A49=ARHGPROD^A52=20211110-16:36:19.609^A56=BBGPROD^A10=179^A
8=FIXT.1.1^A9=59^A35=0^A49=BBGPROD^A56=ARHGPROD^A34=37^A52=20211110-16:36:46.763^A10=186^A
8=FIXT.1.1^A9=162^A35=X^A34=41^A49=ARHGPROD^A52=20211110-16:36:49.235^A56=BBGPROD^A1022=KPIS^A268=2^A279=0^A269=0^A48=XS2269741729^A22=4^A270=99.59^A279=0^A269=1^A48=XS2269741729^A22=4^A270=100.59^A10=239^A
8=FIXT.1.1^A9=162^A35=X^A34=42^A49=ARHGPROD^A52=20211110-16:36:49.236^A56=BBGPROD^A1022=KPIS^A268=2^A279=0^A269=0^A48=XS2269741729^A22=4^A270=99.59^A279=0^A269=1^A48=XS2269741729^A22=4^A270=100.59^A10=241^A
My Java code :
/**
* Classe responsable de la publication des prix sur Bloomberg
* */
public class BloombergPricePublisher {
Logger logger = LoggerFactory.getLogger(BloombergPricePublisher.class);
/**
* Constructeur de BloombergPricePublisher
* */
public BloombergPricePublisher(){
super();
}
/**
* Méthode de publication d'un prix sur Bloomberg
* */
public void publish(MarketPrice marketPrice) {
MarketDataIncrementalRefresh marketDataIncrementalRefresh = createMarketDataIncrementalRefresh(marketPrice);
try{
for (SessionID sessionID : ValuationApplication.threadedSocketInitiator.getSessions()){
Boolean sent = Session.lookupSession(sessionID).send(marketDataIncrementalRefresh);
logger.info("Prix publié sur Bloomberg : " + marketDataIncrementalRefresh.toString().replace('\001', '|'));
logger.info("Confirmation de réception : " + sent);
}
}catch (Exception e){
e.printStackTrace();
}
}
/**
* Méthode de création d'un nouveau prix pour le publier sur Bloomberg
* #param marketPrice
* */
public MarketDataIncrementalRefresh createMarketDataIncrementalRefresh(MarketPrice marketPrice) {
quickfix.fix50sp2.MarketDataIncrementalRefresh message = new MarketDataIncrementalRefresh();
quickfix.fix50sp2.MarketDataIncrementalRefresh.NoMDEntries group = new MarketDataIncrementalRefresh.NoMDEntries();
message.getHeader().setString(1022, "****");
/**
* FIX tags :
* 8: BeginString
* 9: BodyLength
* 10: CheckSum
* 22: IDSource
* 34: MsgSeqNum
* 35: MsgType
* 49: SenderCompID
* 52: SendingTime
* 56: TargetCompID
* 268: NoMDEntries
* 269: MDEntryType
* 270: MDEntryPx
* 279: MDUpdateAction (0 = New, 1 = Change, 2 = Delete)
* */
/**
* Ajout prix Bid au message
* */
group.setString(48, marketPrice.getISIN());
group.setString(22, "4");
group.setString(279, "0");
group.setString(269, "0");
group.setString(270, marketPrice.getBid_kech().toString());
message.addGroup(group);
/**
* Ajout prix Ask au message
* */
group.setString(48, marketPrice.getISIN());
group.setString(22, "4");
group.setString(279, "0");
group.setString(269, "1");
group.setString(270, marketPrice.getAsk_kech().toString());
message.addGroup(group);
return message;
}
}
I cannot see what I'm doing wrong as my parameter send is set to true after the Publish method is called. Can anyone help me with this issue? Many thanks in advance !
Just changed publication to CUSIP instead of ISIN
Related
I'm writing a very basic program in java but I get the error "error: cannot find symbol".
It's driving me crazy because I really don't know what I did wrong this time.
Here is the code of the main class
package glaces.tests;
import geometrie.Point ;
import glaces.Iceberg2D;
public class TestIceberg2D {
public static void main (String[] args){
Iceberg2D i1 = new Iceberg2D(new Point(2,3), new Point(6,7));
Iceberg2D i2 = new Iceberg2D(new Point(3,7), new Point(5,9));
Iceberg2D i3 = new Iceberg2D(i1,i2);
System.out.println(i3.toString());
}
}
Here is the class Iceberg2D :
package glaces;
import geometrie.Point;
import java.lang.Math;
/**
* Un iceberg rectangulaire
* #author Martine Gautier, Université de Lorraine
*/
public class Iceberg2D {
private Point enBasAGauche ;
private Point enHautADroite ;
/**
* Construction
* #param g le coin en bas à gauche
* #param d le coin en haut à droite
* uniquement en coordonnées positives
*/
public Iceberg2D(Point g, Point d) {
this.enBasAGauche = g;
this.enHautADroite = d;
}
/**
* Construction par fusion de deux icebergs qui se touchent
* #param i1 premier iceberg à fusionner
* #param i2 deuxième iceberg à fusionner
*/
public Iceberg2D(Iceberg2D i1, Iceberg2D i2) {
this.enBasAGauche = new Point (Math.min(i1.coinEnBasAGauche().getAbscisse(),i2.coinEnBasAGauche().getAbscisse()),Math.min(i1.coinEnBasAGauche().getOrdonnee(),i2.coinEnBasAGauche().getOrdonnee()));
this.enHautADroite = new Point (Math.max(i1.coinEnHautADroite().getAbscisse(),i2.coinEnHautADroite().getAbscisse()),Math.max(i1.coinEnHautADroite().getOrdonnee(),i2.coinEnHautADroite().getOrdonnee()));
}
/**
* Retourne le coin en bas à gauche
* #return le coin en bas à gauche
*/
public Point coinEnBasAGauche() {
return this.enBasAGauche ;
}
/**
* Retourne le coin en haut à droite
* #return le coin en haut à droite
*/
public Point coinEnHautADroite() {
return this.enHautADroite ;
}
/**
* Retourne la hauteur
* #return hauteur
*/
public double hauteur() {
return Math.abs(enHautADroite.getOrdonnee()-enBasAGauche.getOrdonnee());
}
/**
* Retourne la largeur
* #return largeur
*/
public double largeur() {
return Math.abs(enHautADroite.getAbscisse()-enBasAGauche.getAbscisse());
}
/**
* Retourne la surface totale
* #return surface totale
*/
public double surface() {
return hauteur()*largeur() ;
}
/**
* Retourne vrai si il y a une collision entre les deux icebergs
* #param i iceberg potentiellement en collision
* #return vrai si collision entre les deux icebergs
*/
public boolean collision(Iceberg2D i) {
if(this.enBasAGauche.getAbscisse() + largeur() == i.enBasAGauche.getAbscisse() || i.enBasAGauche.getAbscisse() + i.largeur() == this.enBasAGauche.getAbscisse()){
if(this.enBasAGauche.getOrdonnee() + hauteur() >= i.coinEnBasAGauche().getOrdonnee() && i.enBasAGauche.getOrdonnee() + i.hauteur() >= this.coinEnBasAGauche().getOrdonnee()){
return true;
}}
if(this.enBasAGauche.getOrdonnee() + hauteur() == i.enBasAGauche.getOrdonnee() || i.enBasAGauche.getOrdonnee() + i.hauteur() == this.enBasAGauche.getOrdonnee()){
if(this.enBasAGauche.getAbscisse() + largeur() >= i.coinEnBasAGauche().getAbscisse() && i.enBasAGauche.getAbscisse() + i.largeur() >= this.coinEnBasAGauche().getAbscisse()){
return true;
}
}
return false ;
}
/**
* Retourne vrai si this est plus volumineux que i
* #param i iceberg à comparer
* #return vrai si this est plus volumineux que i
*/
public boolean estPlusGrosQue(Iceberg2D i) {
return this.surface() > i.surface();
}
public String toString() {
return "Point bas gauche : "+enBasAGauche.toString()+" / Point haut droite : "+enHautADroite.toString() ;
}
/**
* Retourne le point au centre
* #return le point au centre de l'iceberg
*/
public Point centre() {
return new Point((enBasAGauche.getAbscisse()+enHautADroite.getAbscisse())/2,(enBasAGauche.getOrdonnee() +enHautADroite.getOrdonnee())/2);
}
/**
* Réduction dans les quatre directions ; le centre ne bouge pas
* #param fr dans ]0..1[ facteur de réduction
*/
public void fondre(double fr) {
fr = fr/2;
double hauteur = hauteur();
double largeur = largeur();
enBasAGauche.deplacer(largeur*fr,hauteur*fr);
enHautADroite.deplacer(-largeur*fr,-hauteur*fr);
}
/**
* Casser une partie à droite
* #param fr dans ]0..1[ facteur de réduction
*/
public void casserDroite(double fr) {
fr = fr/2;
enHautADroite.deplacer(-largeur()*fr,0);
}
/**
* Casser une partie à gauche
* #param fr dans ]0..1[ facteur de réduction
*/
public void casserGauche(double fr) {
fr = fr/2;
enBasAGauche.deplacer(largeur()*fr,0);
}
/**
* Casser une partie en haut
* #param fr dans ]0..1[ facteur de réduction
*/
public void casserHaut(double fr) {
fr = fr/2;
enHautADroite.deplacer(0,-hauteur()*fr);
}
/**
* Casser une partie en bas
* #param fr dans ]0..1[ : définit le pourcentage supprimé
*/
public void casserBas(double fr) {
fr = fr/2;
enBasAGauche.deplacer(0,hauteur()*fr);
}
}
here is the error I get :
javac -classpath ../ressourcesBPO/geometrie.jar -encoding "iso-8859-1" glaces/tests/TestIceberg2D.java
glaces/tests/TestIceberg2D.java:3: error: cannot find symbol
import glaces.Iceberg2D;
^
symbol: class Iceberg2D
location: package glaces
glaces/tests/TestIceberg2D.java:9: error: cannot find symbol
Iceberg2D i1 = new Iceberg2D(new Point(2,3), new Point(6,7));
^
symbol: class Iceberg2D
location: class TestIceberg2D
glaces/tests/TestIceberg2D.java:9: error: cannot find symbol
Iceberg2D i1 = new Iceberg2D(new Point(2,3), new Point(6,7));
^
symbol: class Iceberg2D
location: class TestIceberg2D
glaces/tests/TestIceberg2D.java:10: error: cannot find symbol
Iceberg2D i2 = new Iceberg2D(new Point(3,7), new Point(5,9));
^
symbol: class Iceberg2D
location: class TestIceberg2D
glaces/tests/TestIceberg2D.java:10: error: cannot find symbol
Iceberg2D i2 = new Iceberg2D(new Point(3,7), new Point(5,9));
^
symbol: class Iceberg2D
location: class TestIceberg2D
glaces/tests/TestIceberg2D.java:58: error: cannot find symbol
Iceberg2D i3 = new Iceberg2D(i1,i2);
^
symbol: class Iceberg2D
location: class TestIceberg2D
glaces/tests/TestIceberg2D.java:58: error: cannot find symbol
Iceberg2D i3 = new Iceberg2D(i1,i2);
^
symbol: class Iceberg2D
location: class TestIceberg2D
7 errors
This is my folder tree view
thanks in advance !!!
Ok so I found the solution but I have absolutely no idea why it works.
Here is what I typed in the terminal :
javac -classpath ../ressourcesBPO/geometrie.jar:. -encoding "iso-8859-1" glaces/tests/TestIceberg2D.java
I added :. after the .jar
Why it worked ? I have absolutely no idea so, if someone wants to explain it would be much appreciated. Thanks a lot btw for trying to help !
Since your test is using the Iceberg2D class, you will first need to compile that and then point javac to its location as part of the classpath, or compile both sources at the same time.
Based on your directory structure, the first would be (assuming you’re in the top-level java directory):
javac -cp ../ressourcesBPO/geometrie.jar -d java java/glaces/Iceberg2D.java
javac -cp ../ressourcesBPO/geometrie.jar:. -d java java/glaces/test/TestIceberg2D.java
The point is that you need to add the top-level path of your *.class files to the classpath (i.e. where Java would search for the compiled file glaces/Iceberg2d.class) — and that is the current directory (i.e. .).
However, that’s ending up mixing compiled and source files, and makes everything more complicated than necessary. A more conventional Java project structure would have this outline:
projectname/
╰── build/
╰── classes/
├── main/
╰── test/
├── lib/
│ ╰── geometrie.jar
╰── src/
├── main/
│ ╰── java/
│ ╰── glaces/
│ ╰── Iceberg2D.java
╰── test/
╰── java/
╰── glaces/
╰── TestIceberg2D.java
This simplifies the build command somewhat, and prevents cluttering your source tree:
shopt extglob # requires Bash to run!
javac -d build/classes/main -cp lib/geometrie.jar src/main/java/**/*.java
javac -d build/classes/test -cp lib/geometrie.jar:build/classes/main src/test/java/**/*.java
Furthermore, this is also the directory structure used by modern Java build systems such as Gradle. Using the latter, you could create a minimal build configuration (using gradle init) and then run gradle test to build your entire main source tree, the test source tree, and then run the tests.
A final note, I know it’s extremely common to program “in French” at University in France (been there, done the same) but I strongly recommend consistently using English when writing code. Names matter for code comprehension and mixing different languages when working with other libraries makes everything confusing. It also means that only French-speaking people can read or use your code. This means asking questions (e.g. here on Stack Overflow) gets harder, but also that you can’t usefully distribute your code once you write something cool and want to share it.
I record audio using android AudioRecord class with success and to make it play with all players i add AAC ADTS headers with success and concatenated all in MPEG 2 TS (.ts) file and it's able to play with all players (native an VLC).
But unfortunately this file is not ISOMEDIA compliant to dashing with GPAC. I try to look at a solution and i found that i need to add PES headers to my ES stream.
please can't someone know how to add PES headers on top of ADTS headers in MPEG 2 TS using java ? on code below ?
enter code here
private void addADTStoPacket(byte[] packet, int packetLen) {
int profile = 2; //AAC LC //39=MediaCodecInfo.CodecProfileLevel.AACObjectELD;
int freqIdx = 4; //44.1KHz
int chanCfg = 2; //CPE
// fill in ADTS data
packet[0] = (byte)0xFF; // conversion hexadecimal a decimal - il y a seize unités de 0 à F, on parle donc d'hexadécimal.
packet[1] = (byte)0xF1; // installe l'entete ADTS dans MPEG-2 (0xF1) au lieu de MPEG-4 (0xF9)
packet[2] = (byte)(((profile-1)<<6) + (freqIdx<<2) +(chanCfg>>2));
packet[3] = (byte)(((chanCfg&3)<<6) + (packetLen>>11));
packet[4] = (byte)((packetLen&0x7FF) >> 3);
packet[5] = (byte)(((packetLen&7)<<5) + 0x1F);
packet[6] = (byte)0xFC; // 0xFC est également correct si vous ne connaissez pas la valeur de la plénitude du tampon
}
I'm doing internships with a small project that asks the user to select a category of expenses, to later request quantities that are stored in a ArrayList and finally the amount of the total expenses of that category is printed on the screen. The problem comes at the moment in which I associate the variable 'quantity' with a Scanner entry, at that moment the execution thread remains in Execution and it does not return any type of error.
package gestioneconomica;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Scanner;
/**
*
* #author Robin
*/
class Gastos {
//Declaración de los tipos de gastos organizados en ArrayList()
ArrayList<Double> taberna=new ArrayList<>();
ArrayList<Double> tPublico=new ArrayList<>();
ArrayList<Double> alimentacion=new ArrayList<>();
ArrayList<Double> formacion=new ArrayList<>();
//Declaración e inicialización de la suma de los valores de cada ArrayList()
double sumTaberna=0.0;
double sumTPublico=0.0;
double sumAlimentacion=0.0;
double sumFormacion=0.0;
//Instanciación del objeto 'sc' de la clase Scanner
Scanner sd=new Scanner(System.in);
//*************THE NEXT LINE CAUSES THE ERROR****************
double quantity=sd.nextDouble();
//Declaración e inicialización de métodos
public void addTaberna(){
System.out.print("Ingrese importe: ");
while(quantity!=0){
taberna.add(quantity);
}
System.out.print("El total consumido en esta categoría es de: ");
Iterator <Double> itTaberna=taberna.iterator();
while(itTaberna.hasNext()){
System.out.println(itTaberna.next());
}
}
public void addtPublico(){
System.out.print("Ingrese importe: ");
while(quantity!=0){
tPublico.add(quantity);
}
Iterator <Double> itTPublico=tPublico.iterator();
while(itTPublico.hasNext()){
sumTPublico+=itTPublico.next();
}
System.out.println("Gastos totales en Transporte Público: " + sumTPublico);
}
public void addAlimentacion(){
System.out.print("Ingrese importe: ");
alimentacion.add(sd.nextDouble());
}
public void addFormacion(){
System.out.print("Ingrese importe: ");
formacion.add(sd.nextDouble());
}
}
//THIS IS THE DRIVER CLASS
package gestioneconomica;
import java.util.Scanner;
class GastosExe{
public static void main(String[]args){
System.out.println("###################################################");
System.out.println("BIENVENIDO/A AL PROGRAMA DE GASTOS DE ROBIN");
System.out.println("###################################################");
System.out.println("(1)TABERNA\t(2)TRANSPORTE PÚBLICO\t(3)ALIMENTACIÓN\t (4)INVERSIÓN FORMATIVA");
System.out.println("Seleccione el tipo de Gasto: ");
Gastos gastos=new Gastos();
Scanner sc=new Scanner(System.in);
int tipo=sc.nextInt();
switch(tipo){
case 1:
System.out.println("Ha seleccionado Taberna");
gastos.addTaberna();
break;
case 2:
System.out.println("Ha seleccionado Transporte Público");
break;
case 3:
System.out.println("Ha seleccionado Alimentación");
gastos.addAlimentacion();
break;
case 4:
System.out.println("Ha seleccionado Inversión Formativa");
gastos.addFormacion();
break;
}
}
}
Welcome to SO. This is a very nicely phrased first question.
at that moment the execution thread remains in Execution and it does
not return any type of error
That's because there is no error here. And the correct term is "at the moment the execution thread (main thread) remains blocked" Your program is behaving exactly the way you coded it to behave
Let's break it down from the main method.
Gastos gastos=new Gastos();
When you call the Gastos constructor here on the main method, the Gastos class initializes, which has the quantity field of type double, initialized directly with the input from the Scanner.
When execution reaches this line double quantity = sd.nextDouble(); it blocks the main thread, waiting for keyboard input from the user..
So you should enter a selection here 1
when you press enter, sd.nextDouble(); method returns, and main thread resumes.
Then, when the Gastos() constructor call returns and the main thread reaches this line int tipo = sc.nextInt();
Which blocks the main thread again, waiting for another keyboard input from the user.
So you should enter a selection here again 2
When you press enter, sc.nextInt(); method returns and the main thread resumes execution
Sample run
###################################################
BIENVENIDO/A AL PROGRAMA DE GASTOS DE ROBIN
###################################################
(1)TABERNA (2)TRANSPORTE PÚBLICO (3)ALIMENTACIÓN (4)INVERSIÓN FORMATIVA
Seleccione el tipo de Gasto:
1
2
Ha seleccionado Transporte Público
try:
double quantity = Double.parseDouble(sd.nextLine());
I'm trying to figure out how to best parse the following log file, splitting each section seperated by the horizontal lines and extract various pieces of data, e.g. 'COMPANY123', 'BIMMU', the date (2/18 etc.) and then create a string containing all of the other data contained in a section delimited by the horizontal lines.
I.e., I want to create an array of 'statement' objects each with the following attributes:
Company name, Account, Date, Data.
E.g. for the second record below,
Account = 'BIMMU'
Firm = 'Super Corporation'
Date= 9/14/11
Data = '* * * * * * * * TODAYS ACCOUNT ACTIVITY * * * * * * * * * * *
9/14/11 Y9 CALL OESX OCT 11 ........ etc'
The log is a fixed-width text file and the variables (date etc.) always occur at the same position in the line, e.g. sSalesCode = line.substring(142, 147);
Should I maybe do this in two passes, e.g. split the code into sections delimited by the horizontal line, and then parse these sections individually?
Just writing this out here has helped me get my train of thought, but if anybody else has any smart ideas then it would be great to hear them.
------------------------------------------------------------------------------------------------------------------------------------F BIASPBIMMU
BIMMU BIASP-COMPANY123 KG (Z ) 9/14/11 EU (T- I- ) MT-0 F BIASP²BIMMU
CALLS 2/18 YI 50.00-X (49) F BIASP²BIMMU
------------------------------------------------------------------------------------------------------------------------------------F BIASPBIMMU
BIMMU BIMM2-SUPER CORPORATION KG (Z ) 9/14/11 EU (T- I- ) MT-0 F BIMM2²BIMMU
F BIMM2²BIMMU
* * * * * * * * * * * * * * * * * * * T O D A Y S A C C O U N T A C T I V I T Y * * * * * * * * * * * * * * * * * * * *F BIMM2²BIMMU
9/14/11 Y9 500 GO CALL OESX OCT 11 2400 9.60 EU .00 F BIMM2²BIMMU
GO-PARFSecurities Ser F BIMM2²BIMMU
Y9 * 500 * COMMISSIONS EU 250.00- F BIMM2²BIMMU
Y9 PERTES & PROFITS NETS EU 250.00- F BIMM2BIMMU
CALLS 9/14 E1 17,825.00-H ( 1) F BIMM2²BIMMU
CALLS 9/14 E1 17,825.00-N ( 1) F BIMM2²BIMMU
-----------------------------------------------------------------------------------------------------------------------------------
You can try to use framework Fixedformat4j. It uses annotations and works fast. I have implemented it partially for my project to understand how it works.
You can create class with annotations like this:
#Record
public class LogRecord {
private String firm;
private String user;
private Date logonDate;
private String logData;
public String getFirm() {
return firm;
}
#field(offset=10, length=10)
public void setFirm(String firm) {
this.firm = firm;
}
public String getUser() {
return user;
}
#field(offset=0, length=10)
public void setUser(String user) {
this.user = user;
}
public Date getLogonDate() {
return logonDate;
}
#field(offset=nn, length=8)
#FixedFormatPattern("mm/dd/yy")
public void setLogonDate(Date logonDate) {
this.logonDate = logonDate;
}
public String getLogData() {
return logData;
}
#field(offset=mm, length=yy)
public void setLogData(String logData) {
this.logData = logData;
}
}
And then instantiate it with FixedFormatManager.
i had similar problem recenly, i ended up using Flapjack (Google Code: Flapjack)... See the examples on google code, i guess it should help you out.
I have a problem with a JSP file. I want to retrieve the header but I have an error:
Une erreur s'est produite à la ligne: 45 dans le fichier jsp: /logTest.jsp
Enumeration cannot be resolved to a type
42: String headerString = "";
43: String name = "";
44:
45: for (Enumeration en = request.getHeaderNames(); en.hasMoreElements(); ) {
46: name = (String)en.nextElement();
47: headerString = headerString + name + "=<B>" + request.getHeader(name) + "</B><BR>";
48: }
My object (request) is not null so I don't understand why I have this error.
Can you help me ?
Thanks.
You have to explicitly import java.util.Enumeration. The stack trace gave you the answer: "Enumeration cannot be resolved to a type".