logo Hurry, Grab up to 30% discount on the entire course
Order Now logo

Ask This Question To Be Solved By Our ExpertsGet A+ Grade Solution Guaranteed

expert
Aditya ChopraComputer science
(5/5)

971 Answers

Hire Me
expert
Rashmi AgnihotriComputer science
(5/5)

852 Answers

Hire Me
expert
Aashi NagpalOthers
(5/5)

921 Answers

Hire Me
expert
Catherine Chanwai EarleLaw
(5/5)

713 Answers

Hire Me
Java Programming

Create a program that allows a user to purchase one or more of the laptops listed. Logical Control Structures from PA1 with changes in brown: Use a while loop to process for multiple laptops a given purchase

INSTRUCTIONS TO CANDIDATES
ANSWER ALL QUESTIONS

OBJECTIVE: Code a program that uses the concepts covered in chapters 1-5 and lecture. This is the same program as PA1 except you’ll be recoding it with a combination of void, value-returning, and value-receiving methods. The output is the same except for validation of numeric input from the keyboard.

PREP WORK: Chapters 1-5 (including Shepherd’s PowerPoint slides); labs, in-class exercises or demos.

GRADING: You’ll be graded on how well you follow the program instructions and the accuracy of your output as reflected in the prompts, the output specifications, and the sample output.

This includes spacing and line advancing. Each line of output can be associated with multiple points in the code! Please make sure you correct your PA1 for formatting (line advancing, spacing) errors and that it is running with the correct output before attempting PA3. You are not at liberty to change anything, but code to these requirements. You’ll also be graded on the code given to you by your professor for this PA. The instructions are practically identical to PA1 except for the inclusion of methods, and changes to decision structures.

PROGRAM INSTRUCTIONS: Create a program that allows a user to purchase one or more of the laptops listed.

  1. Logical Control Structures from PA1 with changes in brown:

  2. Use a while loop to process for multiple laptops a given purchase. Use a sentinel-controlled loop

      1. Use

        • if-else to figure out the laptop name and its price;

        • or the printing of the error message "Invalid choice! Try "

 

  • if, nested if to figure out when the choice for the laptop is valid to proceed with the rest of the processing for the laptop (quantity, calculations, addition of the laptop information to the final output);

  1. the determination of the laptop name and price will be moved to their respective methods (see method instructions below) and their nested if-else structures will be replaced with switch statements.

  2. if, nested if to only print order summary when laptops are actually

  3. Use printf() with format specifiers where needed. Don’t forget to insert the exit statement at the end of main().

  4. Code for Proper Output Alignment & Justification: where orderSummary is the String variable you’ve already declared and populated with the header information. Now you’ll add each laptop purchase (line item) to that header information. Use right and left justification to align the output. Use += to add to what is already in the orderSummary

  5. Java Statements: ALL Java statements are to be typed exactly as shown. The following if-else prints a $ sign for the first line item; otherwise, there’s no $ sign printed. Change the if-else to a switch with only 2 cases and no default. Look at the output specs above or the sample output. The trigger variable determines the first line item. NOTE: There is a space between the double quotes.

if(trigger == 1)

{

orderSummary += String.format("%n%,-9d %-30s %8s $%,17.2f",

qty, laptop, " ", lineItem);

ç Resets the trigger variable so the code in the else, that

doesn’t print the $ sign, is executed for the next line item.

 

trigger = 0;

}//END if for $ sign. else

{

orderSummary += String.format("%n%,-9d %-30s %9s %,17.2f",

qty, laptop, " ", lineItem);

}//END else for no $ sign.

 

  1. Use printf() with format specifiers where

  2. CODE FOR FINAL OUTPUT:

 

//The following Java statement prints the order summary of the laptops purchased.

//The print should be done when there are no more laptops to process.

if(choice > 0 && choice < 6)

{

tax = subtotal * .0825; total = subtotal + tax;

 

orderSummary += String.format("%n%n%34s Subtotal %6s %,17.2f"

+ "%n%31s Tax @ 8.25%% %6s %,17.2f"

Arguments for the Subtotal line →

Arguments for the Tax line              →

Arguments for the TOTAL line    ä

 

 

+ "%n%n%37s TOTAL %5s $%,17.2f%n",

" ", " ", subtotal,

" ", " ", tax,

" ", " ", total);

 

System.out.printf("%s", orderSummary);

}//END if valid choice from 1 through 5

 

  1. Program Logic: NO plan for this

    1. The prompts (to return press Alt then left arrow) tell you what input variables you will

    2. The final output specifications will tell you the type of calculations you will need (if any) and whether you will need to declare additional

    3. The sample output will tell you the order of logic for your

  1. Instructions for Coding Methods: Only code what is asked for in these methods and nothing more.

    1. Values that are returned by methods, and used multiple times in the method that calls for the value, should be stored in local

    2. Variables used in more than one method should be fields (class variables). There are 3 fields: objects for the classes that are imported; orderSummary.

    3. main(): Only 2 lines of code: processOrder() is called and the exit

    4. processOrder(): This method is not value-receiving or value-returning. It contains all the code that was originally in main().

  • Move the code from main() to this method, then work line-by-line to determine which variables will be fields (class variables), and which will be local, and which statements are to be moved to the other

  • The while-loop, the IF-ELSEs, the calculations remain in this

    1. Use a logical operator to range test the

    2. Replace the if-else for the trigger with a switch. Use 2 cases no

  • The print for the error message will now be in an else option for the first range test of

  • The other methods will be called in processOrder(). In processOrder(), these methods are called in place of the code that was moved into

    1. Other methods:

  • setLaptopChoice(): Prompts for the laptop choice and returns it from the keyboard. Validate the integer input before returning it using a while validation

  • setLaptopName(): Receives the laptop choice and returns the name of the laptop. Use a switch statement to determine the laptop

  • setLaptopPrice(): Receives the laptop choice and returns the price of the laptop. Use a switch statement to determine the laptop price.

  • setLaptopQty(): Receives the laptop name, prompts for the quantity, and returns it from the keyboard. Validate the integer input before returning it using a while validation loop. Use in calculation of the lineItem.

  • getErrorMsg(): Returns the formatted String for the error message “Invalid choice! Try ”.

Related Questions

. The fundamental operations of create, read, update, and delete (CRUD) in either Python or Java

CS 340 Milestone One Guidelines and Rubric  Overview: For this assignment, you will implement the fundamental operations of create, read, update,

. Develop a program to emulate a purchase transaction at a retail store. This  program will have two classes, a LineItem class and a Transaction class

Retail Transaction Programming Project  Project Requirements:  Develop a program to emulate a purchase transaction at a retail store. This

. The following program contains five errors. Identify the errors and fix them

7COM1028   Secure Systems Programming   Referral Coursework: Secure

. Accepts the following from a user: Item Name Item Quantity Item Price Allows the user to create a file to store the sales receipt contents

Create a GUI program that:Accepts the following from a user:Item NameItem QuantityItem PriceAllows the user to create a file to store the sales receip

. The final project will encompass developing a web service using a software stack and implementing an industry-standard interface. Regardless of whether you choose to pursue application development goals as a pure developer or as a software engineer

CS 340 Final Project Guidelines and Rubric  Overview The final project will encompass developing a web service using a software stack and impleme