3 Replies - 217 Views - Last Post: 09 October 2012 - 09:27 AM Rate Topic: -----

#1 yakult02  Icon User is offline

  • New D.I.C Head

Reputation: -3
  • View blog
  • Posts: 26
  • Joined: 04-December 09

Printing entire row

Posted 09 October 2012 - 08:45 AM

Hi. can someone give me a hint on how to print an entire row when the input matches with an element in an array.. :)

/**
 *	Copyright © Ja Gb
 *	justineanne.bacatio@my.jru.edu 
 * 
 *	Sep 1, 2012
 */
package scanner;
import java.util.Arrays;
import java.util.Scanner;

public class EmployeeInformation {

	static Scanner sc = new Scanner(System.in);
	
	static String info[][] = {{"09-001", "Ja Gb", "100", "10", },
						{"09-002", "Justine", "200", "20", ""},
						{"09-003", "Ja Ja", "150", "15", ""}};
	
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub

		System.out.print("     - MENU -\n");
		System.out.print("A. Search Record\nB. Payroll Summary\n------------------\nEnter choice: ");
		String choice = null;
		choice = sc.nextLine();
	
				
		if (choice.equalsIgnoreCase("a")) {
			System.out.print("Enter Employee #: ");
			String EmpNum = sc.nextLine();
			SearchRecord(EmpNum);
		}
		else {
				PayrollSummary();
			}
	}

	private static void SearchRecord(String employeeNumber) {
		// TODO Auto-generated method stub
	
		int i = 0;
		while(i <= info.length) {
			int j = 0;
			while(j <= info.length) {
				if(employeeNumber.equals(info[i][j])) {
					j++;
					System.out.println("\nName: " + info[0][j]);
					j++;
					System.out.println("\nRate per Hour: " + info[0][j]);
					j++;
					System.out.println("\nTotal Hours Worked: " + info[0][j]);
					j++;
					
					System.out.println("\nGross Pay: " + info[0][j]);
					j++;
				}
				else {
					System.out.print("Invalid employee number.");
					System.exit(0);
				}
				j++;
			}
			i++;
		}
	}
	
	private static void PayrollSummary() {
		
		System.out.println("Employee #:\tEmployee Name\tRate per Hour\tTotal Hours Worked\tGross Pay");
		int r = 0;
		while ( r <= info.length - 1) {
			int c = 0;
			while ( c <= info.length ) {
				System.out.print(info[r][c] + "\t\t");
				if (c == 3) {
				System.out.print("\n");
				}
				c++;
			}
			r++;
		}
		
		

		//for (int a = 0; a <= info.length -1; a++) {
		//		Integer.parseInt(info[a][4]) = Integer.parseInt((info[a][3]) *  (info[a][4]));
				
		//}
	}
}




I forgot to put bb codes on my original post..

This post has been edited by macosxnerd101: 09 October 2012 - 08:47 AM
Reason for edit:: Removed extraneous code not in code tags


Is This A Good Question/Topic? 0
  • +

Replies To: Printing entire row

#2 jdavi134  Icon User is offline

  • D.I.C Head

Reputation: 42
  • View blog
  • Posts: 225
  • Joined: 26-October 11

Re: Printing entire row

Posted 09 October 2012 - 09:18 AM

So you are traversing through the arraylist and when you find something that matches whatever you are looking for, you want to print the entire contents of the row that the match was found?

Just trying to understand what you are asking.
Was This Post Helpful? 0
  • +
  • -

#3 yakult02  Icon User is offline

  • New D.I.C Head

Reputation: -3
  • View blog
  • Posts: 26
  • Joined: 04-December 09

Re: Printing entire row

Posted 09 October 2012 - 09:23 AM

Yes. Apologies for my english grammar..
Was This Post Helpful? 0
  • +
  • -

#4 jdavi134  Icon User is offline

  • D.I.C Head

Reputation: 42
  • View blog
  • Posts: 225
  • Joined: 26-October 11

Re: Printing entire row

Posted 09 October 2012 - 09:27 AM

Thanks for the code tags by the way Mac =)

1. Start search
2. Find match
3. Use variable from your "row" for loop in order to print the row by using another for loop.
4. Problem Solved =)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1