• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Problem while executing the program

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello to All,

I'm having a little issue while runnig the program.
Here's the explanation and the code is at the bottom ...
(I'm sorry the whole program is in french since my Java class is in French !!)

In the program the first question is "Which Day"

There is two different prices for both Weekdays and Weekends.
I'm using an IF, ELSE IF, ELSE... structure.
basically I entered If (jourSemaine == "LU){ ...

(FYI JourSemain which means weekday and LU stands for Lundi which is Monday)

The issue that I'm having is ; regardlees of the day that is enter, it looks like the program skip the appropriate instructions and go directly to the ELSE instruction, which is ok for the weekends but returns wrong values for Weekdays (LU, MA, ME, JE, VE)
as for an example, for an Adulte (Adult) the price during the week is 26$ but the program will return 29$ which is the price on the weekend.

I Also have another issue which is the Loop using a DO - While, at the end there is question that says "encore un autre traitement" which means "is there an other customer ..." the answer is by "yes or no" regardless of what I'm typing it will loop again and again.

I would really appreciate if you can help on this one
let me know what is wrong in my program !!!
Thanks in adavce
Ed

---
Here's the program

public class facturation {

// Autres m�thodes s'il y a lieu

public static void main (String[] params) {
// Bloc de D�claration
final String lundi = "LU";
final String mardi = "MA";
final String mercredi = "ME";
final String jeudi = "JU";
final String vendredi = "VE";
final String samedi = "SA";
final String dimanche = "DI";
final double prixUnitaireEnfantSemaine = 10.0;
final double prixUnitaireEtudiantSemaine = 17.0;
final double prixUnitaireAdulteSemaine = 26.0;
final double prixUnitaireAgeDorSemaine = 19.0;
final double prixUnitaireFamilleSemaine = 65.0;
final double prixUnitaireEnfantFinSemaine = 13.0;
final double prixUnitaireEtudiantFinSemaine = 19.0;
final double prixUnitaireAdulteFinSemaine = 29.0;
final double prixUnitaireAgeDorFinSemaine = 21.0;
final double prixUnitaireFamilleFinSemaine = 76.0;
final double tauxTps = 0.07;
final double tauxTvq = 0.075;
String encoreUnClientATraiter = "oui";
String jourSemaine;
double PrixUnitaireEnfant = 0.00;
double PrixUnitaireEtudiant = 0.00;
double PrixUnitaireAdulte = 0.00;
double PrixUnitaireFamille = 0.00;
double PrixUnitaireAgeDor = 0.00;
double nbBilletTotalBilletParJour = 0.00;
int nbBilletFamille = 0;
int nbBilletEnfant = 0;
int nbBilletEtudiant = 0;
int nbBilletAdulte = 0;
int nbBilletAgeDor = 0;
double montantBilletEnfant = 0.00;
double montantBilletEtudiant = 0.00;
double montantBilletAdulte = 0.00;
double montantBilletFamille = 0.00;
double montantBilletAgeDor = 0.00;
double montantTotalBillet = 0.00;
double montantTPS = 0.00;
double montantTVQ = 0.00;
double montantTotalFacture = 0.00;

// D�but de l'algorithme
do // pour chaque client
// Bloc de saisie
//jour de la semaine
{
System.out.print("Entrez le jour de la visite:");
System.out.println("LU=Lundi, MA=Mardi, ME=Mercredi, JE=Jeudi, VE=Vendredi, SA=Samedi ou DI=Dimanche");
jourSemaine = Clavier.lireString();
//Nombre de Billets pour chaque groupe d'�ge
System.out.print("Entre le nombre de billets pour laissez-passer famille:");
nbBilletFamille = Clavier.lireInt();
System.out.print("Entre le nombre de billets pour les enfants (de 10 ans et moins):");
nbBilletEnfant = Clavier.lireInt();
System.out.print("Entre le nombre de billets pour les Etudiants (de 11 a 17 ans):");
nbBilletEtudiant = Clavier.lireInt();
System.out.print("Entre le nombre de billets pour les Adultes (de 18 a 64 ans):");
nbBilletAdulte = Clavier.lireInt();
System.out.print("Entre le nombre de billets pour les Ainees (65 ans et plus):");
nbBilletAgeDor = Clavier.lireInt();
// BLOC DE CALCUL
// D�terminer le prix unitaire des billets (selon le jour de la semaine)
if (jourSemaine == "LU"){
PrixUnitaireEnfant = prixUnitaireEnfantSemaine;
PrixUnitaireEtudiant = prixUnitaireEtudiantSemaine;
PrixUnitaireAdulte = prixUnitaireAdulteSemaine;
PrixUnitaireFamille = prixUnitaireFamilleSemaine;
PrixUnitaireAgeDor = prixUnitaireAgeDorSemaine;
}
else if (jourSemaine == "MA"){
PrixUnitaireEnfant = prixUnitaireEnfantSemaine;
PrixUnitaireEtudiant = prixUnitaireEtudiantSemaine;
PrixUnitaireAdulte = prixUnitaireAdulteSemaine;
PrixUnitaireFamille = prixUnitaireFamilleSemaine;
PrixUnitaireAgeDor = prixUnitaireAgeDorSemaine;
}
else if (jourSemaine == "ME"){
PrixUnitaireEnfant = prixUnitaireEnfantSemaine;
PrixUnitaireEtudiant = prixUnitaireEtudiantSemaine;
PrixUnitaireAdulte = prixUnitaireAdulteSemaine;
PrixUnitaireFamille = prixUnitaireFamilleSemaine;
PrixUnitaireAgeDor = prixUnitaireAgeDorSemaine;
}
else if (jourSemaine == "JU"){
PrixUnitaireEnfant = prixUnitaireEnfantSemaine;
PrixUnitaireEtudiant = prixUnitaireEtudiantSemaine;
PrixUnitaireAdulte = prixUnitaireAdulteSemaine;
PrixUnitaireFamille = prixUnitaireFamilleSemaine;
PrixUnitaireAgeDor = prixUnitaireAgeDorSemaine;
}
else if (jourSemaine == "VE"){
PrixUnitaireEnfant = prixUnitaireEnfantSemaine;
PrixUnitaireEtudiant = prixUnitaireEtudiantSemaine;
PrixUnitaireAdulte = prixUnitaireAdulteSemaine;
PrixUnitaireFamille = prixUnitaireFamilleSemaine;
PrixUnitaireAgeDor = prixUnitaireAgeDorSemaine;
}
else {
PrixUnitaireEnfant = prixUnitaireEnfantFinSemaine;
PrixUnitaireEtudiant = prixUnitaireEtudiantFinSemaine;
PrixUnitaireAdulte = prixUnitaireAdulteFinSemaine;
PrixUnitaireFamille = prixUnitaireFamilleFinSemaine;
PrixUnitaireAgeDor = prixUnitaireAgeDorFinSemaine;
}
//calculer le montant des billets pour chaque groupe d'age
montantBilletEnfant = PrixUnitaireEnfant * nbBilletEnfant;
montantBilletEtudiant = PrixUnitaireEtudiant * nbBilletEtudiant;
montantBilletAdulte = PrixUnitaireAdulte * PrixUnitaireAdulte;
montantBilletFamille = PrixUnitaireFamille * nbBilletFamille;
montantBilletAgeDor = PrixUnitaireAgeDor * PrixUnitaireAgeDor;
// calculer le montant total des billets
montantTotalBillet = montantBilletEnfant + montantBilletEtudiant + montantBilletAdulte + montantBilletFamille + montantBilletAgeDor;
// calculer le montant des taxes
montantTPS = montantTotalBillet * tauxTps;
montantTVQ = (montantTotalBillet + montantTPS) * tauxTvq;
// calculer le montant total de la facture
montantTotalFacture = montantTotalBillet + montantTPS + montantTVQ;
// calculer le nombre de billets vendus par jour
nbBilletTotalBilletParJour = nbBilletTotalBilletParJour + nbBilletEnfant + nbBilletEtudiant + nbBilletAdulte + nbBilletFamille + nbBilletAgeDor;
// ajout de la date systeme

// BLOC D'AFFICHAGE

// Afficher la date
System.out.print("Nous sommes le:");

// voici le prix unitaire et le nombre de billets pour le groupe enfant
System.out.print("Vous avez achet�:" + nbBilletEnfant );
System.out.print("billets pour les enfants de 10 ans et moins");
System.out.print("le prix unitaire est:" + PrixUnitaireEnfant);
System.out.println();
// le prix unitaire et le nombre de billets pour le groupe ETUDIANT
System.out.print("Vous avez achet�:" + nbBilletEtudiant );
System.out.print("billets pour les etudiants de 11 � 17");
System.out.print("le prix unitaire est:" + PrixUnitaireEtudiant);
System.out.println();
//le prix unitaire et le nombre de billets pour le groupe ADULTE
System.out.print("Vous avez achet�:" + nbBilletAdulte );
System.out.print("billets pour les adultes de moins de 65 ans");
System.out.print("le prix unitaire est:" + PrixUnitaireAdulte);
System.out.println();
// le prix unitaire et le nombre de billets pour le groupe FAMILLE
System.out.print("Vous avez achet�:" + nbBilletFamille );
System.out.print("billets pour un laissez-passer familliale");
System.out.print("le prix unitaire est:" + PrixUnitaireFamille);
System.out.println();
//le prix unitaire et le nombre de billets pour le groupe age d'or
System.out.print("Vous avez achet�:" + nbBilletAgeDor );
System.out.print("billets pour les ainees de 65 ans et plus");
System.out.print("le prix unitaire est:" + PrixUnitaireAgeDor);
System.out.println();
//C'etait la zone d'affichage pour les billets
// Voici le total des billets
System.out.print("Le montant des billets avant taxes est de :" + montantTotalBillet);
//Le montant avec les taxes TPS en premier
System.out.print("le taux pour la tps est :" + tauxTps);
System.out.print("Le montant de la tps est :" + montantTPS);
// TVQ en second
System.out.print("le taux pour la tpq est :" + tauxTvq);
System.out.print("le montant de la tvq est :" + montantTVQ);
//Le montant de la pr�sente facture
System.out.print("le montant total de la facture :" + montantTotalFacture);
// Il faut le meme traitement plusieurs fois
// Demander � l'utilisateur du programme s'il y a d'autres clients � traiter
System.out.print("Est-ce qu'il y a un autre client a traiter : (Oui ou Non):");
encoreUnClientATraiter = Clavier.lireString();
} while (encoreUnClientATraiter != "Non");

} // main

} // facturation
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
all these
if (jourSemaine == "LU"){

should be
if (jourSemaine.equals("LU")){

(unless there's a french locale word for 'equals')
 
Eddy Ades
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks again

this works just fine now,
I had to correct a few thinks in my calculation because I was getting a really bad result !!! But now this is fine.

I have anohter question.
Since I'm using the DO - While instruction

In my program I'm trying to say Do (the whole calculation) while the answer is "oui" (which is Yes).

Regardless of what I'm typing, either oui or non
It's looping over and over.

Only once when I entered Non it stopped, but I've testing it more than 30 times and it's always looping.

DO you have any suggestion

Thanks
Ed
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
from your original code
while (encoreUnClientATraiter != "Non");

assuming you have changes this to
while (!encoreUnClientATraiter.equals("Non"));
or
while (encoreUnClientATraiter.equals("Non") == false);

the fact it worked once could indicate a capitalisation issue
i.e. "non" does not match "Non"

try this
while (encoreUnClientATraiter.equalsIgnoreCase("Non") == false);
 
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Did you change this:



to this:




If not, your while will fail for the same reason - the two strings wont be compared based on their values.
 
Eddy Ades
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks again, after making the modification, it's working just fine.

I also added the code so we can get the system date and a $ symbol and both of them are working well.

On another point
I was playing with the decimals stuff but I'm not getting what I need.
I want to specify Only 2 decimals.
What could be the easiest way to write this one down

Thanks
Ed
 
Marshal
Posts: 79239
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Decimals with two points?
Have you looked in the Formatter class, or PrintStream.printf() or String.format()?
Both the latter refer back to Formatter, and there is a long list of formatting options. You might want that with %f in. It is a bit easier to understand in the books, but you can put a . and a number to represent the number of digits after the . after the % and before the f, eg %.6f

I think that is what you want.

CR
 
Eddy Ades
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks,
I will try this.
I taught there would be a "small" command where we can specify the the number of decimals. Just like in SQL we can say something like round(...*100,2) where 2 represents the number of decimals

I will try with the formatter class, I also taught that maybe I can use the a "casting" to conver the value.
I tried a few things already but it didn't work.
 
Eddy Ades
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Forgot about my last question.
After playing with it a couple time everything is fine.

Thanks for all your help
 
reply
    Bookmark Topic Watch Topic
  • New Topic