Thread Options Help Assistance needed in java for assignment

  • (2 Pages)
  • +
  • 1
  • 2

26 Replies - 637 Views - Last Post: 04 December 2017 - 04:55 PM Rate Topic: -----

#1 Dimlead  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 12
  • Joined: 03-December 17

Thread Options Help Assistance needed in java for assignment

Posted 03 December 2017 - 10:38 AM

I need help for this assignment I'm doing for school since I can't figure out how to do it. Also I tried to fix the problem over the internet by look up for answers but I can't find any answer for my specific problem since I have some specific guideline that I have to follow for this assignment, so I thought the best idea was to post it on a forum since I'm going to get answered specifically for my problem.

These are the following guidelines that I have to follow:
You are required to write a program (java class) to create a system for a bank ATM machine.
Hard code the users for the system. Each user will have a name, password, and balance and overdraft facility. (These must all be stored in arrays.)
The user will be asked to log in to the ATM using a method which should return the position (index) of the user in the array.
Once they log in they will have a Display Menu (method) with options to View Bank Statement (method), Change Password (method), Deposit Money (method), Withdraw Money (method) and Exit (method). The menu should loop until the user chooses to Exit. (The new password cannot be a password that is already in use.)
The arrays must be updated when the user deposits or withdraws money or changes a password.
The user can only withdraw more money than they have in their account if they have an overdraft facility.
There is no limit on the overdraft.
All inputs must be validated for error checking using a method.









import java.util.Scanner;//java library class
public class Assigment2 {//start class

    //global variable
    static int creditsbalanceArray []={156,256,504};// user currency balance
   static String nameArray []={"Molly","Connor","Shane"};// user name
   static int passcodeArray []= {6543,7654,8765};// user passcode
   static int overdraftArray []={1,2,3};// user overdraft
   static int passcode;// user passcode
   static Scanner input = new Scanner(System.in);//static Scanner input
   static int index;// user index
    public static void main(String[] args) {//start main method

         showAllUsers();//show All user variable
       loginBankMachine();//login Bank Machine variable
       showAlternativeOptions();//show Alternative Options variable

   }//end main method

   //METHODOLOGY||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
   public static void showAllUsers(){//start showAllUsers method
        System.out.println("  All Users");// All Users
        System.out.println("INDEX\tNAME\t$ BAL\tPASSCODE");//user options
        for(int i=0;i<creditsbalanceArray.length;i++){//intializing credit balance Array
            System.out.println(i+"\t"+nameArray[i]+"\t"+creditsbalanceArray[i]+"\t"+passcodeArray[i]);//displaying arrays
        }// end for loop
   }//end showAllUsers method

   public static void loginBankMachine(){//start login method

        int[] accountPasscode;
        int[] d;
       int found = 0;
       System.out.println("Welcome " + d+"\nPlease Enter Passcode : ");
       int passcode = input.nextInt();

       //find the passcode in the array
       for (int i = 0;i <accountPasscode.length;i++){
           if (accountPasscode[i] == passcode ){
               found = 1;
               index = i;
               break;
           }//end if
       }//end for

       if (found == 0 ){
           System.out.println("Not found Try again");
           loginBankMachine();
       }//end if
   }//end loginATM

   public static void showAlternativeOptions(){//start ShowAlternativeOption Method
       System.out.println(" Please select one of the following options available");
        //give the user the menu
           System.out.print("\n1.View Bank Machine Produced Statment \n2.Deposit credits\n3.Withdraw credits\n4.Change Passcode\n5.Exit");//user options
           String option =input.next();//string option

           switch(option){//start switch method
               case "1":
                   BankMachineProducedStatement();break;//BankMachineProducedStatment option
               case "2":
                   System.out.println(" Deposit Credits");break;//Deposit Credits option
            case "3":
                System.out.println(" Withdraw Credits");break;//Withdraw Credits option
            case "4":
                System.out.println(" Change Passcode");break;//Change Passcode option
            case "5":
                System.out.println(" Thank you for using our bank machine");break;//Exit option
           }//end switch
   }// end ShowaAlternativeOption method

    public static void BankMachineProducedStatement(){//start BankMachineProducedStatement Method
        System.out.println(" Bank Machine Produced Statment");//Bank Machine Produced Statment Description
       System.out.println(index+"\t"+nameArray[index]+"\t"+creditsbalanceArray[index]+"\t"+passcodeArray[index]);//initalizing arrays
    }//end BankMachineProducedStatement method

    public static void DepositCredits(){//start DepositCredits Method
        System.out.println(" Credits Total");//Credits Total Description
        System.out.println(" Credit ");
        System.out.println(index+"\t"+creditsbalanceArray[index]);//initalizing arrays
    }//end DepositCredits method

