Q:

A local company has the following monthly charges for snowclearing services:

$250 for 0-5 visits
$250 + $55 for each visit over 55
13% tax is to be charged in each case

if previous balance is not zero, intrest of 4% of that balance is to be charged.

theres also some other stuff i need to include, but this sums up the problem im having:

public class Snow

	{

		private int visit;
		private String name;
		private String month;
		private String address;
		private double pBalance;
		private String mop;
		private double total;
		private double flatRate;

		

		public Snow(String mName, String cName, String cAddress, int numVisit, double preBalance, String methodOP)

		{

			month = mName;

			name = cName;

			address = cAddress;

			visit = numVisit;

			pBalance = preBalance;

			mop = methodOP;
			flatRate = 282.5;

		}



		public double getTotal()

		{
		while ((visit >= 0) && (visit <= 5))

			{

				total = flatRate;

			}



		while (visit>5)

			{

				//wtf goes here.... 

			}

		

		while (pBalance > 0);

			{

				pBalance = pBalance * .04 + pBalance + total;

			}



		return total;

		}

}

When visit is greater then 5, i need to charge &250 + $55 per visit & im having trouble initializing that in java.

if visit > 5; total = 250 + 55 per visit - would be the pseudo code?

Start by charging $250. For each visit over 5, charge $55. That is, if visit > 5, add (visit-5)*$55 to the $250 initial fee.

Here's one of the things you might want to iron out:

while ((visit >= 0) && (visit <= 5)
{

total = flatRate;
}

You're using while loops in what I might charitably call an "idiosyncratic" way here. If the variable you're testing never changes in the course of the loop, then if it's ever true, it'll stay in the loop and never become false - it's a deathtrap.
If you're only executing it once, use an if, not a while.

thanks! i have fixed that problem and have found another one that i cant seem to figure out. heres the full question that should explain to you, what it is im trying to do:

A local company has the following monthly charges for snowclearing services:

$250 for 0-5 visits
$250 + $55 for each visit over 55
13% tax is to be charged in each case

method of payment is by cheque or credit card. for payment by credit card, and extra 3% (of the subtotal, ie. before tax) is charged.

if previous balance is not zero, intrest of 4% of that balance is to be charged.

calculate/output the amount due & month coustomer name and address.

here is my code:

public class Snow

	{

		private int visit;

		private String name;

		private String month;

		private String address;

		private double pBalance;

		private String mop;

		private double total;

		private int flatRate;

		private String cc;

		private String ch;

		private double cCard;

		

		public Snow(String mName, String cName, String cAddress, int numVisit, double preBalance, String methodOP)

		{

			month = mName;

			name = cName;

			address = cAddress;

			visit = numVisit;

			pBalance = preBalance;

			mop = methodOP;

			flatRate = 250;

		}



		public double getTotal()

		{

		if ((visit >= 0) && (visit <= 5))

			{

				total = flatRate;

			}



		 else

			{

				total = (visit - 5) * 55 + flatRate;

			}



		if (mop == cc)

		{

			cCard = (total * .03) + total;

		}

		

		if (pBalance > 0);
		{

			pBalance = pBalance * .04 + pBalance;

		}

		

		total = (pBalance + cCard + total * .13) + total;



		return total;

		}



		public String getInfo()

		{

			return month + " " + name + " " + address + " ";

		}

}

here is my tester code:

public class SnowTester

{



	public static void main(String[]args)

	{

		Snow test = new Snow("January","z00t","daniweb ave.",5,0,"cc");

		System.out.println(test.getTotal());

		System.out.println(test.getInfo());

		System.out.println(" ");

		System.out.println("expect:351.7  ");

	}

}

the prog works perfect for calculating the total if there is no previous balance, payment is cheque and visits is between 0-5 (282.5). also works for visits over 5 and same conditions (344.65). works for visits = n and pbalance = n. my problem is when i choosse cc as method of payment, i cannot get the 3% added to the total, before taxes!!

maybe someone could copy/edit my code? suggestions??

You're using cc as the name of the variable in the class and passing it as the value of the String in your test class. In your Snow class, the variable called cc is never assigned a value, so it's null. The variable mop gets the value "cc", which is not null, so the test fails.

Try using a static final constant for this.

private static final int CC = 1;
private static final int CHECK = 2; 
private static final int CASH= 3;

Then for a credit card order, you'd pass in Snow.CC as a value. The value of that is 1, but that doesn't matter to you, because in your Snow class, you're going to compare that incoming value to a named constant.

if (mop == CC) 
{
  // do credit card stuff;
}

Makes life a lot easier. There are ways that are easier still, but you'll get to those soon enough.

Comments
Always helpful.
This question has already been answered. Start a new discussion instead.