Question

Create a Console application for a library and name it FineForOverdueBooks. The Main( ) method asks...

Create a Console application for a library and name it FineForOverdueBooks.

The Main( ) method asks the user to input the number of books that are overdue and the number of days they are overdue. Pass those values to a method that displays the library fine, which is 10 cents per book per day for the first seven days a book is overdue, then 20 cents per book per day for each additional day.

Grading criteria

1. Create a Console application. In the Main( ) method, the user is prompted to enter the number of books that are overdue, and then the number of days they are overdue.

2. Create a user-defined method to compute the fine for overdue books. This method will receive the number of overdue books and the number of days the books are overdue as parameters from the Main( ) method. Then this method will calculate the fine and display it.

3. Compile and test the program to make sure there is no syntax error. Submit the completed program in a .zip file.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

FineForOverdueBooks.java

import java.util.Scanner;

public class FineForOverdueBooks {

public static void main(String[] args) {

//Declaring variables

int noOfOverdueBooks, noOfOverdueDays;

/*

* Creating an Scanner class object which is used to get the inputs

* entered by the user

*/

Scanner sc = new Scanner(System.in);

//Getting the input entered by the user

System.out.print("Enter the number of books that are overdue :");

noOfOverdueBooks = sc.nextInt();

System.out.print("Enter the number of days they are overdue :");

noOfOverdueDays = sc.nextInt();

//calling the method

double fineAmt = calculateFine(noOfOverdueBooks, noOfOverdueDays);

//Displaying the output

System.out.println("Total Fine Amount :$" + fineAmt);

}

/* This method will calculate the fine amount based

* on no of overdue days and no of overdue books

*/

private static double calculateFine(int noOfOverdueBooks,

int noOfOverdueDays) {

double fineAmt = 0.0;

if (noOfOverdueDays <= 7)

fineAmt = noOfOverdueBooks * 0.10;

else if (noOfOverdueDays > 7)

fineAmt = 7 * 0.10 + (noOfOverdueDays - 7) * 0.20;

return fineAmt;

}

}

____________________

Output:

Enter the number of books that are overdue :6
Enter the number of days they are overdue :22
Total Fine Amount :$3.7

_______________Could you plz rate me well.Thank You

Add a comment
Know the answer?
Add Answer to:
Create a Console application for a library and name it FineForOverdueBooks. The Main( ) method asks...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Create the following programs in Java {Java1 difficulty} [Please create as simple as possible] a. Ask...

    Create the following programs in Java {Java1 difficulty} [Please create as simple as possible] a. Ask the user to enter their favorite number and favorite word. Pass both of these values to a method that will print the favorite word vertically the favorite number of times. b. Ask the user to enter 2 integers. Pass the integers to 2 different methods: one method to add the integers and print the sum (from the method); the second method to multiply the...

  • Weather Program Create an application to interacts with a web service in order to obtain data....

    Weather Program Create an application to interacts with a web service in order to obtain data. Program must prompt the user for their city or zip code and request weather forecast data from OpenWeatherMap (https://openweathermap.org). Program must display the weather information in a READABLE format to the user. Requirements: Create a header for your program just as you have in the past. Create a Python Application which asks the user for their zip code or city. Use the zip code...

  • Create a C# console application that performs the following: 1) Build a method which reads 3...

    Create a C# console application that performs the following: 1) Build a method which reads 3 integers from the console and returns them as an int array (type a number, then hit enter, 3 times). This needs to be its own method. 2) Call this method twice to store 2 local int array variables. 3) Once both arrays are built, write another method which accepts the two arrays and compares the contents to see if they match. If the method...

  • Create a C# console application that performs the following: 1) Build a method which reads 3...

    Create a C# console application that performs the following: 1) Build a method which reads 3 integers from the console and returns them as an int array (type a number, then hit enter, 3 times). This needs to be its own method. 2) Call this method twice to store 2 local int array variables. 3) Once both arrays are built, write another method which accepts the two arrays and compares the contents to see if they match. If the method...

  • We use JAVA. Thanks.    Create an application whose main method asks the user to enter...

    We use JAVA. Thanks.    Create an application whose main method asks the user to enter an n by m integer matrix that contains nm integer numbers. n and m should be between 1 and 10. If the user enters a             number less than 1 or greater than 10, the program will continue to ask the user to enter an integer number between 1 and 10. The program should print the sum of the boundary elements of the matrix....

  • Please help me with these two problems. Thank you. Part A Create a console-based application that...

    Please help me with these two problems. Thank you. Part A Create a console-based application that prompts the user to enter the total price of the transaction as well as a sale or discount percentage, then returns the price of the transaction with the percentage discount applied. You should create at least one method that accepts and returns data. Part B Create a console-based application named MealPrice that computes the price of a meal at a pirate-themed restaurant owned by...

  • The Task: Create a console application that prompts the user to select either a stack, queue,...

    The Task: Create a console application that prompts the user to select either a stack, queue, linked list, or binary search tree. Then prompt the user for a number that will then be passed to a recursive function that will populate an array in ascending order. If user selected binary search tree, they will then be prompted to choose how the data will be received either in-order, preorder, or post-order. If user selected linked list, they will then be prompted...

  • // C programming Create a system managing a mini library system. Every book corresponds to a...

    // C programming Create a system managing a mini library system. Every book corresponds to a record (line) in a text file named "mylibrary.txt". Each record consists of 6 fields (Book ID, Title, Author, Possession, checked out Date, Due Date) separated by comma: No comma '', "in title or author name. This mini library keeps the record for each book in the library. Different books can share the book "Title". But the "Book ID" for each book is unique. One...

  • Create a Ruby class Book1. Each book is characterized by the instance variables authnr rf t class . For this class create the initializer and the method show1 that displays the instance variables of...

    Create a Ruby class Book1. Each book is characterized by the instance variables authnr rf t class . For this class create the initializer and the method show1 that displays the instance variables of the Bookl. class Create the class Book2 that inherits properties from the class Bookl and ad variables publisher and price. Write the following Book2 methods e read2 that prompts the user and reads from the keyboard all data for Book e show2 that displays all instance...

  • Write a Java console application that prompts the user to enter the radius of a circle,...

    Write a Java console application that prompts the user to enter the radius of a circle, then prints its radius, diameter, circumference, and area. Write a JavaFX GUI application to do the same calculation, and draw the circle. The Console Output Enter the radius of the circle: 1.2 The radius is 1.2 The diameter is 2.4 The circumference is 7.5398223686155035 The area is 4.523893421169302 Write and document your program per class coding conventions. Add an instance variable double radius. Generate...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT