Pennies for Pay

Program should calculate the salary of a 30 day period when first day - add one penny, second day, add two pennies and continues to double each day.  Two tables should be created: one showing thesalary foreach day aand then the total pay at the end of the period.  Should be displayed in dollars not pennies.

Attached is a first draft.  Thank you in advance for your assistance.
public class Salary
{
	public static void main(String[] args)
	{
		int number;
		int sum;
		
		System.out.println(" Salary       Total pay");
		System.out.println("----------------------------");
		
		for(number = 1; number <= 30; number++)
		{
			System.out.println(number + "\t\t" + number);
		}
	}
}

Open in new window

gkilgoreAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

gkilgoreAuthor Commented:
Revised program requirement:  Need assistance completing the following program.  The program should calculate the amount a person would earn over a periodof time  if their salary is one penny the first day, two pennies the second day and continues to double each day.  Program will display the salary for each day and then show the total pay at the end of the period.  
0
gkilgoreAuthor Commented:
Revised code.  This is a portion of the program, any additional steps I may have left off.
import java.text.DecimalFormat;
import javax.swing.JOptionPane;
 
public class TotalSales
{
	public static void main(String[] args)
	{
		int days;
		double sales;
		double totalSales;
		String input;
		
		DecimalFormat dollar = new DecimalFormat("#,##0.00");
		
		input = JOptionPane.showInputDialog("For how many day " + 
														"do yoiu have sales figures");
		days = Integer.parseInt(input);
		
		totalSales = 0.0;
		
		for (int count = 1; count <= days; count++)
		{
			input = JOptionPane.showInputDialog("Enter the sales " +
															"for day " + count + ":");
			sales = Double.parseDouble(input);
			totalSales += sales;
		}
		
		JOptionPane.showMessageDialog(null, "The total sales are $" +
												dollar.format(totalSales));
		System.exit(0);
	}
}			

Open in new window

0
gkilgoreAuthor Commented:
Last copy with correct data.  Please critique according to program specifications.  Thank you.
import java.text.DecimalFormat;
import javax.swing.JOptionPane;
 
public class Salary
{
	public static void main(String[] args)
	{
		int days;
		double salary;
		double totalSalary;
		String input;
		
		DecimalFormat dollar = new DecimalFormat("#,##0.00");
		
		input = JOptionPane.showInputDialog("For how many day " + 
														"do you have salary for?");
		days = Integer.parseInt(input);
		
		totalSalary = 0.0;
		
		for (int count = 1; count <= days; count++)
		{
			input = JOptionPane.showInputDialog("Enter the salary " +
															"for day " + count + ":");
			salary = Double.parseDouble(input);
			totalSalary += salary;
		}
		
		JOptionPane.showMessageDialog(null, "The total salary $" +
												dollar.format(totalSalary));
		System.exit(0);
	}
}			

Open in new window

0
gkilgoreAuthor Commented:
Please disregard the other versions displayed earlier.  The listed program should calculate the amount a person would earn overa period of timne if their salary was one penny for the first day,l two pennies for the second day, and continues to double each day.  A table should be displayed showing the salary for each day and the total pay at the end of the period.  I think I have over coded this program.  Any feedback will be appreciated.
import java.text.DecimalFormat;
import javax.swing.JOptionPane;
 
public class Salary
{
	public static void main(String[] args)
	{
		int days;
		double salary;
		double totalSalary;
		String input;
		
		DecimalFormat dollar = new DecimalFormat("#,##0.00");
		
		input = JOptionPane.showInputDialog("For how many day " + 
														"do you have salary for?");
 
		
		System.out.println("Days                    Salary");
		System.out.println("------------------------------");		
		
													
		days = Integer.parseInt(input);
		
		totalSalary = 0.00;
				
		for (int count = 1; count <= days; count++)
		{
		
			input = JOptionPane.showInputDialog("Enter the salary " +
															"for day " + count + ":");
															
			System.out.print(count + "\t\t\t");	
			
														
			salary = Double.parseDouble(input);
			totalSalary += salary;
			
			System.out.println(salary);
			
		}
		
		System.out.println("Total Salary $ " + totalSalary); 
				
		System.exit(0);
	}
}			

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
8080_DiverCommented:
That's a lot of processing and code for a simple calculation.
For each day, the pay is 2 ^ (n - 1) and the total pay is ((2 ^ n) -1) .  So stic that in a FOR loop, using n as your index and go from 1 to 30 and, as my SQL mentor used to say, "the SQL to insert the data into each table is a trivial exercise left for the student.". ;-)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java EE

From novice to tech pro — start learning today.