1.

Solve : Help with Java?

Answer»

So I've got an assignment to do but I don't quite get it, I'm supposed to make a program let's say for a company with x number of employees, what the program does is that it stores the name, age and salary of each user by using both arrays and a different class (Object oriented). The thing is I have no idea how to combine arrays with a different class, I made something but it doesn't use another class so I won't get a grade, if anyone can help me use this with another class I'll be grateful

Quote

/*
* To change this TEMPLATE, choose Tools | Templates
* and open the template in the editor.
*/

package assignment;

import com.sun.org.apache.bcel.internal.generi c.ARRAYLENGTH;
import javax.swing.JOptionPane;
import sun.swing.PrintColorUIResource;

/**
*
* @author Gimmy
*/
public class Main {

PRIVATE static int size;

public static void main(String[] args) {
size = Integer.parseInt(JOptionPane.showInputDialog("Enter number of employees"));

double [] salary = new double[size];
String [] name = new String[size];
int [] age = new int[size];

for (int i=1; i<=size ; i++)

{
salary = Double.parseDouble(JOptionPane.showInputDialog("Enter salary of employee number" + i ));
name = (JOptionPane.showInputDialog("Enter name of employee number" + i));
age = Integer.parseInt(JOptionPane.showInputDialog("Enter age of employee number" + i));


}

for (int R=1; r<=size ; r++)
{

System.out.println("Employee number " + r + "Details are");
System.out.println("Name is " + name[r] + "Age is " + age[r] + "Salary is " +salary[r]);


}

}

}

sounds like the intent is to get you to use an array of instances of a class, like say EmployeeInfo[], and then the class has the Name, Salary, and other employee based information.


It's also rather interesting that the whole "employee table" example is still being used. That's in my Visual Basic version 2 programmers guide aaaah :p , I came up with this but I don't know what's wrong and I'm desperate

Employee class
Quote
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package assignment;

import javax.swing.JOptionPane;

/**
*
* @author Gimmy
*/

public class Employee
{
double [] salary ;
String [] name;
int [] age ;
}

Main
Quote
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package assignment;

import com.sun.org.apache.bcel.internal.generi c.ARRAYLENGTH;
import javax.swing.JOptionPane;
import sun.swing.PrintColorUIResource;

/**
*
* @author Gimmy
*/
public class Main {

private static int size;

public static void main(String[] args) {
size = Integer.parseInt(JOptionPane.showInputDialog("Enter number of employees"));









for (int i=1; i<=size; i++){

Employee employees=new Employee();

employees.salary = new double[size];
employees.age = new int[size];
employees.name = new String[size];


employees.salary=Double.parseDouble(JOptionPane.showInputDialog("Enter salary of employee"));

}



}





}



no, you have teh arrays in the class instances, what you want is a MEMBER on each instance, and array of those instances, such as:


Code: [Select]
public class Employee
{
public double salary;
public String name;
public int age;
public Employee(String pname, int page,double psalary)
{
salary=psalary;
name=pname;
age=page;


}

}



and then later in the code (the other SECTION) you would create an employee simply like so:

Employee mEmployee = new Employee("George",47,43000);

and then add that instance to an array.


Discussion

No Comment Found