Question:
Notepad to Java file?
2008-06-21 16:03:43 UTC
I wrote this code in notepad and now I need to turn it into a Java.file. I have tried to save it as payrollcalculator.java in notepad and that doesn't work. Any help on this would be greatly appreciated. I have Java JDK downloaded I just don't know how to put this in there properly to make it run. Please Help!

/* --Payrollprogram
* myname
* 06/20/08
* payroll/calculation

System.out.print("Enter employee name: ");

employee = Input.readString();
while (employee.equals(""))
{
System.out.print("Enter proper employee name: ");
employee = Input.readString();
continue;
}

// hours worked
while (!hours_valid)
{
System.out.print("How many hours did " + employee + " work? ");
hours = Input.readDouble();
while (hours < 0)
{
System.out.print("Enter proper number of hours: ");
hours = Input.readDouble();
continue;
}
hours_valid = true;

}

// rate
while (!rate_valid)
{
System.out.print("How much does " + employee + " make per hour? ");
rate = Input.readDouble();
while (rate < 0)
{
System.out.print("Enter proper number for rate: ");
rate = Input.readDouble();
continue;
}
rate_valid = true;

}

// compute pay check
double pay = rate * hours;
NumberFormat fmt = NumberFormat.getCurrencyInstance();
System.out.println("\n" + employee + " worked for " + hours
+ " hours at " + fmt.format(rate) + "/hr; paycheck = "
+ fmt.format(pay));
}

}
Three answers:
2008-06-21 16:09:11 UTC
Hi. When using notepad and you click the save button or the save as button you should put quotation marks around the name of the file like this "PayRoll.java" and it will save the file correctly as a .java file. To compile the code your class name must be exactly the same as the file name (sans the suffix), like so:



public class PayRoll{

//code here

}
?
2016-10-13 11:10:43 UTC
Notepad Java
?
2014-04-08 01:06:56 UTC
I recommend you to use Programming environment like JCreator, Eclipse, Intellij etc. But if you want to compile it in cmd Use this instruction:

1st: save your notepad to save us then PayrollProgram.java (Not .txt)

I recommend you to make a folder in drive C: and save it in there.

2nd: Go to CMD or command prompt it is mine is default C:\Users\bluwishi>

use cd.. twice it will going to change to C:\>

then cd Projects (My folder name is Projects there is where I save my notepad with java codes)

3rd: It should be like C:\Projects >

4th:type in cmd (set path=%path%;C:\Program Files\Java\jdk1.8.0\bin) (Depends on what your Jdk tools

5th: compile your code using this ,type this in CMD (javac ProgramPayroll.java) after compiling there you will going to know if you have error if it's doesn't have error

6th:type this in cmd (java ProgramPayroll)

7th: that's it :)


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...