Soldato
You have a function that nominally returns a boolean value.
Edit: I misread that. Ignore.
You have a function that nominally returns a boolean value.
Are you asking how to setup Eclipse so that instead of writing to the built in console it opens a black Windows command prompt instead,
public class helloworld {
public static void main(String[] args) {
System.out.println("Hello world");
}
}
Sorry for not replying sooner; I've been very busy.
As far as I know Eclipse won't open a command prompt to run Java in. It just uses it's built in console. It would be possible to get your Java program to launch the command prompt and then run another Java program inside that. But I'd need to take a while to work that one out as it's been some time ince I properly used Java.
However, if you wanted to use Eclipse to write Java code and then run it yourself in your own command prompt then that's easy...
Firstly it's useful to understand what Eclipse (or any IDE) is doing when it 'compiles' Java code. It's actually just calling the javac compiler which is part of the Java Development Kit. Javac will take source code and create bytecode in the form of class files (it can also create jar and war files which are a collection of class files, but that's a little more advanced). Let's take this example helloworld code:
Code:public class helloworld { public static void main(String[] args) { System.out.println("Hello world"); } }
This would be saved as a file called hellowold.java. When you save it in Eclipse it will automatically be compiled to a new file called helloworld.class (you could also do this manually if you install the JDK and simply type javac helloworld.java in the command prompt). Eclipse will save this class file in your workspace directory under a new sub-directoy called bin.
So in order to run that helloworld java program from the command prompt you need to do the following:
1) Save the file in Eclipse so that it creates a class file (or compile it manually using the JDK javac command).
2) Find where Eclipse has created the class file. For example if your Eclispe workspace dircetory is c:\workspaces and your project name is Project1 then Eclipse will probably save it as c:\workspaces\Projet1\bin\hellowworld.class
3) Open a command prompt. Make sure you have Java installed (see below).
4) type cd java c:\workspaces\Project1\bin (or wherever your class file is)
5) type java helloworld (don't add .class on the end, leave that out because java knows it should be a .class)
How to Check If You Have Java Installed
1) Open a command prompt and type java --version
2) If the command can't be found then you need to download java from www.java.com
public class Employee {
private String name;
private int age;
private String employeeNumber;
private double amountPerHour;
private double hoursWorked;
private double totalWage;
private static final String MOTTO = "Work Hard Play Hard!";
public Employee() {
this("x",0,"xx",0.0,0.0);
}
public Employee(String Name){
this(Name,0,"xx",0.0,0.0);
}
public Employee(String Name,int Age){
this(Name,Age,"xx",0.0,0.0);
}
public Employee(String Name,int Age,String EmployeeNumber){
this(Name,Age,EmployeeNumber,0.0,0.0);
}
//public Employee(String Name,int Age,String EmployeeNumber,double AmountPerHour){
// this(Name,Age,EmployeeNumber,Age,AmountPerHour,0.0);
// }
public Employee(String Name,int Age,String EmployeeNumber,double AmountPerHour,double HoursWorked){
this.name = Name;
this.age = Age;
this.employeeNumber = EmployeeNumber;
this.amountPerHour = AmountPerHour;
this.hoursWorked =HoursWorked;
}
public static String getMOTTO()
{
return Employee.MOTTO;
}
public void setName(String value)
{
this.name = value;
}
public String getName()
{
return this.name;
}
public void setAge(int value)
{
this.age = value;
}
public int getAge()
{
return this.age;
}
public void setEmployeeNumber(String value)
{
this.employeeNumber = value;
}
public String getEmployeeNumber()
{
return this.employeeNumber;
}
public void setAmountPerHour(double APH)
{
this.amountPerHour = APH;
}
public double getAmountPerHour()
{
return this.amountPerHour;
}
public void setHoursWorked(double HS)
{
this.hoursWorked = HS;
}
public double getHoursWorked()
{
return this.hoursWorked;
}
public double gettotalPay()
{
Scanner sc = new Scanner(System.in);
System.out.println("Please enter the total hours your worked this week:");
double hoursWorked = sc.nextDouble();
double totalWage = this.amountPerHour * this.hoursWorked;
return totalWage;
}
public String toString()
{
StringBuilder strB = new StringBuilder();
strB.append(" Name: ");
strB.append(this.getName() + "\n");
strB.append(" Age: ");
strB.append(this.getAge() + "\n");
strB.append(" EmployeeNumber: ");
strB.append(this.getEmployeeNumber() + "\n");
strB.append("Rate Per Hour: ");
strB.append(this.getAmountPerHour() + "\n");
strB.append(" Total Wage this week: ");
strB.append(this.gettotalPay() + "\n");
return strB.toString();
}
}
new Employee_Tester().tester_Application();
}
public void tester_Application()
{
Employee s1 = new Employee();
s1.setName("John");
s1.setAge(32);
s1.setEmployeeNumber("112345");
s1.setAmountPerHour(8.75);
s1.setHoursWorked(0);
System.out.println(s1.toString());
//Employee s2 = new Employee();
//Employee s3 = new Employee();
//Employee s4 = new Employee();
//Employee s5 = new Employee();
//Employee s6 = new Employee();
//Employee s7 = new Employee();[/CODE
public double gettotalPay()
{
Scanner sc = new Scanner(System.in);
System.out.println("Please enter the total hours your worked this week:");
double hoursWorked = sc.nextDouble();
double totalWage = this.amountPerHour * this.hoursWorked;
return totalWage;
}
public double gettotalPay()
{
Scanner sc = new Scanner(System.in);
System.out.println("Please enter the total hours your worked this week:");
this.hoursWorked = sc.nextDouble();
double totalWage = this.amountPerHour * this.hoursWorked;
return totalWage;
}