Question

No matter which editor you’re using, there are debugging tools that can help simplify the process...

No matter which editor you’re using, there are debugging tools that can help simplify the process of hunting down logic errors. In Eclipse and BlueJ, you just need to toggle a breakpoint in the gutter of the text area; this should place a blue circle next to the line of code your debugger will execute up to. Then to debug, instead of play, click on the “little bug” icon next to play. Say yes to the perspective change dialog, and watch as your code executes up until the breakpoint. Once your code is paused, you now have the option to inspect variables and their values (hover over them or use a watch). You can step over whole lines at a time (such as function calls) or step into a function call to examine the execution further. If you’re using JEdit, you may have to configure the plug-in manager to include a debugger. If on linux, consider using gdb, which offers command-line debugging (and there are GUIs to wrap this). Answer the following questions in your comments in any file and submit that.

(1) Using your debugger, debug Account.java and DebuggingExercise4.java

(2) Hover over variables to see their values. a. Where is the variable watch window on your screen? i. What information does this present to you? 1. Describe this in comments in your code. b. Where is the method call stack on your screen? i. What information does this describe?

(3) Find the shortcut keys for the following debugging commands, and describe what each does in comments. a. Step over i. What does this do? b. Step into i. What does this do

ii. How is it different from step over? c. Step out i. What does this do? ii. How is it different from step over or step into? d. Continue i. What does this do? ii. How is it different than moving in steps?

DebugginExersie4

class DebuggingExercise4
{
public static void main(String[] args)
{
Account a = null;
a.deposit(100);
System.out.println(a.getOwner() + " has $" + a.getBalance());
a.withdraw(200);
System.out.println("After trying to withdraw $200, " + a.getOwner() + " has $" + a.getBalance());
}
}

Account.java

{
// Instance variables
   private double balance;   // invariant: balance >= 0 (should never be negative)
   private String owner;

//Constructor
   public Account(String name)
   {
       balance = 0;
       owner = name;
   }

// Instance methods
   /** Deposits 'amount' into the account
   */
   public void deposit(int amount)
   {
       balance = balance + amount;
   }

   /** Withdraws 'amount' from the account.
   *   This only makes sense if amount <= balance.
   *   This method should be re-written so that there is not a possibility of
   *   having a negative balance.
   */
   public void withdraw(int amount)
   {
       balance = balance - amount;
   }

   /* Returns the balance of the Account
   */
   public double getBalance()
   {
       return balance;
   }

   /* Returns the owner of the Account
   */
   public String getOwner()
   {
       return owner;
   }
}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Please let me know if you have any doubts or you want me to modify the answer. And if you find this answer useful then don't forget to rate my answer as thumps up. Thank you! :)

class DebuggingExercise4 {
    public static void main(String[] args) {
        Account a = new Account("John");
        a.deposit(100);
        System.out.println(a.getOwner() + " has $" + a.getBalance());
        a.withdraw(200);
        System.out.println("After trying to withdraw $200, " + a.getOwner() + " has $" + a.getBalance());
    }
}
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
public class Account {
    private double balance;
    private String owner;

    //Constructor
    public Account(String name) {
        balance = 0;
        owner = name;
    }

    // Deposits amount into the account

    public void deposit(int amount) {
        balance = balance + amount;
    }

    // Withdraws 'amount' from the account.

    public void withdraw(int amount) {
        if (amount <= balance) {
            balance = balance - amount;
        }
    }

    // Returns the balance of the Account

    public double getBalance() {
        return balance;
    }

    // Returns the owner of the Account

    public String getOwner() {
        return owner;
    }
}


----------------------------------------------------------------------------------------------------------------------------------

Where is the variable watch window on your screen?
Answer: Bottom panel (below the code editor where output shows).

What information does this present to you?
Answer:
args (String[])
Account)
balance (double)
owner name (String)
value (char[])
hash (int)


Where is the method call stack on your screen?
Answer:
To the left of the variables

What information does this describe?
Answer:
The active threads and the call stack.

Step Over: What does this do?
Answer:
Go to the next line in the block.

Step Into: What does this do?
Answer:
Go to the next line or into a user defined method.

Step Out: What does this do?
Answer:
Completes and moves to to the point that called the method

Continue: What does this do?
Answer:
Runs the program from where programmer has set debug point up to the end of the program or to the point where programmer has set break point


Add a comment
Know the answer?
Add Answer to:
No matter which editor you’re using, there are debugging tools that can help simplify the process...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 6-1 Test and debug the Invoice Application i need help with this please.. all help is...

    6-1 Test and debug the Invoice Application i need help with this please.. all help is appreciated Source code Java: import java.util.Scanner; import java.text.NumberFormat; public class InvoiceApp { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String choice = "y"; while (!choice.equalsIgnoreCase("n")) { // get the input from the user System.out.print("Enter customer type (r/c): "); String customerType = sc.next(); System.out.print("Enter subtotal: "); double subtotal = sc.nextDouble(); // get the discount percent double discountPercent = 0.0; switch(customerType) {...

  • Please help me code the following in JAVA! Box class: Debugme class: (1) Debug the two...

    Please help me code the following in JAVA! Box class: Debugme class: (1) Debug the two programs (DebugMe.java and Box.java) by following the comments and fixing the errors. Note that there are both syntax and logic errors. (2) We'll use the graphical debugger built into Eclipse a. Set a breakpoint on the first line in main i. Do this by clicking in the "gutter" area for Eclipse and Bluel. ii. These appear as blue circles in Eclipse and red stop...

  • [JAVA] < Instruction> You are given two classes, BankAccount and ManageAccounts ManageAccounts is called a Driver...

    [JAVA] < Instruction> You are given two classes, BankAccount and ManageAccounts ManageAccounts is called a Driver class that uses BankAccount. associate a member to BankAcount that shows the Date and Time that Accounts is created. You may use a class Date. To find API on class Date, search for Date.java. Make sure to include date information to the method toString(). you must follow the instruction and Upload two java files. BankAccount.java and ManageAccounts.java. -------------------------------------------------------------------------- A Bank Account Class File Account.java...

  • help! Run the FileClient with the debugger (with a breakpoint on the line with while). You'll...

    help! Run the FileClient with the debugger (with a breakpoint on the line with while). You'll need to create a file called input.txt in the src folder (which the program will open) and add some (any) contents to it. Expand the inputFile Scanner variable in the debugger window to check out its stored data. How much of it can you make sense of? Watch the values of keep looping, next word, and inputFileScanner's buf field in the debugger as you...

  • The code is attached below has the Account class that was designed to model a bank account.

    IN JAVAThe code is attached below has the Account class that was designed to model a bank account. An account has the properties account number, balance, annual interest rate, and date created, and methods to deposit and withdraw funds. I need creat program using the 2 java programs.Create two subclasses for checking and savings accounts. A checking account has an overdraft limit, but a savings account cannot be overdrawn.I need to write a test program that creates objects of Account,...

  • *Step1: -Create UML of data type classes: reuse from lab3 for class Account, CheckingAccount and SavingAccount...

    *Step1: -Create UML of data type classes: reuse from lab3 for class Account, CheckingAccount and SavingAccount -Read the requirement of each part; write the pseudo-code in a word document by listing the step by step what you suppose to do in main() and then save it with the name as Lab4_pseudoCode_yourLastName *Step2: -start editor eClipse, create the project→project name: FA2019_LAB4PART1_yourLastName(part1) OR FA2019_LAB4PART2_yourLastName (part2) -add data type classes (You can use these classes from lab3) Account_yourLastName.java CheckingAccount_yourLastName.java SavingAccount_yourLastName.java -Add data structure...

  • Unable to find out why am I getting: Account.java:85: error: reached end of file while parsing...

    Unable to find out why am I getting: Account.java:85: error: reached end of file while parsing import java.util.*; class Account{ private int id; private double balance; private double annualInterestRate; private Date dateCreated; public Account() { id = 0; balance = 0; annualInterestRate = 0; dateCreated = new Date(); } public Account(int id1, double balance1) { id =id1; balance = balance1; dateCreated = new Date(); } public void setId(int id1) { id=id1; } public void setBalance(double balance1) { balance = balance1;...

  • Java debugging in eclipse package edu.ilstu; import java.util.Scanner; /** * The following class has four independent...

    Java debugging in eclipse package edu.ilstu; import java.util.Scanner; /** * The following class has four independent debugging * problems. Solve one at a time, uncommenting the next * one only after the previous problem is working correctly. */ public class FindTheErrors { public static void main(String[] args) { Scanner keyboard = new Scanner(System.in); /* * Problem 1 Debugging * * This problem is to read in your first name, * last name, and current year and display them in *...

  • please rewrite this code as Pseudo-Code,.. basically rewrite the code but in english language , Thank...

    please rewrite this code as Pseudo-Code,.. basically rewrite the code but in english language , Thank you so much! public abstract class BankAccount {    //declare the required class variables    private double balance;    private int num_deposits;    private int num_withdraws;    private double annualInterest;    private double serviceCharges;       //constructor that takes two arguments    // one is to initialize the balance and other    // to initialize the annual interest rate       public BankAccount(double balance,...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
Active Questions
ADVERTISEMENT