Question
1. Add the import statement import java.util.Scanner; //required for Scanner class. and import javax.swing.JOptionPane; //required for JOptionPane class. with System.exit(0); //required for JOptionPane class. to
1. Add the import statement import java.util.Scanner; //required for Scanner class.
and
import javax.swing.JOptionPane; //required for JOptionPane class.
with
System.exit(0); //required for JOptionPane class.
to your code above the class header except that System.exit(0) must be at the end
of the main method. All the rest of the code shall be in the main method.
-
Declare the following variables:
-
- numberOfBooks of type int
-
- titleLength of type int
-
- unitPrice of type double
-
- totalCost of type double
-
- authorName, bookTitle, publisher, edition, yearPublisher, firstName, middleName, lastName all of type String except yearPublisher of type int
-
- middleInitial of type char
-
- The customer name: cfirstName, cmiddleName, clastName all of type String.
-
- The customer address: streetAddress, cityName, stateName, zipCode all of type
String.
-
-
Declare and instantiate a Scanner object that can read data from the console (suggested reading pp 84-88 of your text)
-
Solicit and read an integer value from the console (you choose the input). Store the input in variable numberOfBooks
-
Solicit and read a number with decimal point from the console (you choose the input). Store the input in variable unitPrice
-
Assign totalCost the total cost of all books
-
Solicit the name of your favorite author on the console. Make sure that there is a first
name, a middle name and a last name in the input. If there is no middle name or you
do not know it, add a replacement name of your own choice.
-
Make Scanner read the first name and store it in variable firstName
Read the middle name and store it in middleName Read the last name and store it in lastName (you will have to call the next( ) method three times)
-
Extract the middle initial as a character from the middle name and store it in middleInitial
-
Re-assign all characters of the lastName to be all uppercase version.
-
Re-build the authors name to be of the format (last name (all in uppercase), first
name middle initial.). Store it variable authorName.
-
Solicit the title of your favorite book on the console
-
Using the nextLine( ) method read the title and store it in variable bookTitle; note
that you will have to make a dummy call of the nextLine( ) before the actual reading
works, see pp 88 91 of your book.
-
Re-assign bookTitle its own all uppercase version
-
To the console, print the authors name, the bookTitle of the book, followed by publisher, edition and year published. Then the length of the title and how old is the book? (If it is a year or less than a year old book, then you should print It is a year old book. If more than a year such as 73 years, then you need to print It is a 73 years old book.)
-
Print the result of the order for the book to console as shown in the following template:
The total cost of 1 book of unit price $245.65 is $ 245.65 from the Jones and Bartlett Publishers.
-
Use JOptionPane input dialog box to prompt whether would like to re-order the book.
If yes, Use JOptionPane input dialog boxes to enter number of the book to be re- ordered and enter the unit price of the book.
-
Print the result regarding the re-ordered information to console as shown in the following template:
The total cost for reordered 5 books of unit price $245.65 is $ 1,228.25 from the Jones and Bartlett Publishers.
19. Your printing must follow exactly the layout as shown below. Use two blocks in which one is for input (You do not have to show the showInputDialog for the input data are used to compute the re-ordered books statement) and then followed by the consecutive printing output statements. (That means, you need to hold off the output until you have all the input data.) Ensure that the singular/plural noun, such as book or books and year or years. You need to use decision structure to get these options.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started