Chapter 3 Assignments

.doc

School

Houston Community College *

*We aren’t endorsed by this school

Course

6182-58114

Subject

Computer Science

Date

Feb 20, 2024

Type

doc

Pages

4

Uploaded by CorporalBookPheasant38

Report
Chapter 3 Assignment Debugging Exercises. 1. Try to debug each program without using Java. 2. Then, (a) copy each program to TextPad; (b) save each program as a Java file (in the “Save As” window, change the “Save as type” on the 3 rd line from the bottom of the window from “All Files” to “Java”, using the dropdown arrow; (c) change the “File name” to the name of the program; the name of the first program is “DebugThree1”; (d) fix and run the program. First Debug Program: (Be sure that your output is complete and makes sense) // This class calculates a waitperson's tip as 15% of the bill public class DebugThree1 { public static void main(String args[]) { double myCheck = 50.00; double yourCheck = 19.95; System.out.println("Tips are"); calcTip(mycheck); calctip(yourCheck); } public static int calcTip(int bill) //int double { final double RATE = 0.15; tip = bill + RATE; System.out.println("The tip should be at least " + tip); } } Second Debug Program: // This application displays some math facts public class DebugThree2 { public static void main(String args[]) { int a = 2, b = 5, c = 10; add(a, b); add(b, c); subtract(c, a); } public static void add( int a, int b ) { System.out.println("The sum of " + a + and + b + is + a + b); } public void subtract( int a, int b ) { System.out.println("The difference between " + 1
a + and + b + is + a - b); } } Third Debug Program: // This program calculates tutition bills as credits times rate per credit hour public class DebugThree3 { public static void main(String args[]) { int myCredits = 13 ; int yourCredits = 17 ; double rate = 75.84 ; System.out.println("My tuition:"); tuitionBill(myCredits, rate); System.out.println("Your tuition:"); tuitionBill(myCredits, rate); } public static void tuitionBill( int myCredits, float rate) { System.out.println("Total due " + (rate*credits)); } } Case 1: 1. Do the following:   a. Create a class named Eggs. Its main() method has one integer variable named numberOfEggs. Prompt the user to enter the number of eggs and assign the value to numberOfEggs. (Remember that you will need to convert the String the user enters to an int before assigning it to numberOfEggs.) Save the application as Eggs.java. b. Create a method to which you pass numberOfEggs and which will then calculate and display the number of dozens. Name the method appropriately. In this method, calculate the number of eggs in dozens; for example, 50 eggs is 4 full dozen (with 2 eggs remaining). Display "The number of dozens is XX", where XX is the actual number of FULL dozens of eggs. c. In your main method, call the method that you just created, and pass it numberOfEggs. d. puExecute your application twice. The first time, enter 13 at the prompt. The second time, enter 44 at the prompt. 2
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help