1 Replies - 137 Views - Last Post: 04 December 2017 - 10:07 AM Rate Topic: -----

#1 Dimlead   User is offline

  • New D.I.C Head

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

java.lang.string problem and other problems in java

Posted 04 December 2017 - 10:06 AM

I've got some problem with my code these are the problems that I am getting at the moment:

Compilation Errors Detected

Line: 101
method validateInput in class Assigment2 cannot be applied to given types;
required: java.lang.String
found: int
reason: actual argument int cannot be converted to java.lang.String by method invocation conversion

Line: 102
int cannot be dereferenced

Line: 103
array required, but int found



i don't know how to fix these problems, I've never encountered these problems before so I'm lost and I don't know where to even begin with.

This is my code so far:

/**
 * @(#)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 AccountPasscode=validateInput(passcode);
		for(int i=0;i<passcode.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
		
	public static int validateInput(String stringInput){
	while(!stringInput.matches("\\d+")){
		System.out.println("Digits only Try again");
		stringInput=input.next();
		}
	return Integer.parseInt(stringInput);
	}
}//end class


Is This A Good Question/Topic? 0
  • +

Replies To: java.lang.string problem and other problems in java

#2 macosxnerd101   User is offline

  • Games, Graphs, and Auctions
  • member icon




Reputation: 12298
  • View blog
  • Posts: 45,399
  • Joined: 27-December 08

Re: java.lang.string problem and other problems in java

Posted 04 December 2017 - 10:07 AM

Do not duplicate post.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1