6 Replies - 1605 Views - Last Post: 11 January 2013 - 05:38 AM Rate Topic: -----

#1 mrsadams0412  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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  Icon User is offline

  • Perfectly Squared ;)
  • member icon

Reputation: 408
  • View blog
  • 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

Was This Post Helpful? 0
  • +
  • -

#3 pbl  Icon User is offline

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

Reputation: 8334
  • View blog
  • Posts: 31,857
  • 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 ?
Was This Post Helpful? 0
  • +
  • -

#4 raghav.naganathan  Icon User is offline

  • Perfectly Squared ;)
  • member icon

Reputation: 408
  • View blog
  • Posts: 1,440
  • Joined: 14-September 12

Re: Fee Calculator

Posted 07 January 2013 - 02:11 AM

View Postpbl, 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
Was This Post Helpful? 0
  • +
  • -

#5 DarenR  Icon User is offline

  • D.I.C Lover

Reputation: 469
  • View blog
  • Posts: 3,197
  • Joined: 12-January 10

Re: Fee Calculator

Posted 07 January 2013 - 05:54 AM

View Postpbl, 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)
Was This Post Helpful? 0
  • +
  • -

#6 tango185  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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.
Was This Post Helpful? 0
  • +
  • -

#7 Ytry  Icon User is offline

  • D.I.C Head

Reputation: 16
  • View blog
  • 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 :o
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1