Ask Java Expert


Home >> Java

Debugged with the instructions provided:

Guide to Pseudocode

Pseudocode is an intermediary step between reading a problem statement and writing the code to solve the problem. It serves as a blueprint for your program to guide you through, just like contractors start with a blueprint before building a house. Use your pseudocode as a tool to begin thinking about your program, but keep in mind it might not be the final solution to the problem. Pseudocode is written in a natural language using some programming keywords.

Consider the first example below: INCREMENT the number of apples in the basket by one Notice in the example that it fully describes, in natural language, what needs to be done in the program. When writing pseudocode, start at the beginning of what you need the program to do. Then work through, step by step, until reaching the end of what's required by the program in the problem statement. This is putting the problem in sequence.

For example, making a peanut butter sandwich: OBTAIN a plate OBTAIN two slices of bread OBTAIN a jar of peanut butter OBTAIN a knife Place the slices of bread on the plate Open the jar of peanut butter Spread peanut butter on one bread slice with the knife Place the empty slice of bread on top of the slice with peanut butter Serve There are several common keywords that get capitalized as they refer to actions taken in the program.

Those words include READ, WRITE, PRINT, DISPLAY, CALCULATE, SET, INCREMENT, and more. You can also show choices and loops in pseudocode. Just like in coding, when an item is nested inside another item, you indent that line of pseudocode. Below are three generic examples: IF condition THEN Include the first sequence ELSE Include the second sequence ENDIF WHILE condition Include the sequence ENDWHILE FOR loop parameters Include the sequence ENDFOR You can also use the keyword CALL to reference another algorithm written separately.

Now look at the following more complete examples of both good and bad pseudocode to get a general feel of how to write it. Bad Example (Vague and incomplete): function doProgrammingHomework(): Get things for homework Write the code correctly Finish the homework Bad Example (Too technical; does not follow natural language usage): function doProgrammingHomework(): getComputer(); openBlackboard(); for (var count = 0; count < problems.length(); count++) solve(); while (!compile) debug(); submit() shutDownComputer(); Good Example (Follows steps one at a time through the end of the algorithm): function doProgrammingHomework():

GET a computer OPEN the Blackboard module FOR each of the problems in the module Complete problem WHILE the problem does not compile Debug ENDWHILE Submit the assignment ENDFOR Shut down the computer Remember not to make your pseudocode too technical. You are not trying to write the code itself, just a plan as a stepping-stone after the initial problem to get your creative juices flowing.

code that needs to be debugged

import java.util.Scanner;
import java.lang.Math; // Note: Needed for math functions

PaintEstimator.java
public static void main(String[] args) {
Scanner scnr = new Scanner(System.in);
double wallHeight = 0.0;
double wallWidth = 0.0;
double wallArea = 0.0;
double gallonsPaintNeeded = 0.0;
int cansNeeded = 0;

final double squareFeetPerGallons = 350.0;
final double gallonsPerCan = 1.0;

System.out.println("Enter wall height (feet): ");
wallHeight = scnr.nextDouble();

// Prompt user to input wall's width
System.out.println("Enter wall width (feet): ");
wallWidth = scnr.nextDouble();

// Calculate and output wall area
wallArea = wallHeight * wallWidth;
System.out.println("Wall area: "+wallArea+" square feet");

// Calculate and output the amount of paint in gallons needed to paint the wall
gallonsPaintNeeded = wallArea/squareFeetPerGallons;

System.out.println("Paint needed: " + gallonsPaintNeeded + " gallons");

// Calculate and output the number of 1 gallon cans needed to paint the wall, rounded up to nearest integer
cansNeeded = (int) (gallonsPaintNeeded / gallonsPerCan);

if(gallonsPaintNeeded % gallonsPerCan > 0)
cansNeeded += 1;

System.out.println("Cans needed: " + cansNeeded + " can(s)");

return;
}
}

 

Java, Programming

  • Category:- Java
  • Reference No.:- M92374173
  • Price:- $20

Priced at Now at $20, Verified Solution

Have any Question?


Related Questions in Java

Chatbotscreate a small networked chat application that is

Chatbots Create a small, networked chat application that is populated by bots. Introduction On an old server park, filled with applications from the early days of the internet, a few servers still run one of the earliest ...

Assignment taskwrite a java console application that allows

Assignment task Write a java console application that allows the user to read, validate, store, display, sort and search data such as flight departure city (String), flight number (integer), flight distance (integer), fl ...

Assignment game prototypeoverviewfor this assessment task

Assignment: Game Prototype Overview For this assessment task you are expected to construct a prototype level/area as a "proof of concept" for the game that you have designed in Assignment 1. The prototype should function ...

Assignment taskwrite a java console application that allows

Assignment task Write a java console application that allows the user to read, validate, store, display, sort and search data such as flight departure city (String), flight number (integer), flight distance (integer), fl ...

In relation to javaa what is constructor the purpose of

(In relation to Java) A. What is constructor? the purpose of default constructor? B. How do you get a copy of the object but not the reference of the object? C. What are static variables and instance variables? D. Compar ...

Project descriptionwrite a java program to traverse a

Project Description: Write a java program to traverse a directory structure (DirWalker.java) of csv files that contain csv files with customer info. A simple sample in provided in with the sample code but you MUST will r ...

Fundamentals of operating systems and java

Fundamentals of Operating Systems and Java Programming Purpose of the assessment (with ULO Mapping) This assignment assesses the following Unit Learning Outcomes; students should be able to demonstrate their achievements ...

Assessment -java program using array of Assessment -JAVA Program using array of objects

Assessment -JAVA Program using array of objects Objectives This assessment item relates to the course learning outcomes as stated in the Unit Profile. Details For this assignment, you are required to develop a Windowed G ...

Applied software engineering assignment 1 -learning

Applied Software Engineering Assignment 1 - Learning outcomes - 1. Understand the notion of software engineering and why it is important. 2. Analyse the risk factors associated with phases of the software development lif ...

Retail price calculatorwrite a java program that asks the

Retail Price Calculator Write a JAVA program that asks the user to enter an item's wholesale cost and its markup percentage. It should then display the item's retail price. For example: (If an item's wholesale cost is 5. ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As