Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

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

Assessment instructionsin this assessment you will complete

Assessment Instructions In this assessment, you will complete the programming of two Java class methods in a console application that registers students for courses in a term of study. The application is written using th ...

Assessment instructionsin this assessment you will design

Assessment Instructions In this assessment, you will design and code a simple Java application that defines a class, instantiate the class into a number of objects, and prints out the attributes of these objects in a spe ...

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

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

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

Project requirementsfor the problem described in the next

Project requirements For the problem described in the next section, you must do the following: 1. include your student ID at the end of all filenames for all java code files. Three classes have been identified in section ...

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

Simple order processing systemquestion given the classes

Simple Order Processing System Question: Given the classes Ship (with getter and setter), Speedboat, and SpeedboatTest. Answer the following questions: Refine the whole application (all classes) and create Abstract class ...

Assessment socket programmingtaskwrite a java gui program

Assessment: Socket Programming Task Write a JAVA GUI program that would facilitate text chatting/exchanging between two or multiple computers over the network/internet, using the concept of JAVA socket programming. If yo ...

Assignment - method in our madnessthe emphasis for this

Assignment - "Method in our Madness" The emphasis for this assignment is methods with parameters. In preparation for this assignment, create a folder called Assign_3 for the DrJava projects for the assignment. A Cityscap ...

  • 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