import java.util.Scanner; import java.text.DecimalFormat; public class PenniesFo
ID: 3649558 • Letter: I
Question
import java.util.Scanner;import java.text.DecimalFormat;
public class PenniesForPay
{
public static void main(String[] args)
{
int pennies; // Penny accumulator
int totalPay; // Total pay accumulator
int maxDays; // Max number of days
int day; // Day counter
// Create a Scanner object for keyboard input.
Scanner keyboard = new Scanner(System.in);
//step1: ask the user to enter the number of days he/she worked. and store the input in the variable maxDays
//step2: Assign the variable day to 1.
//step3: Assign the variable pennies to 1
//step4: Initialize the variable totalPay to 0.
// Display the report header.
System.out.println("Day Pennies Earned");
// Write a while loop to calculate and print the salary for each day.
//step5: fill the condition in the while loop
while ( )
{
// Display the day number and pennies earned.
System.out.println(day + " " + pennies);
//step6: add the earned pennies to totalPal.
//step7: Increment day by one.
//step8: Double the number of pennies
}
// Create a DecimalFormat object to format output.
DecimalFormat dollar = new DecimalFormat("#,##0.00");
// Display the total pay.
System.out.println("Total pay: $" +
dollar.format(totalPay / 100.0));
}
}
Explanation / Answer
Hi, I'm trying to write a java program that will read in the scanner input from a user and outputs an postfix expression and answer so if you typed in: A = 5 B = 7 $PART2 AB+ the output would be AB+ = 12 I'm having trouble with the scanner input I can make it so a user can enter a letter and a number, but I'm having trouble trying to make the program shift so when the user enters $PART2 it will then begin to read in the post fix expressions. If anyone could help I would greatly appreciate it. import java.util.*; import java.io.*; import java.util.Scanner; import java.util.Stack; public class PostEval { static public void main(String args[]) { Scanner scanner = new Scanner(System.in); Stack postFix = new Stack(); String part2 = "$PART2"; System.out.println("Input Letter and Number it equals: "); while(scanner.hasNext()) { String letter = scanner.next(); char equals=(scanner.next()).charAt(0); int number = scanner.nextInt(); System.out.println("You Inputted:"+ letter+ equals+ number); if(letter == "$PART2") { while(scanner.hasNext()) { String postfix = scanner.nextLine(); System.out.println(postfix); } } }Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.