Assistance needed in java for assignment - Dimlead - Dec 2, 2017
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.
Code 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 code that I have so far, the variables I used are different since I can't use the same variables as my class mates, so they're a bit odd. I still have to do the withdraw method, the passcode change method, the login method, the deposit method, loop, and errorcheck and I think that's it, if there's anything else that I missed that is in the guidelines then please correct me in the thread and give me a solution for it please. I tried solving the methods myself by putting in solutions from the internet but they don't match the guidelines and variables that I have, which causes problems that I can't fix, hopefully someone is able to fully help me so I can finish this frustrating assignment that has only cost me time and trouble.
RE: Assistance needed in java for assignment - matt - Dec 2, 2017
(Dec 2, 2017 04:33 PM)Dimlead Wrote: -snip-
Are you willing to pay somebody to do the assignment for you?
RE: Assistance needed in java for assignment - Dimlead - Dec 3, 2017
(Dec 2, 2017 08:19 PM)Midnight Blue™ Wrote: Are you willing to pay somebody to do the assignment for you?
Lool if I were to pay someone I would have just paid one of my nerdy class mates to do it for me, and wouldn't go through the trouble of putting up a thread.
RE: Assistance needed in java for assignment - Ozgin - Dec 4, 2017
It is pretty much done, you would just need to do the errorCheck method
Code import java.util.Scanner;//java library class
import java.util.List;
import java.util.Arrays;
public class Assignment2 {//start class
//global variable
private static int creditsbalanceArray []={156,256,504};// user currency balance
private static String nameArray []={"Molly","Connor","Shane"};// user name
private static String passcodeArray []= {"6543","7654","8765"};// user passcode
private static int overdraftArray []={1,2,3};// user overdraft
private static int passcode;// user passcode
private static Scanner input = new Scanner(System.in);//static Scanner input
private static int index;// user index
public static void main(String[] args) {//start main method
showAllUsers();//show All user variable
int userIndex = loginBankMachine();//login Bank Machine variable
while(userIndex == -1){
System.out.println("Something went wrong let's try that again");
userIndex = loginBankMachine();
}
showMenu();//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
private static int loginBankMachine(){//start login method
System.out.println("Welcome " +"\nPlease Enter Username : ");
String uname = input.next();
System.out.println("password: ");
String pass = input.next();
List names = Arrays.asList(nameArray);
List passwords = Arrays.asList(passcodeArray);
System.out.println(names.indexOf(uname));
System.out.println(names.indexOf(pass));
if(names.contains(uname) && passwords.contains(pass)) {
if(names.indexOf(uname) == passwords.indexOf(pass)){
return names.indexOf(uname);
}
}
return -1;
}//end loginATM
public static void showMenu(){//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\n:");//user options
String option =input.next();//string option
switch(option){//start switch method
case "1":
bankMachineProducedStatement();
break;//BankMachineProducedStatment option
case "2":
depositMoney();
break;//Deposit Credits option
case "3":
withdrawMoney();
break;//Withdraw Credits option
case "4":
changePasscode();
break;//Change Passcode option
case "5":
exit();
break;//Exit option
default:
System.out.println("Oops");
break;
}//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("$" +creditsbalanceArray[index] +".00");
showMenu();
}//end BankMachineProducedStatement method
public static void depositMoney(){//start DepositCredits Method
System.out.println(" Total balance");//Credits Total Description
System.out.println("$" +creditsbalanceArray[index] +".00");
System.out.println("How much will you be depositing?");
int amount = input.nextInt();
creditsbalanceArray[index] += amount;
System.out.println(" New balance");//Credits Total Description
System.out.println("$" +creditsbalanceArray[index] +".00");
showMenu();
}//end DepositCredits method
public static void withdrawMoney(){//start WithdrawCredits Method
System.out.println(" Total balance");//Credits Total Description
System.out.println("$" +creditsbalanceArray[index] +".00");
System.out.println("How much will you be Withdrawing?");
int amount = input.nextInt();
while(amount >= creditsbalanceArray[index]) {
System.out.println("Invalid amount, try again");
amount = input.nextInt();
}
creditsbalanceArray[index] -= amount;
System.out.println(" New balance");//Credits Total Description
System.out.println("$" +creditsbalanceArray[index] +".00");
showMenu();
}//end WithdrawCredits method
public static void changePasscode(){
System.out.println("\nEnter new passcode");
String newPass = input.next();
List passwords = Arrays.asList(passcodeArray);
while(passwords.contains(newPass)){
System.out.println("passcode taken, try again:"); //totally not vulnerable password checking
newPass = input.next();
}
passcodeArray[index] = newPass;
showMenu();
}//end changePasscode Method
public static boolean errorCheck(String input) {
return true;
}
public static void exit(){
System.out.println("Thank you for using our bank machine");
System.exit(0);
}//end Exit method
}//end class
|