Skip to content

Instantly share code, notes, and snippets.

@PVaid
Created May 24, 2017 02:57
Show Gist options
  • Save PVaid/07265c3fee7019c583b237289a578cc9 to your computer and use it in GitHub Desktop.
Save PVaid/07265c3fee7019c583b237289a578cc9 to your computer and use it in GitHub Desktop.
Animal Love!!
import java.util.Scanner;
public class DogRegistration
{
public void processDogs()
{ double total_fees=0;
double total_discount = 0;
for(int i=0;i<3;i++)
{
double fee, disct;
Scanner sc=new Scanner(System.in);
System.out.println("Welcome to Dog Registration Program");
System.out.print("Enter the name of dog" +(i+1)+" ==>");
String name=sc.nextLine();
System.out.print("Enter the age of "+" " +name+ " "+"dog in years ==>");
int age=sc.nextInt();
System.out.println("Is "+name+ " "+"dog de-sexed (Y/N) ==>");
String response=sc.next();
fee = this.calculateFee(age, response);
total_fees+=fee;
System.out.print("Enter any additional discount as percentage ==>");
double discount=sc.nextDouble();
disct = this.calculateDiscount(fee, discount);
System.out.println("Statistic for dog"+name);
System.out.println("------------------------------------------------");
System.out.println("Fee: "+fee);
System.out.println("Discounts: "+disct);
System.out.println("------------------------------------------------");
total_discount+=disct;
}
finalOutput(total_fees, total_discount);
}
public double calculateFee(int age, String response)
{
if(age>=10)
{
return 15.00;
}
else if((age<10)&&response.equals("y")||response.equals("Y"))
{
return 25.00;
}
else if((age<10)&&response.equals("n")||response.equals("N"))
{
return 45.00;
}
return 0;
}
public double calculateDiscount(double rs, double discount) //error
{
double discountCal=(rs*(discount/100));
return (rs-discountCal);
}
public void finalOutput(double total_fees,double total_discount)
{
System.out.println("Final statistics");
System.out.println("------------------------------------------------");
System.out.println("Total fees "+total_fees );
System.out.println("Total discounts "+total_discount );
System.out.println("------------------------------------------------");
}
public static void main(String args[])
{
DogRegistration dogRegistration=new DogRegistration();
dogRegistration.processDogs();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment