logo Use CA10RAM to get 10%* Discount.
Order Nowlogo
(5/5)

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 ”.

(5/5)
Attachments:

Related Questions

. Introgramming & Unix Fall 2018, CRN 44882, Oakland University Homework Assignment 6 - Using Arrays and Functions in C

DescriptionIn this final assignment, the students will demonstrate their ability to apply two ma

. The standard path finding involves finding the (shortest) path from an origin to a destination, typically on a map. This is an

Path finding involves finding a path from A to B. Typically we want the path to have certain properties,such as being the shortest or to avoid going t

. 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. The LineItem class will represent an individual

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

. SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of Sea Ports. Here are the classes and their instance variables we wish to define:

1 Project 1 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of

. Project 2 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of Sea Ports. Here are the classes and their instance variables we wish to define:

1 Project 2 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of

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

expert
Um e HaniScience

712 Answers

Hire Me
expert
Muhammad Ali HaiderFinance

569 Answers

Hire Me
expert
Husnain SaeedComputer science

690 Answers

Hire Me
expert
Atharva PatilComputer science

997 Answers

Hire Me