Results 1 to 3 of 3

Thread: Missing code

  1. #1
    LukasHopkins is offline Member
    Join Date
    Aug 2012
    Posts
    6
    Rep Power
    0

    Default Missing code

    Hello, I am struggling with this assingment. The balance in this code prints 0.0 Why does this happen How can I fix that problem? Then the next part asks me to add println methods to the main function to show that the problem is fixed for all entries made into Mr. Partridge's account. Can anyone assist me with this?? Thanks!!


    class User {

    private int accountID, routingNum;
    private float balance, lastDepositAmount, lastWithdrawalAmount;
    private String[] info = new String[9]; //info(0) = First name, info(1) = middle name,
    //info(2) = Last Name, info(3) = Street Address,
    //info(4) = State, info(5) = Zip Code, info(6) = Tel
    //info(7) = email address, info(8) = Description
    private String creationDate, terminationDate;
    private String lastDepositDate, lastWithdrawalDate;

    static void getBalance(User user) {
    System.out.println(user.balance);
    }

    static void getCreationDate(User user) {
    System.out.println(user.creationDate);
    }

    static void setCreationDate(User user, String date) {
    user.creationDate = date;
    }

    static void setTerminationDate(User user, String date) {
    user.terminationDate = date;
    }

    static void getTerminationDate(User user) {
    System.out.println(user.terminationDate);
    }

    static void setInfo(User user, String... input) {
    for (int i = 0; i < input.length; i++) {
    user.info[i] = input[i];
    }
    //for(int i=0;i<input.length;i++){System.out.println(input[i]);}
    }

    static void getInfo(User user) {
    for (int i = 0; i < user.info.length; i++) {
    System.out.println(user.info[i]);
    }
    }

    static void setDeposit(User user, float deposit, String date) {
    user.balance += deposit;
    user.lastDepositAmount = deposit;
    user.lastDepositDate = date;
    }

    static void setWithdrawal(User user, float withdrawal, String date) {
    if (withdrawal > user.balance) {
    System.out.println("Withdrawal amount exceeds balance.");
    } else {
    user.balance -= withdrawal;
    user.lastWithdrawalAmount = withdrawal;
    user.lastWithdrawalDate = date;
    }
    }

    static void setAccountID(User user, int accountNum) {
    user.accountID = accountNum;
    }

    static void getAccountID(User user) {
    System.out.println(user.accountID);
    }

    static void setRoutingNum(User user, int routing) {
    user.routingNum = routing;
    }

    static void getRoutingNum(User user) {
    System.out.println(user.routingNum);
    }

    static void getLastDeposit(User user) {
    System.out.println("Date of Deposit: " + user.lastDepositDate + " Amount " + user.lastDepositAmount);
    }

    static void getLastWithdrawal(User user) {
    System.out.println("Date of Withdrawal " + user.lastWithdrawalDate + " Amount " + user.lastWithdrawalAmount);
    }
    }

    class C3p4 {

    public static void main(String[] args) {
    User user1 = new User();
    createAccount();
    user1.getBalance(user1);
    }

    static void createAccount() {
    User user1 = new User();
    User.setAccountID(user1, 1234567);
    User.setRoutingNum(user1, 9872345);
    User.setInfo(user1, "John", "C", "Partridge", "123 Liberty Way", "VA", "24502", "555-3456", "jcpartri@liberty.edu", "This is a new account holder.");
    User.setDeposit(user1, 500.00f, "01/01/2010");
    User.setCreationDate(user1, "01/01/2010");


    }
    }

  2. #2
    milovan is online now Senior Member
    Join Date
    Jan 2011
    Location
    Belgrade, Serbia
    Posts
    295
    Rep Power
    4

    Default Re: Missing code

    At the moment I can see you have made two User instances

    public static void main(String[] args) {
    User user1 = new User();
    createAccount();
    user1.getBalance(user1);
    }

    static void createAccount() {
    User user1 = new User(); // you shouln't do this, User is already declared in the class.
    ...

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default Re: Missing code

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. org.j3d is missing...
    By LinuxDev@Flanders in forum Java Gaming
    Replies: 3
    Last Post: 07-23-2012, 12:31 PM
  2. What am I missing here?
    By PuppetJacks in forum New To Java
    Replies: 4
    Last Post: 07-01-2012, 11:16 AM
  3. What am I missing here..?
    By andrew_smiley in forum New To Java
    Replies: 5
    Last Post: 02-22-2012, 01:47 PM
  4. Replies: 2
    Last Post: 03-03-2011, 06:55 PM
  5. Missing Elements
    By princess in forum NetBeans
    Replies: 1
    Last Post: 10-29-2008, 11:51 PM

Posting Permissions

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