> Why isn't this JAVA program working? May someone fix it, please?

Why isn't this JAVA program working? May someone fix it, please?

Posted at: 2014-12-18 
Lets look at all the errors..

Main.java:25: error: 'else' without 'if' ... that while loop executes under the condition is false so there's no need for an else and it's not allowed because you have no if. so remove the else and the matching {}

lines 40 and 41 you forgot a semicolon same with line 52

you forgot a closing } at the end of the program..

line 35 you declared day again... get rid of "int"

you are trying to use a Formatter without importing java.util.Formatter nor declaring a formatter

etc

etc

You have so many errors it looks like you weren't testing as you wrote it. That's a huge mistake.

import java.util.Scanner;

public class Program {

public static void main(String[] args) {

int dayWorked = read("Enter number of days worked? ");

int pay = calculatePay(dayWorked);

System.out.printf("Day %d pay is %s (%d pennis)%n",

dayWorked, formatted(pay), pay);

}

private static int read(String message) {

boolean done = false;

int result = 0;

do {

System.out.print(message);

Scanner keyboard = new Scanner(System.in);

result = keyboard.nextInt();

if (result <= 0) {

System.err.println("Invalid input");

} else {

done = true;

}

} while (!done);

return result;

}

private static int calculatePay(int dayWorked) {

final int PAY_PER_DAY = 99;

return dayWorked * PAY_PER_DAY;

}



private static String formatted(int value) {

int pennis = value % 100;

int dollar = (value - pennis) / 100;

return String.format("$%d.%d", dollar, pennis);

}

}

you are missing some semi colons

import java.util.Scanner;

import java.text.DecimalFormat;

public class PenniesForPay

{

public static void main(String[] args)

{

int daysWorked;

double pennies, dollars, totalPay;

// Create a Scanner object for keyboard input.

Scanner keyboard = new Scanner(System.in);

// Get the number of days worked.

System.out.print("Enter the number of days worked: ");

daysWorked = keyboard.nextInt();

while(daysWorked < 1)

{

System.out.println("Invalid input!");

System.out.println("Enter a number greater than 1.");

daysWorked = keyboard.nextInt();

}

else

{

System.out.println("Days Dollars");

System.out.println("-------------------------");

}

int day = 0;

pennies = 1;

totalPay = 0;

for (int day = 1; day <= daysWorked; day++)

{

day++;

if (day > 1)

{

pennies = pennies * 2

dollars = pennies / 100

System.out.println(day + " $ " + formatter.format(dollars));

}

else

{

dollars = pennies / 100

System.out.println(day + " $ " + formatter.format(dollars));

}

System.out.println("The total pay is $" + totalPay);

}

}