Results 1 to 8 of 8

Thread: hey

  1. #1
    k3boi is offline Member
    Join Date
    Nov 2008
    Posts
    4
    Rep Power
    0

  2. #2
    k3boi is offline Member
    Join Date
    Nov 2008
    Posts
    4
    Rep Power
    0

    Default can someone look at my java code for an ATM and analyze/correct it

    /*
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    */

    package jtest;
    import java.io.*;
    import java.util.*;


    class Bank{
    protected int PIN; //notice the change in the access modifiers
    protected double current_bal;
    protected double trans_amount;
    public String acct_name;
    public int get_PIN(){
    return(PIN);
    }
    private void readfile()throws IOException{//for reading from the file
    Scanner s = null;
    //String S_PIN;
    try {
    s = new Scanner(new BufferedReader(new FileReader("filefullofmoney.txt")));
    PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("filefullofmoney.txt")));
    String d;

    while ((s.hasNext()) ||(s.hasNextInt()) ) {
    acct_name = s.nextLine();//this reads the entire line and puts it as the acct name
    PIN = s.nextInt();

    System.out.println(acct_name);
    System.out.println(PIN);
    //im trying to store each line and specify them into pins, names, and bals.


    }
    } finally {
    s. close();
    }

    }
    public double inquiry(){
    return (current_bal);
    }
    public void deposit(){
    current_bal += trans_amount;
    }

    public void withdraw() {
    current_bal -= trans_amount;
    }

    public void inquiry(String str){
    System.out.println(str + current_bal);
    }
    public void set_transamount(double amount) {
    trans_amount = amount;
    }
    }

    class Teller extends Bank{
    public Teller(String user_name, int user_pin, double user_startbal) {
    PIN = user_pin;
    current_bal = user_startbal;
    acct_name = user_name;
    }

    public void New_acct(){
    String tempacct_name;
    System.out.println("Create a new account\n type in the desired name, pin, and balance seperated by spaces for the account:\n");
    Scanner sacct_name = new Scanner (System.in);
    tempacct_name = sacct_name.next(); //store name from input but its temporary to check if name already exists
    int pin_acc = sacct_name.nextInt();//store pin from input
    int bal_acc = sacct_name.nextInt();//store balance from input
    System.out.println(tempacct_name);//just printing the values
    System.out.println(pin_acc);//""""""""
    System.out.println(bal_acc);//""""""""
    int i=0;
    for(i = 0;i<100;i++){
    if(tempacct_name.equals(acct_name)){
    System.out.println("That account name already exists");
    //to check if user name already exists
    }
    else{
    System.out.println("Account name is: \n"+ acct_name);
    System.out.println("Type in the desired password/PIN\n");
    Scanner sacct_PIN = new Scanner (System.in);
    PIN = sacct_PIN.nextInt();
    System.out.println("Account PIN is: \n"+ PIN);
    }
    }}}
    class ATM extends Bank {


    public ATM() {
    Scanner sc = new Scanner(System.in);

    }


    }


    public class Main {

    /**
    * @param args the command line arguments
    */
    public static void main(String[] args) {
    //Overloaded constructors for initialization of object
    // ATM account1 = new ATM(1234, 100);
    //ATM account1 = new ATM(1234);
    //ATM account1 = new ATM();
    int PIN_val = 0, menu_val = 0, choice, tell_choice;
    double amnt= 0 ;


    System.out.println("Welcome to 2SH4 ATM OO Model\n 1. For Teller operations\n 2. For ATM operations\n");

    try{
    Scanner schoice = new Scanner (System.in);
    choice = schoice.nextInt();//scanner for choice of type of user
    switch(choice) {
    case 1://for a bank teller
    System.out.println("Bank Teller selected\n1. To create a new account\n2. To deposit\n3. Withdraw\n4. Display balance\n");
    tell_choice = schoice.nextInt();//get choice
    switch(tell_choice){
    case 1://create account
    System.out.println("Create account");
    Teller a = new Teller;
    //nAcc = a.New_acct();
    break;
    case 2://Deposit
    System.out.println("Deposit");
    break;
    case 3://Withdraw
    System.out.println("Withdraw");
    break;
    case 4://Inquiry
    System.out.println("Display");
    break;
    }
    break;
    case 2://to use ATM functions
    System.out.println("ATM selected");
    break;
    default:
    System.out.println("Invalid menu entry: " + choice);
    break;
    }
    }catch (InputMismatchException e) {
    System.out.println("Mismatch exception:" + e);
    }
    }}

    // Create a scanner to read from keyboard
    // Scanner overcomes problems with System.in.read()


    thanks in advance

  3. #3
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    7

    Default Suggestions...

    First some suggestions...
    • Next time, use a meaningful title for your post. "hey" doesn't help anybody know what your post is about and therefore you may receive less help.
    • Use the code wraps (the # button) when posting code.
    • Please specify what the problem is with your code. The forum can't read your mind and unfortunately it doesn't come equipped with a crystal ball.
    • Reading the following document will both help getting and giving help on this forum:
      How To Ask Questions The Smart Way

    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

  4. #4
    fishtoprecords's Avatar
    fishtoprecords is offline Senior Member
    Join Date
    Jun 2008
    Posts
    571
    Rep Power
    6

    Default

    Among your many errors, you are using a double for money. That is a sin.

    Put in some effort, tell us where you are having problems.

    This is not a "do your homework for you" forum.

  5. #5
    k3boi is offline Member
    Join Date
    Nov 2008
    Posts
    4
    Rep Power
    0

    Default

    thanks for your replies
    and i am sort off new to programming done a bit with C and C sharp

    my code is supposed to be an implementation of a Bank machine that has a teller class (that does everything the ATM does but can also create accounts) and an ATM class that deposits, withdraws and displays balance
    ok my main error is at
    Teller a = new Teller;
    //nAcc = a.New_acct();
    break;

    my teller is supposed to be able to create new accounts, and i was trying to instantiate a new object with the teller class and make a new account each time(max of about 100 accounts)

    im just too confused to even know what i want to do

    Thanks in advance

  6. #6
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    7

    Default easy...

    • I would suggest that you write it down on paper and then implement it in the program. Go one step at a time. Once you get one part working, implement the next step. If you try to do it all in one big step/effort, yes you will become overwhelmed and it will become confusing and seem impossible to do.
    • I would also suggest reviewing the concept of inheritance and extending classes (which you're trying to do in this particular case):

    Inheritance (The Java™ Tutorials > Learning the Java Language > Interfaces and Inheritance)

    Luck,
    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

  7. #7
    Nicholas Jordan's Avatar
    Nicholas Jordan is offline Senior Member
    Join Date
    Jun 2008
    Location
    Southwest
    Posts
    1,018
    Rep Power
    7

    Lightbulb various tips.

    Quote Originally Posted by k3boi View Post
    thanks for your replies
    and i am sort off new to programming done a bit with C and C sharp
    .....
    im just too confused to even know what i want to do
    Per ftr and CJSLMAN - plus no void anything anywhere and everything is signed, except for char for which unsigned makes no sense here. Everything goes in a class, which has some similar behaviour with struct in C

    Suggest start by reading docs ( which is comments with minimal html parsing ) for class BigDecimal.... it took me under a month to transition from C/C++ to Java, very powerful libs freely available - skip gc as there is no way to do the pointer casts even semi-portably and makes for beginner blunders, no end. Pointers ( of which there are none in Java ) are called references but the use thereof gets buried during beginner sample code. Strings are said to be immutable, but one can use assignment op to point the string somewhere else.

    For pw, use only hash and char[] + do char[++index] = ' ';// page-outs not controllable

    This better be student work. + "Java Tips" in the nav bar at left has an abundance of cannonical Java work.
    Introduction to Programming Using Java.
    Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor

  8. #8
    k3boi is offline Member
    Join Date
    Nov 2008
    Posts
    4
    Rep Power
    0

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •