Keep in mind that all program variables must be mnemonic in that they should hel
ID: 3652415 • Letter: K
Question
Keep in mind that all program variables must be mnemonic in that they should help describe what is being held in the variable. Although used by the author, single letter variable identifiers are discouraged in that they do not allow the code to be self-documenting. When choosing names for program variables, be mindful that there are several reserved words which have special meaning in the language and therefore are "off-limits" to programmers. A list of these may be found on page 72 of the text. While it is not expected to memorize the list, knowing where it can be located may save some time. Remember that Java is case sensitive and convention dictates that the first letter of a variable name is lower case while the first letter of succeeding words in the variable name are upper case. Variable names are always nouns. Also remember that identifiers can not begin with a number but can include numbers in their name. For example : hour12 is a valid identifier, but 3Outs is not. Also, the only symbols that can be included in variable identifier are the underscore _ and the dollar sign $. For example total_Tax and $amount are legal. However, the style followed by a large number of programmers tends to avoid the $ and consider the underscore _ more reflective of previous programming languages, most notably Pascal and C++. Follow this convention and avoid these symbols when creating our variable names.Sample test data is provided below.
Test data :
Employee ID : 3248 - Hourly Wage : 17.25 - Regular Hours : 36.5 - Overtime Hours : 7.75
Sample Output :
Total Pay : $830.16
Explanation / Answer
import java.util.Scanner; public class Cramster_TotalPay { public static void main(String[] args){ int employeeNumber; double hourlyWage, hoursWorked, hoursWorkedOvertime, totalPay; Scanner keyboard = new Scanner(System.in); System.out.println("What is the employee number?"); employeeNumber = Integer.parseInt(keyboard.nextLine()); System.out.println("What is the hourly wage amount?"); hourlyWage = Double.parseDouble(keyboard.nextLine()); System.out.println("What is the number of regular hours worked?"); hoursWorked = Double.parseDouble(keyboard.nextLine()); System.out.println("What is the number of overtime hours worked?"); hoursWorkedOvertime = Double.parseDouble(keyboard.nextLine()); totalPay=(hoursWorked*hourlyWage+hoursWorkedOvertime*hourlyWage*1.5); System.out.printf("Total Pay : $%.2f", totalPay); } }
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.