Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. PROGRAMMING ASSIGNENT 1 Read CSE 11 Laboratory Guide Read Deitel: Ch 1-4, App

ID: 3854442 • Letter: 1

Question

1. PROGRAMMING ASSIGNENT 1 Read CSE 11 Laboratory Guide Read Deitel: Ch 1-4, Appendix A-D, (F on ang: Ch 1-3, 4.6, Appendix A-c Programming: Name your application progran aturday, July 8, 2017 6:00an (Note: xx in the login: "callux" is your ni for turn in.) In: "calluxx is your unique login name and required Write a program to calculate an online book order types,1oops, and decisions a, a program to calculate an online book order for a student using data Input will be student name, isbn International Standard Book Number), vendor cholce,a The switch statement will determine the price associated w book choice. All other decisions will be using the a ), vendor choice, and program repeat. ith the ve d if-else constructs. The do 1oop will repeat the book number input, and the while 1oop wi1 entire program, a for loop will reduce the user 1 range the check the vendor input. Use type long integer, "1ong" for your variable that holds your data given by the grader will be one integer n 9223372036854775807 to 92233720368547758087 (mallest and larges input r in the range The of integer: 2-1). Use given code in Box below to use Scanner tor input. import java.util.Scanner? public class P1 // Scanner for input public static void main String args)) final long MAX_ISBN 10 999999999: final long BOOK1 final long BOOK2 final long BOOK3 final double PRICE3C -29.99; // Upper bound ISBN-10 // #1 Liang ISBN // #2 Deitel ISBN // #3 Unix ISBN // #3 Unix OCSD price - 134611037: - 134791401; 596002619; - char choice; char vendor // Repeat loop // Which online vendoz // Which ISBN long isbn double price: scanner scan = new Scanner (System.in); / Total price book order // Read input from keyboard // Input string reference // Assign to string Input student name String inputStr null System.out.print ("Enter students' name:) name scan.next (); system.out.print crEnter 1588-10 (omit hyphens and leadting tezons):) isbn scan.nextLong ) // Assign to long System.out.print ("Want to order more books (y/n)2") inputstr = scan.next(); // Read and assign to String /7 Assign to character // Loop while NOT n nor N // Close Scanner choice = inputstr.charAt(0); scan.close();

Explanation / Answer

Solution: See the code below:

------------------------------------------

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package onlinebook;

import java.util.Scanner; //scanner for input

/**
*
* P1 class
*/
public class P1 {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        final long MAX_ISBN_10 = 999999999; //Upper bound ISBN-10
        final long BOOK1 = 134611037; //#1 Linag ISBN
        final long BOOK2 = 134791401; //#2 Deitel ISBN
        final long BOOK3 = 596002619; //#3 Unix ISBN
        final double PRICE_1A = 143.74; //#1 Liang BarnesNoble price
        final double PRICE_2A = 134.90; //#2 Deitel BarnesNoble price
        final double PRICE_3A = 16.99; //#3 Unix BarnesNoble price
        final double PRICE_1B = 143.74; //#1 Liang BarnesNoble price
        final double PRICE_2B = 134.90; //#2 Deitel BarnesNoble price
        final double PRICE_3B = 24.75; //#3 Unix BarnesNoble price
        final double PRICE_1C = 158.00; //#1 Liang UCSD price
        final double PRICE_2C = 149.00; //#2 Deitel UCSD price
        final double PRICE_3C = 29.99; //#3 Unix UCSD price

        char choice = 0; //Repeat loop
        char vendor; //which online vendor
        long isbn; //which ISBN
        double price = 0.0; //Total price book order

        Scanner scan = new Scanner(System.in); //Read input from keyboard
        String name = null; //Input student name
        String inputStr = null; //Input string reference

        System.out.println("Enter students' name: ");
        name = scan.next(); //Assign to string
        do {
            //price list
            System.out.println(" CSE 11 TEXT BOOK ONLINE ORDER");
            System.out.println("==============================================");
            System.out.println("1) Intro. to Java Programming Brief: Liang");
            System.out.println("2) Java How to Program Late Objects: Deitel");
            System.out.println("3) Learning the Unix O/S: Peek, Todino, Strang");
            System.out.println("==============================================");
            System.out.println(" A)AMAZON B)BarnesNoble C)UCSD");
            System.out.println("----------------------------------------------");
            System.out.println("1) $" + PRICE_1A + " $" + PRICE_1B + " $" + PRICE_1C);
            System.out.println("1) $" + PRICE_2A + " $" + PRICE_2B + " $" + PRICE_2C);
            System.out.println("1) $" + PRICE_3A + " $" + PRICE_3B + " $" + PRICE_3C);
            System.out.println("----------------------------------------------");
            //loop for isbn
            do {
                System.out.println("Enter ISBN-10 (omit hyphens and leading zeros): ");
                isbn = scan.nextLong(); //Assign to long
                if (isbn >= BOOK1 && isbn <= BOOK3) {
                    for (;;) {
                        if (isbn >= 0 && isbn < MAX_ISBN_10) {
                            break;
                        }
                        isbn %= 10;
                    }
                    break;
                } else if (Character.isSpaceChar((char) isbn)) {
                    System.err.println("ISBN can not be blank.");
                } else {
                    System.err.println("ERROR: None of these books!");
                }
            } while (true);
            while (true) //loop for vendor
            {
                System.out.println("Enter vendor letter (A-C): ");
                inputStr = scan.next();
                vendor = inputStr.toUpperCase().charAt(0);
                if (vendor >= 'A' && vendor <= 'C') {
                    //if-else to select proper book
                    if (isbn == BOOK1) {
                        //switch statement for processing order
                        switch (vendor) {
                            case 'A':
                                price = PRICE_1A;
                                break;
                            case 'B':
                                price = PRICE_1B;
                                break;
                            case 'C':
                                price = PRICE_1C;
                                break;
                        }
                        System.out.println(name + ", your total price for ISBN# " + isbn + " is $" + price);
                    } else if (isbn == BOOK2) {
                        //switch statement for processing order
                        switch (vendor) {
                            case 'A':
                                price = PRICE_2A;
                                break;
                            case 'B':
                                price = PRICE_2B;
                                break;
                            case 'C':
                                price = PRICE_2C;
                                break;
                        }
                        System.out.println(name + ", your total price for ISBN# " + isbn + " is $" + price);
                    } else if (isbn == BOOK3) {
                        //switch statement for processing order
                        switch (vendor) {
                            case 'A':
                                price = PRICE_3A;
                                break;
                            case 'B':
                                price = PRICE_3B;
                                break;
                            case 'C':
                                price = PRICE_3C;
                                break;
                        }
                        System.out.println(name + ", your total price for ISBN# " + isbn + " is $" + price);
                    }
                    break;
                } else {
                    System.err.println("ERROR: range(A-C)!");
                }
            }
            System.out.println("Want to order more books (y/n)? ");
            inputStr = scan.next(); //Read and assign to string
            choice = inputStr.charAt(0); //Assign to character
        } while (choice != 'n');//Loop while not n or N
        scan.close(); //close scanner
    }
}

-----------------------------------------

Output:

-------------------------------------------------

Enter students' name:
Jo
       CSE 11 TEXT BOOK ONLINE ORDER
==============================================
1) Intro. to Java Programming Brief: Liang
2) Java How to Program Late Objects: Deitel
3) Learning the Unix O/S: Peek, Todino, Strang
==============================================
   A)AMAZON   B)BarnesNoble   C)UCSD
----------------------------------------------
1)   $143.74       $143.74       $158.0
1)   $134.9       $134.9       $149.0
1)   $16.99       $24.75       $29.99
----------------------------------------------
Enter ISBN-10 (omit hyphens and leading zeros):
134611037
Enter vendor letter (A-C):
A
Jo, your total price for ISBN# 134611037 is $143.74
Want to order more books (y/n)?
n

---------------------------------