This is an assignment I have and i'm running into problems on this part of it.
I need to assign the value I get from scanner input = to a variable in another class.
After I do that, I need to be able to call a method that will display the value along with other ones.
Like this,
Name: "value"
Age: "value"
ect...
import java.util.*;
public class main {
public static void main(String[] args) {
}
public void setEmployee(){
Employee emp = new Employee();
Scanner scan = new Scanner(System.in);
try {
System.out.println("Enter Employee name. \n");
// String emp.setName(nameIn) = scan.next(); <-- trying to set the nameIn = to the scanner value
System.out.println("Enter Employee age. \n");
int ageIn = scan.nextInt();
System.out.println("Enter Employee sex. \n");
String sexIn = scan.next();
System.out.println("Enter Employee salary. \n");
double salaryIn = scan.nextDouble();
System.out.println("Enter Employee job title. \n");
String jobIn = scan.next();
}
catch(InputMismatchException ime)
{
System.out.println("Input mismatch, please enter the correct datatype.");
}
}
public void getEmployee() {
Employee emp = new Employee();
System.out.println("Name: " + emp.getName());
System.out.println("Age: " + emp.getAge());
System.out.println("Sex: " + emp.getSex());
System.out.println("Salary: " + emp.getSalary());
System.out.println("Job : " + emp.getJob_title());
}
}
public class Employee {
private String name;
String nameIn;
private int age;
int ageIn;
private char sex;
char sexIn;
private double salary;
double salaryIn;
private String job_title;
String jobIn;
// constructor
// Employee(String nameIn, int ageIn, char sexIn, double salaryIn, String jobIn)
// {
// name = nameIn;
// age = ageIn;
// sex = sexIn;
// salary = salaryIn;
// job_title = jobIn;
// }
// Accessors and Mutators
public void setName(String nameIn)
{
name = nameIn;
}
public String getName()
{
return name;
}
public void setAge(int ageIn)
{
age = ageIn;
}
public int getAge()
{
return age;
}
public void setSex(char sexIn)
{
sex = sexIn;
}
public char getSex()
{
return sex;
}
public void setSalary(double salaryIn)
{
salary = salaryIn;
}
public double getSalary()
{
return salary;
}
public void setJob_title(String jobIn)
{
job_title = jobIn;
}
public String getJob_title()
{
return job_title;
}
}