Question

In: Computer Science

Write a program that prints the insurance fee to pay for a pet according to the...

Write a program that prints the insurance fee to pay for a pet according to the following rules:(NOTE:You must use a switch statement to determine pet fee.)A dog that has been neutered costs $50.A dog that has not been neutered costs $80.A cat that has been spayedcosts $40.A cat that has not been spayedcosts $60.A bird or reptile costs nothing.Any other animal generates an error message.The program should prompt the user for the appropriate information: a character code for the pet type, and a yes/no response for the neutered status. Use a code letter to determine the kind of animal (i.e. D or d represents a dog, C or c represents a cat, B or b represents a bird, R or r represents a reptile, and anything else represents some other kind of animal). Use a code letter to determine the neutered/spayedstatus(i.e. Y or y represents yes, N or n represents no). The user should be allowed to enter the input in either upper or lower case.It prints out the type of animal (full name of animal) and the insurance fee. Any error in input data should generate an error message “Invalid data –no fee calculated”.

Solutions

Expert Solution

Code:

=====

import java.util.Scanner;

public class PetFee {

static Scanner sc;

static String pet_code, neut_stat;

static int cost = 0;

public static void main(String[] args) {

sc = new Scanner(System.in);

System.out.print("Enter pet code: ");

pet_code = sc.nextLine();

System.out.println();

if(pet_code.equalsIgnoreCase("B") || pet_code.equalsIgnoreCase("R")){

System.out.println("Bird/Reptile doesn't cost anything");

System.exit(0);

}

  

System.out.print("Enter neutered/spayed status: ");

neut_stat = sc.nextLine();

System.out.println();

if(pet_code.equalsIgnoreCase("D") && neut_stat.equalsIgnoreCase("Y")){

System.out.println("Neutered dog costs: "+60);

}

else if(pet_code.equalsIgnoreCase("D") && neut_stat.equalsIgnoreCase("N")){

System.out.println("Un-neutered dog costs: "+80);

}

else if(pet_code.equalsIgnoreCase("C") && neut_stat.equalsIgnoreCase("Y")){

System.out.println("Neutered cat costs: "+40);

}

else if(pet_code.equalsIgnoreCase("C") && neut_stat.equalsIgnoreCase("N")){

System.out.println("Un-neutered cat costs: "+60);

}

else{

System.out.println("Invalid data – no fee calculated");

}

}

}

Output screen:

============


Related Solutions

Write a C++ program that prints the insurance fee to pay for apet according to...
Write a C++ program that prints the insurance fee to pay for a pet according to the following rules:(NOTE:You must use a switch statement to determine pet fee.)A dog that has been neutered costs $50.A dog that has not been neutered costs $80.A cat that has been spayedcosts $40.A cat that has not been spayedcosts $60.A bird or reptile costs nothing.Any other animal generates an error message.The program should prompt the user for the appropriate information: a character code for...
Writes a program that prints the insurance fee to pay for a Vehicle according to the following rules:
C++ ProgrammAutomobile Insurance Program:Writes a program that prints the insurance fee to pay for a Vehicle according to the following rules:A Honda that is All Wheel Drive costs $450.A Honda that is two wheels drive costs $350.A Toyota that is All Wheel Drive costs $300.A Toyota that is Two Wheel Drive costs $250.A Nissan that is All Wheel Drive costs $200.A Nissan that is Two Wheel Drive costs $280Any other type of vehicle generates an error message. The program should...
Automobile Insurance Program: Writes a program that prints the insurance fee to pay for a Vehicle...
Automobile Insurance Program: Writes a program that prints the insurance fee to pay for a Vehicle according to the following rules: A Honda that is All Wheel Drive costs $450. A Honda that is two wheels drive costs $350. A Toyota that is All Wheel Drive costs $300. A Toyota that is Two Wheel Drive costs $250. A Nissan that is All Wheel Drive costs $200. A Nissan that is Two Wheel Drive costs $280.
Automobile Insurance Program: Writes a program that prints the insurance fee to pay for aVehicle...
Automobile Insurance Program:Writes a program that prints the insurance fee to pay for a Vehicle according to the following rules:A Honda that is All Wheel Drive costs $450.A Honda that is two wheels drive costs $350.A Toyota that is All Wheel Drive costs $300.A Toyota that is Two Wheel Drive costs $250.A Nissan that is All Wheel Drive costs $200.A Nissan that is Two Wheel Drive costs $280.
Write a program that asks the user for an integer. The program checks and prints to...
Write a program that asks the user for an integer. The program checks and prints to the screen whether the number is prime or not. For example, if user enters 17, the program should print “17 is prime”; if the user enters 20, the program should print “20 is not prime”. please do it with a “ while Loop”, Thanks..
Programming in C++ Write a program that prints the values in an array and the addresses...
Programming in C++ Write a program that prints the values in an array and the addresses of the array’s elements using four different techniques, as follows: Array index notation using array name Pointer/offset notation using array name Array index notation using a pointer Pointer/offset notation using a pointer Learning Objectives In this assignment, you will: Use functions with array and pointer arguments Use indexing and offset notations to access arrays Requirements Your code must use these eight functions, using these...
Write a Java program that takes in a string and a number and prints back the...
Write a Java program that takes in a string and a number and prints back the string from the number repeatedly until the first character... for example Pasadena and 4 will print PasaPasPaP. Ask the user for the string and a number Print back the string from the number repeatedly until the first character For both programs please utilize: methods arrays loops Turn in screenshots
Write a short program that asks the user for a sentence and prints the result of...
Write a short program that asks the user for a sentence and prints the result of removing all of the spaces. Do NOT use a built-in method to remove the spaces. You should programmatically loop through the sentence (one letter at a time) to remove the spaces.
C program, please Write a program that reads a sequence of 10 integer inputs and prints...
C program, please Write a program that reads a sequence of 10 integer inputs and prints the smallest and largest of the inputs and the number of even and odd inputs. for a beginner please, you could use a while loop,if-else,
*Java program* Use while loop 1.) Write a program that reads an integer, and then prints...
*Java program* Use while loop 1.) Write a program that reads an integer, and then prints the sum of the even and odd integers. 2.) Write program to calculate the sum of the following series where in is input by user. (1/1 + 1/2 + 1/3 +..... 1/n)
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT