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:
When I execute the Projet.java I obtain: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); } }
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.