please check my code

here goes the problem:

A bicycle salesperson is offered a choice of wage plans:

1) straight salary of $300

2)$3.50 per hour for 40 hrs plus 10% commission on sales

3)a straight 15% commission on sales with no other salary.

Write a program that takes as input the salesperson's expected weekly sales and outputs the wages paid under each plan in increasing order.

import java.util.*;

publicclass Number18

{

publicstaticvoid main(String[] args)

{

double Wage1,d2,d3,Wage3,Wage2;

Scanner s=new Scanner(System.in);

System.out.println("Enter Your Estimated Weekly Sales:");

double dSales=s.nextFloat();

d2=3.50*40 + dSales*.10;

d3=dSales*.15;

Wage1=Math.min(d2,d3);

Wage3=Math.max(d2,d3);

Wage2=Wage3-Wage1;

if (Wage1>300)

System.out.println("Wage 1 is:" +"$300");

else

System.out.println("Wage 1 is:" +"$" + Wage1);

if (Wage2>300 && Wage1<Wage2)

System.out.println("Wage 2 is:" +"$300");

else

System.out.println("Wage 2 is:" +"$" + Wage2);

if (Wage3>300)

System.out.println("Wage 3 is:" +"$" + Wage3);

else

System.out.println("Wage 3 is:" +"$300");

s.close();

}

}

did i do it correctly? THANK YOU!!

Message was edited by:

pink-fire

[2304 byte] By [pink-firea] at [2007-11-27 11:17:45]
# 1

> did i do it correctly? THANK YOU!!

Did it work? if so yes it's correct.

Davey_Vargasa at 2007-7-29 14:26:46 > top of Java-index,Java Essentials,New To Java...
# 2

good place for the strategy pattern, eh?

(joking!)

Have you outputted the results in order?

petes1234a at 2007-7-29 14:26:46 > top of Java-index,Java Essentials,New To Java...
# 3

yup! really? gosh do you think i formulated the correct formula? :)

pink-firea at 2007-7-29 14:26:46 > top of Java-index,Java Essentials,New To Java...
# 4

> ...

>

> did i do it correctly? THANK YOU!!

>

That question can be partly answered by your compiler. It the compiler doesn't complain, then you should test your software: put in some values and see if the output is the same as your own calculations.

prometheuzza at 2007-7-29 14:26:46 > top of Java-index,Java Essentials,New To Java...
# 5

haha yep:) omg i'm so happy

pink-firea at 2007-7-29 14:26:46 > top of Java-index,Java Essentials,New To Java...
# 6

I think that your calculation salary for one of the situations is off. If you plug in 500, you should get 300, 75, and 190 as result. You are getting 300, 75, and 115

Message was edited by:

petes1234

petes1234a at 2007-7-29 14:26:46 > top of Java-index,Java Essentials,New To Java...
# 7

Here's your output and mine for an input of $2500

Enter Your Estimated Weekly Sales:

2500

Wage 1 is:$300

Wage 2 is:$15.0

Wage 3 is:$390.0

Straight Salary: $300.00

Commission Only: $375.00

Salary and Commission: $390.00

ps: I did this program by trying out the Strategy Pattern for the first time. I had to see if I could do it, and it was cool as heck to do, though my code is probably a bit sloppy. I may show it here, because there is no way that the OP could use my code and turn it in as his own without raising suspicions

Message was edited by:

petes1234

petes1234a at 2007-7-29 14:26:46 > top of Java-index,Java Essentials,New To Java...
# 8

It's unlikely that somebody at this level will know what the strategy pattern is.

%

duffymoa at 2007-7-29 14:26:46 > top of Java-index,Java Essentials,New To Java...
# 9

I know. I'm just learning myself. That's why I may display it here for your criticism without fear that he'll cheat with my code.

petes1234a at 2007-7-29 14:26:46 > top of Java-index,Java Essentials,New To Java...
# 10

nevermind...withdrawn,... not my thread

Message was edited by:

petes1234

petes1234a at 2007-7-29 14:26:46 > top of Java-index,Java Essentials,New To Java...
# 11

But, for the OP's education, I might start with an interface like this:

package cruft.salary;

/**

* SalaryCalculator

* User: Michael

* Date: Jul 21, 2007

* Time: 1:09:19 PM

*/

public interface SalaryCalculator

{

double calculateSalary(double timeWorked, double sales);

}

Have separate implementations for each of the cases.

%

duffymoa at 2007-7-29 14:26:46 > top of Java-index,Java Essentials,New To Java...
# 12

> But, for the OP's education, I might start with an

> interface like this:

>

Yep, agree that a little interface to tie all of the OP's classes together would be nice. But I doubt s/he's even hit OOP or classes yet given the looks of his/her code.

petes1234a at 2007-7-29 14:26:46 > top of Java-index,Java Essentials,New To Java...
# 13

> Yep, agree that a little interface to tie all of the

> OP's classes together would be nice. But I doubt

> s/he's even hit OOP or classes yet given the looks of

> his/her code.

So tell me why you suggested a strategy pattern? Was it a chance for you to announce to the world that you've heard of the GoF?

%

duffymoa at 2007-7-29 14:26:46 > top of Java-index,Java Essentials,New To Java...
# 14

> So tell me why you suggested a strategy pattern? Was

> it a chance for you to announce to the world that

> you've heard of the GoF?

>

> %

It was not for the OP's benefit. I was just being a smart-A**. Probably a dumb thing to do, but I'm kind of Pattern-crazy right now, as I am delving into a pattern book (no, not the GoF; mine is more light-weight -- Head First). So I'm seeing patterns everywhere.

petes1234a at 2007-7-29 14:26:46 > top of Java-index,Java Essentials,New To Java...