3. Program Logic: import Stmts: List the classes to be imported so your program can use...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
3. Program Logic: import Stmts: List the classes to be imported so your program can use their code. import Scanner Class Header: What is the name of the class? public class BookSales Class Variables (Fields): Refer to the Class Data Members section of the class diagram for a list of class-level variables or fields which should always be private (-). N/A If no class variables; otherwise list them as: modifier dataType variableName Ex: private String employee Name EPH Method Purpose: What is the purpose of the method? Method Header Method Variables CODE What is the method name? Refer to the Class Diagram for what they are. Prompts Identify the variables requiring prompts. Prompt according to the program specifications in the assignment instructions. Calculations Identify the variables storing calculated values and the formula. Print Identify the variables to be printed and print according to output specifications in the IPO chart. Algorithms о COP The control structures will be pseudocoded here in logical sequence. The control structures such as the loops and decisions are pseudocoded similar to the programming language except you don't use braces and semicolons Some test expressions are pseudocoded using language independent symbols 。 Ex: if and if/else decision structures if choice> 1 statement(s) endIf (a close brace in Java) if choice < 1 1. Program Purpose: Input 2. Class Diagram: Class Name Class Data Members Method Data Members Methods Plan for PA Processing Output 3. Program Logic: import Stmts: import NameOfClass Class Header: public class Name Of YourClass Class Variables (Fields): Refer to the Class Data Members section of the class diagram for a list of class-level variables or fields which should always be private (-). METHOD LOGIC TABLE ✔RECOPY FOR EACH METHOD IN YOUR PROGRAM. Method Purpose: Method Header Method Variables CODE Prompts Input Variables Input Prompt Calculations Formulas Print Output Algorithms import java.util.Calendar; import java.util.Scanner; public class Insurance Calculator { /** * Main Method for performing operation * @param args */ public static void main(String[] args) { String insured, message = null, coverage; double homeInsVal, richter, payout = 0, deductible = 0; char cont, correct = 0, another = 0; Scanner scanner = new Scanner(System.in); Calendar dateTime; // Prompt #1 System.out.printf("\nMUTUALLY ACCIDENTAL, INC."); System.out.printf("\n\nDo you want an analysis of earthquake coverage for your property? Enter 'Y' or 'N': "); cont = scanner.next().toUpperCase().charAt(0); while (cont == 'Y') { System.out.printf("\nMUTUALLY ACCIDENTAL, INC."); System.out.printf("\nEarthquake Coverage Analyzer"); // Prompt #2 System.out.printf("Please enter your name: "); scanner.nextLine(); insured = scanner.nextLine(); dateTime = Calendar.getInstance(); coverage = String.format( "\n\nPAYOUT FOR EARTHQUAKE DAMAGE" + "%n\nHomeowner: %s" + "\n\nDate: %tD" + "%nTime: Strån", insured, dateTime, dateTime); do { do { // Prompt #3 System.out.printf("Please enter the insured value of your home: "); home InsVal = scanner.nextDouble(); // Prompt #4 printRichterScale(); System.out.printf("\nPlease enter the Richter scale value for the earthquake: "); richter = scanner.nextDouble(); if (richter < 0) { } else { System.out.printf("Invalid! Cannot enter negative values."); continue; if (richter >= 9.0) { payout home InsVal * 90 / 100; deductible = home InsVal * 10 / 100; message = "Total destruction. } else if (richter >= 8.0) { payout = home InsVal * 80 / 100; deductible = home InsVal * 20 / 100; message = "Most structures fell."; } else if (richter >= 7.0) { payout home InsVal * 70 / 100; deductible = homeInsVal * 30 / 100; message = "Many buildings destroyed."; } else if (richter >= 6.0) { payout = home InsVal * 60 / 100; deductible = home InsVal * 40 / 100; message = "Many buildings considerable damaged, some collapsed."; } else if (richter > 4.5) { payout home InsVal * 50 / 100; deductible = home InsVal * 50 / 100; message = "Damage to poorly constructed buildings."; } else if (richter >= 3.5) { payout home InsVal * 0 / 100; deductible = home InsVal * 0 / 100; message = "Felt by many peole, no destruction."; } else if (richter >= 0.0) { } payout = homeInsVal * 0 / 100; deductible = home InsVal * 0 / 100; message = "Generallly not felt by people."; // Prompt #5 System.out.printf("Your Name: %s%n", insured); System.out.printf("Home's Insured Value: $%, .2f%n", home InsVal); System.out.printf("Richter Scale: Z%.2f\n", richter); System.out.printf("\nIs this Information correct? 'Y' or 'N' "); correct = scanner.next().toUpperCase().charAt(0); } } } while (correct == 'N'); coverage += String.format( "%%-52s $43 $%,20.2f" + "\nDeductible £475 %,20.2f" + "%n %46 TOTAL %43 $ %,20.2f\n", message, "", payout, "", deductible, "", , payout + deductible); if (correct == 'Y') { // Prompt #6 } System.out.printf("%nDo you have another property? 'Y' or 'N' "); another = scanner.next().toUpperCase().charAt(0); } while (another == 'Y'); System.out.printf (coverage); // Prompt #7 System.out.printf("\nEnter 'Y' to continue with another home owner or 'N' to exit: "); cont = scanner.next().toUpperCase().charAt(0); if (cont == 'N') { System.out.printf("Thank you for using the Eathquake Coverage Analyzer."); } else if (cont_!= 'Y' && cont != 'N') { System.out.printf("Invalid input."); } scanner.close(); } /** * Print Richter Scale */ private static void printRichterScale() { System.out.printf("\nRichter Scale + " 8.0 6.0 Damage Assessment\n" + " Most structures fell.\n" + " 9.0+ 7.0 Total destruction.\n" Many buildings destroyed.\n" 4.5 3.5 0 Many buildings considerable damaged, some collapsed.\n" Damage to poorly constructed buildings.\n" Felt by many peole, no destruction.\n" Generallly not felt by people.\n"); 1. Program Purpose: What is the purpose of the program? To understand how to code a program you must first understand its purpose. IPO CHART Input What are the variables necessary to capture data into the program? Processing What type of processing will occur - particularly calculations? Formatting Output: Be aware of the spacing, punctuation, and line advance requirements in the output. Double line advance means 1 blank space between lines, etc. HEADER w/Variables HEADERS w/Company Info LINE LABELS & VARIABLES C SUMMARY LABELS & VARIABLES Output What will the output look like? Looking at the output will tell you the logic of the program. In addition to data, output will also have headers and labels. Headers identify the type of output and labels identify each specific data item in the output. Headers, labels, and spacing don't change so they are entered permanently in the program. Any output that is derived from variables (fields) is data that can change so indicate string and/or character data with Xs and numeric data with 9s and use Zs to indicate suppression of leading zeroes with $ signs and commas where needed. Example: BOOK SALES FOR 9999 Emma's Bookmart DeZavala Road San Antonio, TX XXXXXXXXX Sales XXXXXXXXX Sales TOTAL SALES: PROFIT MARGIN: $ZZ,ZZ9.99 ZZ,ZZ9.99 SZZZ.ZZ9.99 ZZ9.99% 2. Class Diagram: Class Name What is the name of the class program? Examples: OrderBooks, BookSales, Registerclasses, BuyGroceries, LastNameFirstInitialPANO Data Members or Variables Data Members ■ ■ variables declared at the class level are class variables or fields and should be declared as private unless they belong to a superclass then they are declared as protected. Variables declared at the method level are local variables and have no access modifiers. If variables are to be used by more than one method, they should be class variables or fields. Class Modifiers or access modifiers: designate how accessible a variable is and are used in declaring variables at the class level. Class variables are declared the same way as ones for methods, except they require a modifier and the modifier appears before the variable name. o sign means private (belongs only to the class) o + sign means public (belongs to any class) o # sign means protected (belongs to classes in the same family) o Format: modifier variableName: dataType o Multiple variables of the same type can be listed together: o Ex: -choice, quantity, bookCount, size, count: int -keyboard: Scanner -price, total cost, taxAmount, subtotal, averageBookPrice: double -totals: double[] -itemName, sales Receipt, receiptHeader: String -decimal: COPYR Data Members DecimalFormat OR -decimal: Decimal Format("#,##0.00") -money: NumberFormat -SALES TAX: double Variables for input and for output. Most of the time output variables are input variables. Sometimes there are variables that contain data that has been processed such as variables involved in calculations. Identifiers are the names that you give to the variables. variables (local variables) do not need modifiers. Method Plan Instructions V2 Methods ■ Format: identifierName: dataType o Ex: noOfBooks: int totalBkSales: double Reference variables for objects. These variables reference or point to objects of programs that contain multiple values. ■ Format: objectName: dataType o Ex: input: Scanner o Ex: totals []: double ■ If listing more than one method then separate variables for each method by the method name. Ex: main() SPARDY noofBooks, month, year: int avgBkPrice, totalвkSales, booksales, discountMargin, profitMargin: double monthName: String input: Scanner displayData() now: Date date: String formatter: SimpleDateFormat An application is a class program that usually has one method and it is the main(). The main() puts into motion the rest of the code. ■ A class is a program without the main() and it usually has 3 basic methods 。 one that captures input. One that processes that input. o One that takes care of the output. All other methods support the above three. If code is being repeated in each of the basic methods then it is a good idea to put that code in a method of its own so that the method can be called by the basic methods. o All methods are declared with a modifier. COP Format: modifier methodName (parameter list): returnType o Ex: +main(String[] args): void A public method that receives values in a string array through its parameter list and returns nothing o Ex: -displayData(): void A private method that receives nothing through its parameter list and returns nothing 3. Program Logic: import Stmts: List the classes to be imported so your program can use their code. import Scanner Class Header: What is the name of the class? public class BookSales Class Variables (Fields): Refer to the Class Data Members section of the class diagram for a list of class-level variables or fields which should always be private (-). N/A If no class variables; otherwise list them as: modifier dataType variableName Ex: private String employee Name EPH Method Purpose: What is the purpose of the method? Method Header Method Variables CODE What is the method name? Refer to the Class Diagram for what they are. Prompts Identify the variables requiring prompts. Prompt according to the program specifications in the assignment instructions. Calculations Identify the variables storing calculated values and the formula. Print Identify the variables to be printed and print according to output specifications in the IPO chart. Algorithms о COP The control structures will be pseudocoded here in logical sequence. The control structures such as the loops and decisions are pseudocoded similar to the programming language except you don't use braces and semicolons Some test expressions are pseudocoded using language independent symbols 。 Ex: if and if/else decision structures if choice> 1 statement(s) endIf (a close brace in Java) if choice < 1 1. Program Purpose: Input 2. Class Diagram: Class Name Class Data Members Method Data Members Methods Plan for PA Processing Output 3. Program Logic: import Stmts: import NameOfClass Class Header: public class Name Of YourClass Class Variables (Fields): Refer to the Class Data Members section of the class diagram for a list of class-level variables or fields which should always be private (-). METHOD LOGIC TABLE ✔RECOPY FOR EACH METHOD IN YOUR PROGRAM. Method Purpose: Method Header Method Variables CODE Prompts Input Variables Input Prompt Calculations Formulas Print Output Algorithms import java.util.Calendar; import java.util.Scanner; public class Insurance Calculator { /** * Main Method for performing operation * @param args */ public static void main(String[] args) { String insured, message = null, coverage; double homeInsVal, richter, payout = 0, deductible = 0; char cont, correct = 0, another = 0; Scanner scanner = new Scanner(System.in); Calendar dateTime; // Prompt #1 System.out.printf("\nMUTUALLY ACCIDENTAL, INC."); System.out.printf("\n\nDo you want an analysis of earthquake coverage for your property? Enter 'Y' or 'N': "); cont = scanner.next().toUpperCase().charAt(0); while (cont == 'Y') { System.out.printf("\nMUTUALLY ACCIDENTAL, INC."); System.out.printf("\nEarthquake Coverage Analyzer"); // Prompt #2 System.out.printf("Please enter your name: "); scanner.nextLine(); insured = scanner.nextLine(); dateTime = Calendar.getInstance(); coverage = String.format( "\n\nPAYOUT FOR EARTHQUAKE DAMAGE" + "%n\nHomeowner: %s" + "\n\nDate: %tD" + "%nTime: Strån", insured, dateTime, dateTime); do { do { // Prompt #3 System.out.printf("Please enter the insured value of your home: "); home InsVal = scanner.nextDouble(); // Prompt #4 printRichterScale(); System.out.printf("\nPlease enter the Richter scale value for the earthquake: "); richter = scanner.nextDouble(); if (richter < 0) { } else { System.out.printf("Invalid! Cannot enter negative values."); continue; if (richter >= 9.0) { payout home InsVal * 90 / 100; deductible = home InsVal * 10 / 100; message = "Total destruction. } else if (richter >= 8.0) { payout = home InsVal * 80 / 100; deductible = home InsVal * 20 / 100; message = "Most structures fell."; } else if (richter >= 7.0) { payout home InsVal * 70 / 100; deductible = homeInsVal * 30 / 100; message = "Many buildings destroyed."; } else if (richter >= 6.0) { payout = home InsVal * 60 / 100; deductible = home InsVal * 40 / 100; message = "Many buildings considerable damaged, some collapsed."; } else if (richter > 4.5) { payout home InsVal * 50 / 100; deductible = home InsVal * 50 / 100; message = "Damage to poorly constructed buildings."; } else if (richter >= 3.5) { payout home InsVal * 0 / 100; deductible = home InsVal * 0 / 100; message = "Felt by many peole, no destruction."; } else if (richter >= 0.0) { } payout = homeInsVal * 0 / 100; deductible = home InsVal * 0 / 100; message = "Generallly not felt by people."; // Prompt #5 System.out.printf("Your Name: %s%n", insured); System.out.printf("Home's Insured Value: $%, .2f%n", home InsVal); System.out.printf("Richter Scale: Z%.2f\n", richter); System.out.printf("\nIs this Information correct? 'Y' or 'N' "); correct = scanner.next().toUpperCase().charAt(0); } } } while (correct == 'N'); coverage += String.format( "%%-52s $43 $%,20.2f" + "\nDeductible £475 %,20.2f" + "%n %46 TOTAL %43 $ %,20.2f\n", message, "", payout, "", deductible, "", , payout + deductible); if (correct == 'Y') { // Prompt #6 } System.out.printf("%nDo you have another property? 'Y' or 'N' "); another = scanner.next().toUpperCase().charAt(0); } while (another == 'Y'); System.out.printf (coverage); // Prompt #7 System.out.printf("\nEnter 'Y' to continue with another home owner or 'N' to exit: "); cont = scanner.next().toUpperCase().charAt(0); if (cont == 'N') { System.out.printf("Thank you for using the Eathquake Coverage Analyzer."); } else if (cont_!= 'Y' && cont != 'N') { System.out.printf("Invalid input."); } scanner.close(); } /** * Print Richter Scale */ private static void printRichterScale() { System.out.printf("\nRichter Scale + " 8.0 6.0 Damage Assessment\n" + " Most structures fell.\n" + " 9.0+ 7.0 Total destruction.\n" Many buildings destroyed.\n" 4.5 3.5 0 Many buildings considerable damaged, some collapsed.\n" Damage to poorly constructed buildings.\n" Felt by many peole, no destruction.\n" Generallly not felt by people.\n"); 1. Program Purpose: What is the purpose of the program? To understand how to code a program you must first understand its purpose. IPO CHART Input What are the variables necessary to capture data into the program? Processing What type of processing will occur - particularly calculations? Formatting Output: Be aware of the spacing, punctuation, and line advance requirements in the output. Double line advance means 1 blank space between lines, etc. HEADER w/Variables HEADERS w/Company Info LINE LABELS & VARIABLES C SUMMARY LABELS & VARIABLES Output What will the output look like? Looking at the output will tell you the logic of the program. In addition to data, output will also have headers and labels. Headers identify the type of output and labels identify each specific data item in the output. Headers, labels, and spacing don't change so they are entered permanently in the program. Any output that is derived from variables (fields) is data that can change so indicate string and/or character data with Xs and numeric data with 9s and use Zs to indicate suppression of leading zeroes with $ signs and commas where needed. Example: BOOK SALES FOR 9999 Emma's Bookmart DeZavala Road San Antonio, TX XXXXXXXXX Sales XXXXXXXXX Sales TOTAL SALES: PROFIT MARGIN: $ZZ,ZZ9.99 ZZ,ZZ9.99 SZZZ.ZZ9.99 ZZ9.99% 2. Class Diagram: Class Name What is the name of the class program? Examples: OrderBooks, BookSales, Registerclasses, BuyGroceries, LastNameFirstInitialPANO Data Members or Variables Data Members ■ ■ variables declared at the class level are class variables or fields and should be declared as private unless they belong to a superclass then they are declared as protected. Variables declared at the method level are local variables and have no access modifiers. If variables are to be used by more than one method, they should be class variables or fields. Class Modifiers or access modifiers: designate how accessible a variable is and are used in declaring variables at the class level. Class variables are declared the same way as ones for methods, except they require a modifier and the modifier appears before the variable name. o sign means private (belongs only to the class) o + sign means public (belongs to any class) o # sign means protected (belongs to classes in the same family) o Format: modifier variableName: dataType o Multiple variables of the same type can be listed together: o Ex: -choice, quantity, bookCount, size, count: int -keyboard: Scanner -price, total cost, taxAmount, subtotal, averageBookPrice: double -totals: double[] -itemName, sales Receipt, receiptHeader: String -decimal: COPYR Data Members DecimalFormat OR -decimal: Decimal Format("#,##0.00") -money: NumberFormat -SALES TAX: double Variables for input and for output. Most of the time output variables are input variables. Sometimes there are variables that contain data that has been processed such as variables involved in calculations. Identifiers are the names that you give to the variables. variables (local variables) do not need modifiers. Method Plan Instructions V2 Methods ■ Format: identifierName: dataType o Ex: noOfBooks: int totalBkSales: double Reference variables for objects. These variables reference or point to objects of programs that contain multiple values. ■ Format: objectName: dataType o Ex: input: Scanner o Ex: totals []: double ■ If listing more than one method then separate variables for each method by the method name. Ex: main() SPARDY noofBooks, month, year: int avgBkPrice, totalвkSales, booksales, discountMargin, profitMargin: double monthName: String input: Scanner displayData() now: Date date: String formatter: SimpleDateFormat An application is a class program that usually has one method and it is the main(). The main() puts into motion the rest of the code. ■ A class is a program without the main() and it usually has 3 basic methods 。 one that captures input. One that processes that input. o One that takes care of the output. All other methods support the above three. If code is being repeated in each of the basic methods then it is a good idea to put that code in a method of its own so that the method can be called by the basic methods. o All methods are declared with a modifier. COP Format: modifier methodName (parameter list): returnType o Ex: +main(String[] args): void A public method that receives values in a string array through its parameter list and returns nothing o Ex: -displayData(): void A private method that receives nothing through its parameter list and returns nothing
Expert Answer:
Answer rating: 100% (QA)
Program Logic Import Stmts java import javautilScanner Class Header java public class BookSales Clas... View the full answer
Related Book For
Posted Date:
Students also viewed these programming questions
-
Design a Java class that represents a cache with a fixed size. It should support operations like add, retrieve, and remove, and it should evict the least recently used item when it reaches capacity.
-
Let A, B be sets. Define: (a) the Cartesian product (A B) (b) the set of relations R between A and B (c) the identity relation A on the set A [3 marks] Suppose S, T are relations between A and B, and...
-
Consider the following red-black tree. We perform the following sequence of insertions on this tree: 26, 37, 41, 23. Draw the tree after each operation of this sequence (Note that the operations are...
-
What is the difference between an invention and innovation? What are the differences between incremental versus radical innovations?
-
Desrosiers Ltd. had the following long-term receivable account balances at December 31, 2013: Notes receivable........ $1,800,000 Notes receivable-Employees... 400,000 Transactions during 2014 and...
-
You have a \(2.0-\mathrm{m}\) chain lying on the floor alongside ten \(0.10-\mathrm{kg}\) cubical blocks, each \(0.20 \mathrm{~m}\) on a side. Each block is resting on the floor, and the inertia of...
-
Inferring cash flows From balance sheet and income statement data (Based on a problem prepared by Stephen A. Zeff.) You work for the Plains State Bank in Miles City, Montana, as an analyst...
-
Name and explain 2 differences between using oil futures to fix the price of future purchases and doing the same using swaps.
-
As the accountant for Runson Moving Company, you are preparing the companys annual return, Form 940 and Schedule A. Use the following information to complete Form 940 and Schedule A on pages 5-40 to...
-
Rank the following layers by their depth from the surface of the Earth. Items (4 items) (Drag and drop into the appropriate area) |||| mantle inner core crust outer core Items in order 1 2 Shallowest
-
Albert Inc. currently produces 6000 desks per month. Per unit costs are: Direct materials (UVC) $12 Direct manufacturing labour (UVC) $4 Variable manufacturing overhead (UVC) $5 Fixed manufacturing...
-
Khazanchi is considering an investment proposal with the following cash flows: Initial investment - depreciable assets ........ $90,000 Initial investment - working capital......... 12,500 Net cash...
-
What happens if materiality at the end of the audit is significantly lower than at the beginning of the audit?
-
Cramer Corp. issued $20,000,000 of 5-year, 9% bonds at a market (effective) interest rate of 10%, receiving cash of $19,227.757. Interest on the bonds is payable semiannually. Journalize the entry to...
-
A 4.5-kg, three legged stool supports a 65-kg person. If each leg of the stool has a cross-sectional diameter of 1.8 cm and the weight of the person is evenly distributed, determine the pressure...
-
Installation of a certain hardware takes random time with a standard deviation of 5 minutes. (a) A computer technician installs this hardware on 64 different computers, with the average installation...
-
Players A, B, and C toss a fair coin in order. The first to throw a head wins. What are their respective chances of winning?
-
A committee consists of five executives, three women and two men. Their names are Maria (M), John (J), Susan (S), Will (W), and Holly (H). The committee needs to select a chairperson and a secretary....
-
A factory manager collected data on the number of equipment breakdowns per day. From those data, she derived the probability distribution shown in the following table, where W denotes the number of...
-
The linear correlation coefficient of a set of data points is 0.846. a. Is the slope of the regression line positive or negative? Explain your answer. b. Determine the coefficient of determination.
-
Explain how the miR-200 family of miRNAs behave as tumorsuppressor genes. What happens when their expression is blocked or decreased?
-
Outline the steps that occur when piRITS or piRISC silences transposable elements by repressing transcription and by directly inhibiting TE RNAs, respectively. What is the role of piRNAs in this...
-
List five types of cancer in which ncRNAs can be involved.
Study smarter with the SolutionInn App