I have a problem in my beginning java class that I don\'t even know where to sta
ID: 3550028 • Letter: I
Question
I have a problem in my beginning java class that I don't even know where to start working on. I am supposed to write a program that prints a paycheck. I know I need to write a method for the form of the check. The check has to have ------ on the top and bottom then everything a check has on it, date, number, pay to, amount, amount written out, memo, and my name. Then I also have to ask the user to enter hour worked and pay rate. I don't expect someone to do this for me, but if you could help me with the method to set up the check, that would be great. This is what the output is suppsed to look like;
Sample Run:
Check Writing Program
Enter the Hours Worked: XX
Enter the Pay Rate: XX
Enter the Date: XX
Enter the Check Number: XX
Enter the Payee: XX
Enter the Memo: XX
------------------------------------------------------------------------------------------------------------------------------------
Check XXX
Date XX/XX/XX
Pay to the
Order of: XXXXXXXXXX $XXX.XX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ----------------------------------
Memo: XXXXXXX Your Name Here
-------------------------------------------------------------------------------------------------------------------------------------
Explanation / Answer
import java.util.Scanner;
public class Paycheck {
public static void main(String[] args){
System.out.println("Check Writin Program");
Scanner in =new Scanner(System.in);
System.out.print("Enter hours worked:");
int hours = in.nextInt();
System.out.print("Enter Pay rate(amount/hour):");
double rate = in.nextDouble();
System.out.print("Enter the date:");
String date = in.next();
System.out.print("Enter cheque number:");
String chequeNo = in.next();
System.out.print("Enter payee:");
String payee = in.next();
System.out.print("Enter memo:");
String memo = in.next();
writeCheck(hours, rate, chequeNo, payee, memo, date);
in.close();
}
static void writeCheck(int hour, double rate, String checkNo, String payee, String memo, String date){
System.out.println("---------------------------------------------------------------------------");
System.out.println("Check "+checkNo);
System.out.println("Date "+date);
System.out.println("Pay to the");
String amount = String.format("%.2f", rate*hour); // to print the amount to two decimal places
System.out.println("Order of: XXX"+payee+" $"+amount);
System.out.println("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX-------------------------------------");
System.out.println("Memo: "+memo);
System.out.println("---------------------------------------------------------------------------");
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.