    public static void WithdrawCredits(){//start WithdrawCredits Method
        System.out.println("Credits Withdrawn");//Credit Withdrawm Description
        System.out.println(index+"\t"+creditsbalanceArray[index]);//index creditsbalanceArray
    }//end WithdrawCredits method

    public static void changePasscode(){

    System.out.println("\nEnter new passcode");
        String stringpasscode=input.next();
        int passcodeArray=validateInput(passcode);
        for(int i=0;i<passcodeArray.length;i++){
            if (accountPasscode[i] == passcode){
                System.out.println("passcode taken");
                changePasscode();
            }//end if
        }//end for
    }//end changePasscode Method


    public static void Exit(){
        System.out.println("Thank you for using our bank machine");
        System.exit(0);
        }//end Exit method
       }
}//end class



Hopefully someone is able to help me finish off my work because I have to submit my assignment in soon enough, so if I could get any help regarding my problems it would be appreciated. And also can anyone tell me if I did anything wrong in my coding so I can fix it, I'm pretty new to java so I don't really know the rules.

Is This A Good Question/Topic? 0
  • +

Replies To: Thread Options Help Assistance needed in java for assignment

#2 ndc85430  Icon User is online

  • I think you'll find it's "Dr"
  • member icon

Reputation: 787
  • View blog
  • Posts: 3,201
  • Joined: 13-June 14

Re: Thread Options Help Assistance needed in java for assignment

Posted 03 December 2017 - 10:41 AM

What is the specific problem you're having? You need to give us details, as well as posting any error messages in their entirety as appropriate.
Was This Post Helpful? 0
  • +
  • -

#3 g00se  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3536
  • View blog
  • Posts: 16,028
  • Joined: 20-September 08

Re: Thread Options Help Assistance needed in java for assignment

Posted 03 December 2017 - 11:15 AM

Avoid static until you know what you're doing
http://technojeeves....is-a-swear-word
Was This Post Helpful? 0
  • +
  • -

#4 macosxnerd101  Icon User is online

  • Games, Graphs, and Auctions
  • member icon




Reputation: 12278
  • View blog
  • Posts: 45,364
  • Joined: 27-December 08

Re: Thread Options Help Assistance needed in java for assignment

Posted 03 December 2017 - 11:18 AM

Contrary to the specifications, parallel arrays are also poor practice.
Was This Post Helpful? 0
  • +
  • -

#5 Dimlead  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 12
  • Joined: 03-December 17

Re: Thread Options Help Assistance needed in java for assignment

Posted 03 December 2017 - 11:48 AM

View Postg00se, on 03 December 2017 - 11:15 AM, said:

Avoid static until you know what you're doing
http://technojeeves....is-a-swear-word


I have to use static array, it's part of my assignment, these are the problems btw:

Compilation Errors Detected

Line: 100
cannot find symbol
symbol: method validateInput(int)
location: class Assigment2

Line: 101
int cannot be dereferenced

Line: 102
cannot find symbol
symbol: variable accountPasscode
location: class Assigment2

View Postg00se, on 03 December 2017 - 11:15 AM, said:

Avoid static until you know what you're doing
http://technojeeves....is-a-swear-word



I can learn later, but right now I need to get this assignment done, even if I just don't learn anything from it and copy someone else's work, college doesn't really care about you learning new stuff, they just care about your grades, so I really need to get this work done in less than 24 hours, which is my submission date.
Was This Post Helpful? -1
  • +
  • -

#6 ndc85430  Icon User is online

  • I think you'll find it's "Dr"
  • member icon

Reputation: 787
  • View blog
  • Posts: 3,201
  • Joined: 13-June 14

Re: Thread Options Help Assistance needed in java for assignment

Posted 03 December 2017 - 11:51 AM

"Cannot find symbol" means you're trying to use something (e.g. a variable or method) before it has been declared.

The code you posted doesn't have anything on line 101, so it's not too clear where that error message is coming from. Make sure you post the code that you currently have.

Did you write all the code in one go and are only just getting to compiling it and running it now? If so, you're making life difficult for yourself. Get into the habit of working incrementally: writing small pieces of code and making sure they work before moving on. It will be easier to find and fix problems that way.

View PostDimlead, on 03 December 2017 - 06:48 PM, said:

I need to get this assignment done, even if I just don't learn anything from it and copy someone else's work


This really is not the attitude to have. The point of getting the education is for you to learn things, so you should spend time on that. In future, start doing the work earlier and if you find that you're having difficulty, you've got time to speak to the teachers about it and get help.

This post has been edited by ndc85430: 03 December 2017 - 12:06 PM

Was This Post Helpful? 0
  • +
  • -

#7 ndc85430  Icon User is online

  • I think you'll find it's "Dr"
  • member icon

Reputation: 787
  • View blog
  • Posts: 3,201
  • Joined: 13-June 14

Re: Thread Options Help Assistance needed in java for assignment

Posted 03 December 2017 - 12:14 PM

Your program also has several style issues that make it difficult to read:

1. The indentation is inconsistent. Everything inside a block (i.e. between curly braces) should be indented the same amount.

2. There isn't enough whitespace. There should be a space either side of operators like = and + and others.

3. Your method names are written inconsistently. Some of them start with an uppercase character (like WithdrawCredits) and others do not (like changePasscode). The latter is preferred, since the former is how classes are usually named, so can cause confusion if the same is used for method names.

You might want to find a style guide or at least stick to the style used by your teachers.

Also line 33: you do realise that Java has a boolean type, right? That's more meaningful for your found variable than int.
Was This Post Helpful? 0
  • +
  • -

#8 Dimlead  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 12
  • Joined: 03-December 17

Re: Thread Options Help Assistance needed in java for assignment

Posted 03 December 2017 - 05:24 PM

/**
 * @(#)Assigment2.java
 *
 *
 * @author
 * @version 1.00 2017/12/1
 */

import java.util.Scanner;//java library class
public class Assigment2 {//start class

	//global variable
	static int creditsbalanceArray []={156,256,504};// user currency balance
    static String nameArray []={"Molly","Connor","Shane"};// user name
    static int passcodeArray []= {6543,7654,8765};// user passcode
    static int overdraftArray []={1,2,3};// user overdraft
    static int passcode;// user passcode
    static Scanner input = new Scanner(System.in);//static Scanner input
    static int index;// user index
	public static void main(String[] args) {//start main method

      	showAllUsers();//show All user variable
    	loginBankMachine();//login Bank Machine variable
    	showAlternativeOptions();//show Alternative Options variable

    }//end main method

    //METHODOLOGY||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
    public static void showAllUsers(){//start showAllUsers method
		System.out.println("  All Users");// All Users
		System.out.println("INDEX\tNAME\t$ BAL\tPASSCODE");//user options
		for(int i=0;i<creditsbalanceArray.length;i++){//intializing credit balance Array
			System.out.println(i+"\t"+nameArray[i]+"\t"+creditsbalanceArray[i]+"\t"+passcodeArray[i]);//displaying arrays
		}// end for loop
    }//end showAllUsers method

    public static void loginBankMachine(){//start login method

		int[] accountPasscode;
		int[] d;
        int found = 0;
        System.out.println("Welcome " + d+"\nPlease Enter Passcode : ");
        int passcode = input.nextInt();

    	//find the passcode in the array
    	for (int i = 0;i <accountPasscode.length;i++){
    		if (accountPasscode[i] == passcode ){
    			found = 1;
    			index = i;
    			break;
    		}//end if
    	}//end for

    	if (found == 0 ){
    		System.out.println("Not found Try again");
    		loginBankMachine();
    	}//end if
    }//end loginATM

    public static void showAlternativeOptions(){//start ShowAlternativeOption Method
    	System.out.println(" Please select one of the following options available");
		//give the user the menu
	   	System.out.print("\n1.View Bank Machine Produced Statment \n2.Deposit credits\n3.Withdraw credits\n4.Change Passcode\n5.Exit");//user options
	   	String option =input.next();//string option

	   	switch(option){//start switch method
	   		case "1":
	   			BankMachineProducedStatement();break;//BankMachineProducedStatment option
	   		case "2":
	   			System.out.println(" Deposit Credits");break;//Deposit Credits option
			case "3":
				System.out.println(" Withdraw Credits");break;//Withdraw Credits option
			case "4":
				System.out.println(" Change Passcode");break;//Change Passcode option
			case "5":
				System.out.println(" Thank you for using our bank machine");break;//Exit option
	   	}//end switch
    }// end ShowaAlternativeOption method

	public static void BankMachineProducedStatement(){//start BankMachineProducedStatement Method
		System.out.println(" Bank Machine Produced Statment");//Bank Machine Produced Statment Description
    	System.out.println(index+"\t"+nameArray[index]+"\t"+creditsbalanceArray[index]+"\t"+passcodeArray[index]);//initalizing arrays
	}//end BankMachineProducedStatement method

	public static void DepositCredits(){//start DepositCredits Method
		System.out.println(" Credits Total");//Credits Total Description
		System.out.println(" Credit ");
		System.out.println(index+"\t"+creditsbalanceArray[index]);//initalizing arrays
	}//end DepositCredits method

	public static void WithdrawCredits(){//start WithdrawCredits Method
		System.out.println("Credits Withdrawn");//Credit Withdrawm Description
		System.out.println(index+"\t"+creditsbalanceArray[index]);//index creditsbalanceArray
	}//end WithdrawCredits method

	public static void changePasscode(){

	System.out.println("\nEnter new passcode");
		String stringpasscode=input.next();
		int passcodeArray=validateInput(passcode);
		for(int i=0;i<passcodeArray.length;i++){
			if (accountPasscode[i] == passcode){
				System.out.println("passcode taken");
				changePasscode();
			}//end if
		}//end for
	}//end changePasscode Method


	public static void Exit(){
		System.out.println("Thank you for using our bank machine");
		System.exit(0);
		}//end Exit method

	}
}//end class



This is the actual code, sorry for confusing you, hopefully you can still reply
Was This Post Helpful? 0
  • +
  • -

#9 ndc85430  Icon User is online

  • I think you'll find it's "Dr"
  • member icon

Reputation: 787
  • View blog
  • Posts: 3,201
  • Joined: 13-June 14

Re: Thread Options Help Assistance needed in java for assignment

Posted 03 December 2017 - 11:52 PM

I already addressed two of the issues causing the error messages at the beginning of post 6. Have you tried addressing them in your code?

As for the third one, look at lines 100 and 101. An int doesn't have a length, does it?

Are you getting any more errors now?

Also, I was somewhat reluctant to say this before, but the amount of commenting in your code is far too much. That again makes it difficult to read and you should learn to read code without the need for all that commenting, because code you see in the real world won't be commented so heavily. It's just unnecessary to repeat what the code tells you.
Was This Post Helpful? 0
  • +
  • -

#10 Dimlead  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 12
  • Joined: 03-December 17

Re: Thread Options Help Assistance needed in java for assignment

Posted 04 December 2017 - 06:36 AM

I've done static int and int, global and local variable and the problems don't go away or others problems from the same lines come up, so you'll have to look into my coding because I can't figure it out, you'll have to spoon feed me because I honestly am completely lost, and I'm also new at java so I have no clue at most of the stuff, I just look for solutions on the internet, yet my class is moving forward much faster than I thought, I've spent hours trying to fix this frustrating problems, but no luck, the variables were not mine so I had to change them so that's when I started having problems, and sorry for the comments but my teacher emphasized that we should have comments, even thought I personally dislike putting in comments.

This post has been edited by andrewsw: 04 December 2017 - 06:41 AM
Reason for edit:: removed previous quote, just use the REPLY button

Was This Post Helpful? 0
  • +
  • -

#11 g00se  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3536
  • View blog
  • Posts: 16,028
  • Joined: 20-September 08

Re: Thread Options Help Assistance needed in java for assignment

Posted 04 December 2017 - 07:16 AM

Please post the code you were given originally
Was This Post Helpful? 0
  • +
  • -

#12 macosxnerd101  Icon User is online

  • Games, Graphs, and Auctions
  • member icon




Reputation: 12278
  • View blog
  • Posts: 45,364
  • Joined: 27-December 08

Re: Thread Options Help Assistance needed in java for assignment

Posted 04 December 2017 - 07:49 AM

Let me make sure I understand- you found and modified this code? This is not your original solution?
Was This Post Helpful? 0
  • +
  • -

#13 Dimlead  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 12
  • Joined: 03-December 17

Re: Thread Options Help Assistance needed in java for assignment

Posted 04 December 2017 - 08:17 AM

View Postmacosxnerd101, on 04 December 2017 - 07:49 AM, said:

Let me make sure I understand- you found and modified this code? This is not your original solution?


I did all of this by myself, also can you help me integrate withdraw and deposit method into my program since idk how to do it
Was This Post Helpful? 0
  • +
  • -

#14 macosxnerd101  Icon User is online

  • Games, Graphs, and Auctions
  • member icon




Reputation: 12278
  • View blog
  • Posts: 45,364
  • Joined: 27-December 08

Re: Thread Options Help Assistance needed in java for assignment

Posted 04 December 2017 - 08:20 AM

What have you tried? Our members are happy to help, but we’re not here to spoon feed you.
Was This Post Helpful? 0
  • +
  • -

#15 Dimlead  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 12
  • Joined: 03-December 17

Re: Thread Options Help Assistance needed in java for assignment

Posted 04 December 2017 - 09:05 AM

View Postmacosxnerd101, on 04 December 2017 - 08:20 AM, said:

What have you tried? Our members are happy to help, but we’re not here to spoon feed you.


Line: 100
cannot find symbol
symbol: method validateInput(int)
location: class Assigment2

Line: 101
int cannot be dereferenced

Line: 102
cannot find symbol
symbol: variable accountPasscode
location: class Assigment2

what do these even mean, can you help me please, because I haven't done anything yet
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2