Answer To: Object Oriented Programming Task 1 In a bookstore, customers can choose to have their books sent to...
Sayed Shad Ahmad answered on Nov 07 2021
Solution/Task1.java
Solution/Task1.java
//Importing Scanner class for user input
import java.util.Scanner;
//Class Task1
public class Task1
{
//Method to calculate shipping price for given number of boxes
public static int calcShipPrice(int box)
{
//Declaring variable to store shipping price
int price;
/*
* Calculating shipping price
*/
if(box <= 5)
price = 8 * box;
else
price = 5 * box;
//Returning shipping price
return price;
}
//main method
public static void main(String[] args)
{
//Creating Scanner object for user input
Scanner sc = new Scanner(System.in);
//Declaring constant for maximum number of books per box
final int max = 5;
//Declaring variable to store data entered by user
String data;
//Declaring variable to store number of books & boxes required
int books, boxes;
//Declaring variable to store number of full boxes required & books in partially filled box
int fullBoxes, partialBox;
//Declaring an array to store name of numbers
String numberNames[] = { "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten",
"eleven", "twelve", "thirteen", "fourteen", "fifteen",
"sixteen", "seventeen", "eighteen", "nineteen", "twenty",
"twenty-one", "twenty-two", "twenty-three", "twenty-four", "twenty-five",
"twenty-six", "twenty-seven", "twenty-eight", "twenty-nine", "thirty",
"thirty-one", "thirty-two", "thirty-three", "thirty-four", "thirty-five",
"thirty-six", "thirty-seven", "thirty-eight", "thirty-nine", "forty",
"forty-one", "forty-two", "forty-three", "forty-four", "forty-five",
"forty-six", "forty-seven", "forty-eight", "forty-nine", "fifty" };
//Repeating until user enters valid number of books
do
{
//Requesting number of books from user
System.out.println("How many books do you have for shipping?");
data = sc.nextLine();
//try block
...