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: 3854219 • 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

import java.util.Scanner;
public class P1
{
public static void main(String args[])
{
final long MAX_ISBN10=999999999;
final long BOOK1=134611037; //liang
final long BOOK2=134791401; //deitel
final long BOOK3=596002619; //unix
final double price_3C=29.99;
double al,ad,au,bl,bd,bu,ul,ud,uu,total,pr;
int c=0;
total=0.0;
al=bl=143.74;
ad=bd=134.90;
ul=158;
ud=149;
uu=29.99;
au=16.99;
bu=24.75;
char choice;
char vendor;
long isbn;
double price;
String name=null;
String inputSt=null;
Scanner sc=new Scanner(System.in);
System.out.println("Enter student's name");
name=sc.nextLine();
do{
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) $"+al+" $"+bl+" $"+ul);
System.out.println("2) $"+ad+" $"+bd+" $"+ud);
System.out.println("3) $"+au+" $"+bu+" $"+uu);
do{
long t,w,r,d;
w=0;
System.out.println("Enter ISBN-10 (omit hyphens): ");
isbn=sc.nextLong();
t=isbn;
int k=0,i;
if(isbn<0 || isbn==MAX_ISBN10)
{
System.out.println("ERROR: None of these books");
}
else{
while(isbn!=0)
{
r=isbn%10;
c=c+1;
isbn=isbn/10;
}
System.out.println(c);
if(c==9 && t>0)
{
w=t;
}
else
{
d=c-10;
for(i=1;i<=d;i++)
k=k*10;
r=t%k;
t=t/k;
w=t;
}
}
}while(c!=9);
if(isbn==BOOK1)
c=1;
else if(isbn==BOOK2)
c=2;
else
c=3;
System.out.println("Enter vendor letter (A-C): ");
vendor=sc.next().charAt(0);
vendor=Character.toUpperCase(vendor);
switch(vendor)
{
case 'A':
pr=(c==1) ? al: (c==2) ? ad : au;
total=total+pr;
System.out.println(name+" your total price for ISBN:"+isbn+"is $"+total);
break;
case 'B':
pr=(c==1) ? bl: (c==2) ? bd : bu;
total=total+pr;
System.out.println(name+" your total price for ISBN:"+isbn+"is $"+total);
break;
case 'C':
pr=(c==1) ? ul: (c==2) ? ud : uu;
total=total+pr;
System.out.println(name+" your total price for ISBN:"+isbn+"is $"+total);
break;
default:
System.out.println("Invalide choice");
break;
}
System.out.println("Want to order more books (Y/N)? ");
choice=sc.next().charAt(0);
}while(choice!='N' || choice!='n');

}
}