Question: My program keeps looping the Username and Login, without getting to the welcoming login. Help? import java.util.*; public class Account { public static void main(String[]

My program keeps looping the Username and Login, without getting to the welcoming login. Help?

import java.util.*; public class Account

{

public static void main(String[] args)

{ String [] userid = {"John", "Professor", "Charles"}; //Stringing names and passwords as stored String [] passwords = {"College", "Roy", "Xavier"};

Scanner input = new Scanner(System.in); //input via scanner

boolean valid = false; //using boolean for the two options as username/id can only be correct or incorrect String testname = null, password; System.out.println ("Welcome to College Online Shop!");

while(!valid) { System.out.println ("Please enter your login ID: "); testname = input.next(); //was stuck here for a bit due to incompatible types of String. System.out.println ("Please enter your password: "); password = input.next(); } }

private String userid;

private String password;

private double balance;

private int items; // number of items

Account(String id, String pass) // constructor account with no balance

{ userid=userid; password=pass; balance=0; items=0; }

Account(String user, String pass, double balance)// constructor account with balance, using double for decimal values

{

userid=userid; password=pass; balance=balance; items=0;

}

public double check_balance() // check the balance of account

{ return balance; }

public int check_items() // check number of items purchased

{ return items; }

public void order_item(int i) // modifier to order item

{ items = items + i; }

public void add_balance(double balance) // modifier to add balance { balance += balance; }

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!