# Fee Calculator

Page 1 of 1

## 6 Replies - 2141 Views - Last Post: 11 January 2013 - 05:38 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=305361&amp;s=20bcc45ee526699db590c0cc2193c1b7&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

• New D.I.C Head

Reputation: 0
• Posts: 1
• Joined: 01-January 13

# Fee Calculator

Posted 01 January 2013 - 06:51 PM

This is not a homework assignment anymore, just one that I am doing so that I can try to learn how to do this.
I would like create an application for an animal-fur trimming service. The business is open 15 weeks of the year, from April through July. The fee for a small animal (under 6 pounds) is \$100, a medium animal (under 100 pounds) is \$200, and a large animal (101 pounds and above) is \$300.
What I would like to do is create a program using the Scanner class that will eventually allow me to come up with a total fee for each year, but I am stuck on the language that would calculate the fee.
```import java.util.Scanner;
public class AnimalTrim
{
public static void main(String[] args)
{
double animalFeeTotal;
int animalWeight;
int numberOfTrims;
int year;
final double SMALL_ANIMAL_FEE = 100;
final double MED_ANIMAL_FEE = 200;
final double LRG_ANIMAL_FEE = 300;
Scanner keyboard = new Scanner(System.in);
System.out.print("Enter the weight of the animal");
animalWeight = keyboard.nextInt();
if(animalWeight < 6)
fee = SMALL_ANIMAL_FEE;
else
if(animalWeight > 6 && animalWeight < 101);
fee = MED_ANIMAL_FEE;
else
if(animalWeight > 101)
fee = LRG_ANIMAL_FEE;

}
}

```

What I would like for my code to do is use the weight input to decide the fee, then calculate the total based on the number of animals input, while adding the fee altogether. But I am fairly new and cannot find the resources or a similar problem that can help me figure out how to write the code correctly. I have been working on this for weeks and tried looking so many places, which is why I am now asking for guidance.

This post has been edited by macosxnerd101: 01 January 2013 - 11:19 PM
Reason for edit:: Please use a descriptive title

Is This A Good Question/Topic? 0

## Replies To: Fee Calculator

### #2 raghav.naganathan

• Perfectly Squared ;)

Reputation: 410
• Posts: 1,440
• Joined: 14-September 12

## Re: Fee Calculator

Posted 01 January 2013 - 08:38 PM

Well, have you tried loops? The part of calculating total fees for every animal can be done using loops...something like this...
```System.out.println("Enter the weight of the animal");
animalnum = keyboard.nextInt();

for(int i=0;i<=animalnum;i++)
{
//code for adding fees
}
```

P.S : It would be better to use println instead of print in line 14

regards,
Raghav

This post has been edited by raghav.naganathan: 01 January 2013 - 08:41 PM

### #3 pbl

• There is nothing you can't do with a JTable

Reputation: 8365
• Posts: 31,956
• Joined: 06-March 08

## Re: Fee Calculator

Posted 05 January 2013 - 07:27 PM

Always dangerous to repeat a if condition
```        if(animalWeight < 6)
fee = SMALL_ANIMAL_FEE;
else
if(animalWeight > 6 && animalWeight < 101);

```

what if animalWeigth is 6 ?

### #4 raghav.naganathan

• Perfectly Squared ;)

Reputation: 410
• Posts: 1,440
• Joined: 14-September 12

## Re: Fee Calculator

Posted 07 January 2013 - 02:11 AM

pbl, on 06 January 2013 - 07:57 AM, said:

Always dangerous to repeat a if condition
```        if(animalWeight < 6)
fee = SMALL_ANIMAL_FEE;
else
if(animalWeight > 6 && animalWeight < 101);

```

what if animalWeigth is 6 ?

Well said pbl

To the OP, you can make the if(animalWeight < 6) to if(animalWeight <= 6)

So, in that way, even if the animalWeight is 6, it would calculate it appropriately.

regards,
Raghav

### #5 DarenR

• D.I.C Lover

Reputation: 516
• Posts: 3,472
• Joined: 12-January 10

## Re: Fee Calculator

Posted 07 January 2013 - 05:54 AM

pbl, on 05 January 2013 - 09:27 PM, said:

what if animalWeigth is 6 ?

Then it is tossed to the street...... => (get the smily face LOL)

### #6 tango185

• New D.I.C Head

Reputation: 0
• Posts: 4
• Joined: 10-January 13

## Re: Fee Calculator

Posted 10 January 2013 - 09:17 AM

I think it would be much simpler if you broke your program into methods instead of trying to do everything within the main class.

### #7 Ytry

Reputation: 16
• Posts: 120
• Joined: 25-July 12

## Re: Fee Calculator

Posted 11 January 2013 - 05:38 AM

Well, it is obviously better practice to do things in an OOP design, but perhaps he is new to Java, and hasn't got that far yet