I need to do the following program, but it need to have a do while loop, scanner for input, and a console program. Here are the instructions:

Write a Java program that prompts the user for how many individuals they will be entering. Then program will then prompts for each individuals name and account balance. The output of the program will be the person with the highest account balance (name and balance) and the lowest account balance (name and balance). All output should be to 2 decimal places.

If someone could code this program by 5/9/10 it would be great.

6 Years
Discussion Span
Last Post by Katana24

If someone could code this program by 5/9/10 it would be great.

When was this assignment given to you?


How come you haven't posted your attempt? You lazy and want someone else to do it? :P I made your code but it has a few bugs included, so you HAVE to work a-little, in it however it will point you in the right direction.

I know what the bugs are and how to fix them but I can't be writing your entire code for you - that would be against the forum rules. One of the bugs will take input for the names but it will return an error if the name contains a space - you can fix that, and I didn't include a way to format the output - you can do that.. :D

Enjoy your assignment

import java.util.*;

public class Balance {
	public static void main(String [] args)
		int numberA;		int numberB = 0;		String name;		int money;
		Scanner in = new Scanner(System.in);
		System.out.println("How many users are you entering?");
		numberA = in.nextInt();
		String [] names = new String[numberA];									// To hold names
		int [] bank = new int[numberA];											// To hold balance
			System.out.println("Enter name: ");
			name = in.next();
			names[numberB] = name;
			System.out.println("Enter balance: ");
			money = in.nextInt();
			bank[numberB] = money;
		} while(numberB < numberA);

		getHighLow(bank, names);

public static void getHighLow(int [] myArray, String [] theNames )
		int high = myArray[0];			String rich = theNames[0];
		int low = myArray[0];			String poor = theNames[0];
		for(int i = 0; i < myArray.length; i++)
			if(high <= myArray[i])
				high = myArray[i];
				rich = theNames[i];
			else {
				low = myArray[i];
				poor = theNames[i];
		System.out.println("Highest balance belongs to "+rich+" with £"+high);
		System.out.println("\nLowest balance belongs to "+poor+" with "+low);
This article has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.