Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Why my Java Project don't work?

  1. #1
    Junior Member
    Join Date
    Sep 2021
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Why my Java Project don't work?

    Hello to everybody, First, I present myself: I am a french, I live in Paris and right now I am doing a training in Java programming language here in Paris to become a Java developer.My first language speaking is french but I prefer studying Java in English because it's more complete and I like English language.
    Well I have a project in Java: Managing a bank account.It's written(the comments) in french but I try to translate in English.
    The IDE used is Eclipse.
    The fist java file is:
    import java.util.*;
    public class Projet {
     public static void main (String [] args) {
      byte choix;
      char typeCpte ='\0';
      double val_courante = 0.0, rate = 0.0;
      long numéroCpte = 0, numéroLu = 0 ;
      Scanner Clavier = new Scanner(System.in);
      System.out.println("                               WELCOME TO THE BANK.");
      System.out.println("1. Create an account");
      System.out.println("2. Viewing an Account");
      System.out.println("3. Write an accounting line");
      System.out.println("4.Log out");
      System.out.println("5.Help");
      System.out.println();
      System.out.print("Your choise: ");
      choise = Clavier.nextByte();
      //Option 1
      System.out.print("Account type [Possible types : ");
      System.out.print("C(current), J(oint), E(savings)] :");
      typeCpte = Clavier.next().charAt(0);
      System.out.print("Account number :");
      numberCpte = Clavier.nextLong();
      System.out.print("First credited value  :");
      val_courante = Clavier.nextDouble();  //current value
      //If savings accout
      System.out.print("Placement rate :     ");
      rate = Clavier.nextDouble();
      //Option 2
      //asks the user to enter the account number to display
      System.out.print ( " Which account would you like to view ? : ");
      numberRead= Clavier.nextLong();
      //If the account number exists, 
      System.out.print("The account n° : " + numberCpte + " is an account ");
      // displays its rate in the case of a savings account.
      System.out.println("savings whose rate is " + taux);
      System.out.println("First credited value : " + val_courante);
      // Otherwise, it displays a message indicating that the account number is not valid.
      System.out.println("The system does not know the account " + numéroLu);
      //Option 3, the program displays "option not programmed"
      System.out.println("Option not programmed");
      //Option 4,  the program ends its execution
      System.out.println("Goodbye and see you soon");
      // System.exit(0) ;    
      // Option 5
      // the program displays an explanation line for each option
      // from the main menu.
      System.out.println("Option 1. To create a Current account enter C");
      System.out.println("          To create a Joint account enter J ");
      System.out.println("         To create a Savings account enter E");
      System.out.print("          Then, enter the account number, and"); 
      System.out.println(" its first credited value");
      System.out.println("          In the case of a savings account, enter the rate");
      System.out.println("Option 2. The system displays the data of the chosen account ");
      System.out.println("Option 3. Write an accounting line");
      System.out.println("Option 4. To exit the program");
      System.out.println("Option 5. To display help");
     }
    }

    The Account.java file is:
    package Projet;
    import java.util.*;
    public class Compte	{
     private String typeCpte ;
     protected double val_courante;
     private String numberCpte ;
     private LigneComptable []ligne;
     public static final int NBLigne = 10 ;
     private int nbLigneRéel ;  
      public Compte () 	{ 
            Scanner Clavier = new Scanner(System.in);
    	typeCpte = contrôleType();
    	System.out.print("Account number : ");
    	numéroCpte = Clavier.next();
    	val_courante = contrôleValinit();  
    	ligne = new LigneComptable[NBLigne];
    	nbLigneRéel = -1;
    	Clavier.close();
      }
     
      public  Compte( String type)  {
            Scanner Clavier = new Scanner(System.in);
    	if (type.equalsIgnoreCase("Epargne")) {
    		typeCpte = type;
    		System.out.print("Account number : ");
    		numéroCpte = Clavier.next();
    		val_courante = contrôleValinit();   
    		ligne = new LigneComptable[NBLigne];
    		nbLigneRéel = -1;
    		Clavier.close();
       	}
      }
      public String quelTypeDeCompte() 	{
    		return typeCpte;
      }
      public String quelNuméroDeCompte()	{
    		return numberCpte;
      }
      public double quelleValeurCourante()	{
    		return val_courante;//current value
      }
      private String contrôleType()		{
                    Scanner Clavier = new Scanner(System.in);
    		char tmpc;
    		String tmpS = "";
    		do {
    				System.out.print("Account type [Types possibles :" ); 
    				System.out.print("C(ourant), J(oint)] : ");
    				tmpc = Clavier.next().charAt(0);
    		} while ( tmpc != 'C' && tmpc != 'J' );
    		Clavier.close();
    		switch (tmpc) {
    			case 'C' : tmpS = "Courant";
    			break;
    			case 'J' : tmpS = "Joint";
    			break;
    		}
    		return tmpS;
      }
      private double contrôleValinit()	 {
                    Scanner Clavier = new Scanner(System.in);
    		double tmp, tmpval;
    		do {
    			System.out.print("Initial account value: ");
    			tmpval= Clavier.nextDouble();  
    		} while ( tmpval <= 0);
    		Clavier.close();
    		return tmpval;
     
      }
      public void créerLigne() {
    		nbLigneRéel++;
    		if (nbLigneRéel < NBLigne) 
    			ligne [nbLigneRéel] = new LigneComptable();
    		else {
    			nbLigneRéel--;
    			décalerLesLignes();
    			ligne [nbLigneRéel] = new LigneComptable();
    		}
    		val_courante = val_courante + ligne[nbLigneRéel].quelleValeur();
      }
      private void décalerLesLignes() {
    		for(int i = 1; i < NBLigne ; i++)
    		ligne[i-1] = ligne[i];
      }
      public  void afficherCpte() {
    		System.out.print("The account n° : " + numéroCpte );
    		System.out.println(" Is an account "+typeCpte);
    		if (nbLigneRéel >=0) {
    			for (int i = 0; i <= nbLigneRéel; i++) ligne[i].afficherLigne();
    		}
    		System.out.println("Valeur courante : " + val_courante);
    		if (val_courante < 0) System.out.println("Attention debtor account ... !!!");
      }
    }

    The file LigneComptable.java is:

    package projet;
     
    import java.util.Scanner;
     
    public class LigneComptable {
    	private double valeur;
    	private String date;
    	private String motif;
    	private String mode;
    	public LigneComptable()	{
                    Scanner Clavier = new Scanner(System.in);
    		System.out.print("Entrer la valeur à créditer (+) ou débiter (-) : ");
    		valeur = Clavier.nextDouble();
    		System.out.print("Date de l'opération [jj/mm/an] ");
    		date = Clavier.next();
    		motif = contrôleMotif();
    		mode = contrôleMode();
    		Clavier.close();
    	}
     
    	private String contrôleMode() {
                    Scanner Clavier = new Scanner(System.in);
    		String tmpS = "";
    		char tmpc ;
    		do {
    			System.out.print("Mode [C(B), N(° Cheque), V(irement ) ]  : ");
    			tmpc = Clavier.next().charAt(0);
    		} while ( tmpc != 'C' && tmpc != 'N' && tmpc != 'V');
    		Clavier.close();
    		switch (tmpc) {
    			case 'C' : tmpS = "CB";
    			break;
    			case 'N' : tmpS = "Cheque";
    			break;
    			case 'V' : tmpS = "Virement";
    			break;		
    		}
    		return tmpS;
    	}
    	private String contrôleMotif() {
                    Scanner Clavier = new Scanner(System.in);
    		String tmpS = "";
    		char tmpc ;
    		do {
    			System.out.print("Motif de l'operation [S(alaire),");
    			System.out.print(" L(oyer), A(limenation), D(ivers)] : ");
    			tmpc = Clavier.next().charAt(0);
    		} while ( tmpc != 'S' && tmpc != 'L' && tmpc != 'A' && tmpc != 'D');
    		Clavier.close();
    		switch (tmpc) {
    			case 'S' : tmpS = "Salaire";
    			break;
    			case 'L' : tmpS = "Loyer";
    			break;
    			case 'A' : tmpS = "Alimentation";
    			break;		
    			case 'D' : tmpS = "Divers";
    			break;
    		}
    		return tmpS;
    	}
    	public double quelleValeur() {
    		return valeur ;
    	}
    	public String quelMotif(){
    		return motif ;
    	}
    	public String quelMode(){
    		return mode ;
    	}
    	public String quelleDate(){
    		return date ;
    	}
    	public void afficherLigne()  {
    		if (valeur < 0) 
    		System.out.print("Débiter : "+valeur);
    		else
        	System.out.print("Créditer : "+valeur);
    		System.out.println(" le : "+ date +" motif  : " +motif+ " mode : "+mode);
    	}
    }
    When I execute the Projet.java I obtain:

    WELCOME TO THE BANK.
    1. Create an account
    2. Viewing an Account;
    3. Write an accounting line
    4.Log out
    5.Help"
    Your choice : when I enter 1 or 2 or 3 or 4 or 5 I obtain always the same message:
    Votre choix : 2
    Type of account [ possible Types : C(current), J(joint), E(Saving)] :
    What is wrong with those programs.Thank you in advance for your help.

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Why my Java Project don't work?

    Where does the program print this line? I do not see it?
    Votre choix : 2
    One possible problem is there should only be one Scanner that uses System.in. All the code should use that one Scanner.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Sep 2021
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Why my Java Project don't work?

    Fisrt, thank you for your answer.
    When I type 2, I obtain the same message as when I type 1:
    Type of account [ possible Types : C(current), J(joint), E(Saving)] :

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Why my Java Project don't work?

    The posted code has many compiler errors that need to be fixed so that the code can be compiled and executed for testing.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Replies: 0
    Last Post: August 2nd, 2020, 11:55 AM
  2. How to return a string from java project into android project
    By AmitShef in forum What's Wrong With My Code?
    Replies: 4
    Last Post: June 27th, 2014, 08:33 AM
  3. Replies: 1
    Last Post: April 6th, 2014, 05:16 PM
  4. Java School Project Help; Project #2, In Danger of Failing.....
    By john++ in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 2nd, 2014, 02:35 AM
  5. Long term project work from home developer
    By internext in forum Paid Java Projects
    Replies: 17
    Last Post: May 2nd, 2012, 07:51 PM