Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
4th Edition
ISBN: 9780134787961
Author: Tony Gaddis, Godfrey Muganda
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Textbook Question
Chapter 3.4, Problem 3.14CP
What will the following
public class Checkpoint
{
public static void main (String [] args)
{
int funny = 7, serious = 15;
funny = serious % 2;
if (funny != 1)
{
funny = 0;
serious = 0;
}
else if (funny == 2)
{
funny = 10;
serious = 10;
}
else
{
funny = 1;
serious = 1;
}
System.out.println(funny + ” ” + serious};
}
}
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
// Some circle statistics
public class DebugFour2
{
publicstaticvoidmain(Stringargs[])
{
double radius =12.6;
System.out.println("Circle statistics");
double area = java.Math.PI * radius * radius;
System.out.println("area is " + area);
double diameter =2- radius;
System.out.println("diameter is + diameter);
}
}
Follow these steps:
Open the Java file Errors.java.
Attempt to compile the program. You'll notice the compilation will fail due
to some errors. Fix all the compilation errors and compile the program
again. Every time you fix an error, add a comment to the line you fixed and
indicate which of the three types of errors it was.
Now run the program. Once again, you'll encounter some errors (this time,
runtime errors). Fix these errors and run the program once again to see if
it works.
Now run the program and notice the output. You'll notice that there are
some logical errors in the code. Fix these errors and run the program once
again to see if it now correctly displays what it should.
Q2/ Correct the code.
class Box {
public static void main (String args []) {
int x;
int y;
}
class BoxBox {
public static void main (String args []) {
BOXBOX mybox =
new Box () ;
double H;
mybox.x = 1;
mybox.yy = 2;
H = myboxx.x + mybox.y * mybox.x;
System.ouf.println ("H
}
+ H);
}
Chapter 3 Solutions
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
Ch. 3.1 - Write an if statement that assigns 0 to x when y...Ch. 3.1 - Write an if statement that multiplies payRate by...Ch. 3.1 - Write an if statement that assigns 0.2 to...Ch. 3.1 - Write an if statement that sets the variable fees...Ch. 3.1 - Write an if statement that assigns 20 to the...Ch. 3.1 - Write an if statement that assigns 0 to the...Ch. 3.1 - Write an if statement that displays Goodbye if the...Ch. 3.2 - Write an if-else statement that assigns 20 to the...Ch. 3.2 - Write an if-else statement that assigns 1 to x...Ch. 3.2 - Write an if-else statement that assigns 0.10 to...
Ch. 3.2 - Write an if-else statement that assigns 0 to the...Ch. 3.3 - Write nested if statements that perform the...Ch. 3.3 - Write code that tests the variable x to determine...Ch. 3.4 - What will the following program display? public...Ch. 3.4 - The following program is used in a bookstore to...Ch. 3.5 - Prob. 3.16CPCh. 3.5 - Assume the variables a = 2, b = 4, and c = 6....Ch. 3.5 - Write an if statement that displays the message...Ch. 3.5 - Prob. 3.19CPCh. 3.6 - Assume the variable name references a String...Ch. 3.6 - Prob. 3.21CPCh. 3.6 - Prob. 3.22CPCh. 3.8 - Rewrite the following if-else statements as...Ch. 3.9 - Complete the following program skeleton by writing...Ch. 3.9 - Rewrite the following if-else-if statement as a...Ch. 3.9 - Explain why you cannot convert the following...Ch. 3.9 - What is wrong with the following switch statement?...Ch. 3.9 - What will the following code display? int funny =...Ch. 3.10 - Assume the following variable declaration exists...Ch. 3.10 - Prob. 3.30CPCh. 3.10 - Assume the following variable declaration exists...Ch. 3.10 - Prob. 3.32CPCh. 3.10 - Prob. 3.33CPCh. 3.10 - Assume the following declaration exists in a...Ch. 3 - The if statement is an example of a __________. a....Ch. 3 - This type of expression has a value of either true...Ch. 3 - , , and = = are __________. a. relational...Ch. 3 - , | |, and ! are __________. a. relational...Ch. 3 - Prob. 5MCCh. 3 - To create a block of statements, you enclose the...Ch. 3 - This is a boolean variable that signals when some...Ch. 3 - How does the character A compare to the character...Ch. 3 - This is an if statement that appears inside...Ch. 3 - Prob. 10MCCh. 3 - When determining whether a number is inside a...Ch. 3 - Prob. 12MCCh. 3 - The conditional operator takes this many operands....Ch. 3 - This section of a switch statement is branched to...Ch. 3 - You can use this method to display formatted...Ch. 3 - True or False: The = operator and the == operator...Ch. 3 - True or False: A conditionally executed statement...Ch. 3 - Prob. 18TFCh. 3 - True or False: When an if statement is nested in...Ch. 3 - True or False: When an if statement is nested in...Ch. 3 - True or False: The scope of a variable is limited...Ch. 3 - Find the errors in the following code: 1. //...Ch. 3 - Find the errors in the following code: 2. //...Ch. 3 - Find the errors in the following code: 3. //...Ch. 3 - Prob. 4FTECh. 3 - Find the errors in the following code: 5. The...Ch. 3 - Find the errors in the following code: 6. The...Ch. 3 - The following statement should determine whether...Ch. 3 - Find the errors in the following code: 8. The...Ch. 3 - Prob. 9FTECh. 3 - Prob. 10FTECh. 3 - Write an if statement that assigns 100 to x when y...Ch. 3 - Write an if-else statement that assigns 0 to x...Ch. 3 - Using the following chart, write an if-else-if...Ch. 3 - Write an if statement that sets the variable hours...Ch. 3 - Write nested if statements that perform the...Ch. 3 - Write an if statement that prints the message The...Ch. 3 - Write an if statement that prints the message The...Ch. 3 - Write an if statement that prints the message The...Ch. 3 - Write an if-else statement that displays the...Ch. 3 - Convert the following if-else-if statement into a...Ch. 3 - Match the conditional expression with the if-else...Ch. 3 - Prob. 12AWCh. 3 - Prob. 13AWCh. 3 - Prob. 14AWCh. 3 - Explain what is meant by the phrase conditionally...Ch. 3 - Explain why a misplaced semicolon can cause an if...Ch. 3 - Why is it good advice to indent all the statements...Ch. 3 - What happens when you compare two String objects...Ch. 3 - Prob. 5SACh. 3 - What risk does a programmer take when not placing...Ch. 3 - Prob. 7SACh. 3 - Briefly describe how the | | operator works.Ch. 3 - Why are the relational operators called...Ch. 3 - When does a constructor execute? What is its...Ch. 3 - Roman Numerals Write a program that prompts the...Ch. 3 - Magic Dates The date June 10, 1960, is special...Ch. 3 - Body Mass Index Write a program that calculates...Ch. 3 - Test Scores and Grade Write a program that has...Ch. 3 - Mass and Weight Scientists measure an objects mass...Ch. 3 - Time Calculator Write a program that asks the user...Ch. 3 - Sorted Names Write a program that asks the user to...Ch. 3 - Software Sales A software company sells a package...Ch. 3 - Shipping Charges The Fast Freight Shipping Company...Ch. 3 - Fat Gram Calculator Write a program that asks the...Ch. 3 - Running the Race Write a program that asks for the...Ch. 3 - The Speed of Sound The following table shows the...Ch. 3 - Mobile Service Provider A mobile phone service...Ch. 3 - Mobile Service Provider, Part 2 Modify the program...Ch. 3 - Prob. 15PCCh. 3 - Book Club Points Serendipity Booksellers has a...Ch. 3 - Wi-Fi Diagnostic Tree Figure 3-23 shows a...Ch. 3 - Restaurant Selector You have a group of friends...
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
What are the bits in a binary system?
Digital Fundamentals (11th Edition)
What populates the Smalltalk world?
Concepts of Programming Languages (11th Edition)
Why is the study of database technology important?
Database Concepts (8th Edition)
For each of the following activities, give a PEAS description of the task environment and characterize it in te...
Artificial Intelligence: A Modern Approach
Redo (or do for the first time) Programming Project 11 from Chapter 6. Your program should not be hard-coded to...
Problem Solving with C++ (10th Edition)
Describe the implementation of the method drawHere for a class called Diamond that is derived from the class Sh...
Java: An Introduction to Problem Solving and Programming (8th Edition)
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- public static class Lab2{public static void Main(){int idNum;double payRate, hours, grossPay;string firstName, lastName;// prompt the user to enter employee's first nameConsole.Write("Enter employee's first name => ");firstName = Console.ReadLine();// prompt the user to enter employee's last nameConsole.Write("Enter employee's last name => ");lastName = Console.ReadLine()// prompt the user to enter a six digit employee numberConsole.Write("Enter a six digit employee's ID => ");idNum = Convert.ToInt32(Console.ReadLine());// prompt the user to enter the number of hours employeeworkedConsole.Write("Enter the number of hours employee worked =>");// prompt the user to enter the employee's hourly pay rateconsole.Write("Enter employee's hourly pay rate: ");payRate = Convert.ToDouble(Console.ReadLine());// calculate gross paygrossPay = hours * payRate;// output resultsConsole.WriteLine("Employee {0} {1}, (ID: {2}) earned {3}",firstName, lastName, idNum,…arrow_forwardpublic class LabProgram { public static void main(String args[]) { Course course = new Course(); String first; // first name String last; // last name double gpa; // grade point average first = "Henry"; last = "Cabot"; gpa = 3.5; course.addStudent(new Student(first, last, gpa)); // Add 1st student first = "Brenda"; last = "Stern"; gpa = 2.0; course.addStudent(new Student(first, last, gpa)); // Add 2nd student first = "Jane"; last = "Flynn"; gpa = 3.9; course.addStudent(new Student(first, last, gpa)); // Add 3rd student first = "Lynda"; last = "Robison"; gpa = 3.2; course.addStudent(new Student(first, last, gpa)); // Add 4th student course.printRoster(); } } // Class representing a student public class Student { private String first; // first name private String last; // last name private double gpa; // grade point average…arrow_forwardpublic class Errors{public static void main (String[] args){System.out.println("Welcome to my first program!\n")String ageStr = "24 years";int age = Integer.parseInt(ageStr);System.out.println("I'm " + age + " years old.");int three = "3";int answerYears = age + three;System.out.println("Total number of years: " + answerYears);int answerMonths = answerYears * 12; System.out.println("In 3 years and 6 months, I'll be " + answerMonths + " months old");//Once you've corrected all the errors, the answer should be 330.}}arrow_forward
- class Variables { public static void main(String[] args) { .arrow_forwardpublic class Test { } public static void main(String[] args) { int a = 5; a += 5; } switch(a) { case 5: } System.out.print("5"); break; case 10: System.out.print("10"); System.out.print("0"); default:arrow_forwardpublic class MysteryReturn2 {3 public static void main(String[] args)4 {5 int x = 1;6 int y = 2;7 int z = 3;89 z = mystery(x, z, y);10 System.out.println(x + " " + y + " " + z);11 }1213 public static int mystery(int c, a, int b);14 {15 c--;16 a = 2 * b + c;17 b = a - 1;18 System.out.println(b + " " + c);1920 return a;21 }22 } 1. Line 13 contains 2 errors. What are they? 2. Rewrite line 13 with the errors identifed in Question 1 corrected.arrow_forward
- public class MysteryReturn2 {3 public static void main(String[] args)4 {5 int x = 1;6 int y = 2;7 int z = 3;89 z = mystery(x, z, y);10 System.out.println(x + " " + y + " " + z);11 }1213 public static int mystery(int c, a, int b);14 {15 c--;16 a = 2 * b + c;17 b = a - 1;18 System.out.println(b + " " + c);1920 return a;21 }22 } 1. The mystery method has three parameter variables, a, b, and c. What is the scope of these variables (that is, where can they be used by their name)?arrow_forwardclass isNaN_output { public static void main(String args[]) { Double d = new Double(1 / 0.); boolean x = d.isNaN(); System.out.print(x); } } What will the given code prints on the output screen.arrow_forwardQuestion public class MyProgram { if (h 18) { public static void main(String[] args) { int h=10, t-22; System.out.print ("Good "); } } else } } What is the output displayed by the following lines of code?" System.out.print ("Morning"); t = t + 2; if (t > 30) System.out.println(" Every one!"); System.out.println("The Your answer system.out.print("Evening"); t = t + 5; temperature is " System.out.println(" Brink water?"); Degree.");arrow_forward
- Q1. amount the same, y, n, why? public class CheckingAct { private String actNum; private String nameOnAct; private int balance; . . . . public void processDeposit( int amount ) { balance = balance + amount ; } // modified toString() method public String toString() { return "Account: " + actNum + "\tName: " + nameOnAct + "\tBalance: " + amount ; } } Q2. amount the same, y, n, why? public class CheckingAct { private String actNum; private String nameOnAct; private int balance; . . . . public void processDeposit( int amount ) { // scope of amount starts here balance = balance + amount ; // scope of amount ends here } public void processCheck( int amount ) { // scope of amount starts here int charge; incrementUse(); if ( balance < 100000 ) charge = 15; else charge = 0; balance = balance - amount - charge ; // scope of amount ends here }…arrow_forward1 a. is the amount the same, yes or no, why? public class CheckingAct { private String actNum; private String nameOnAct; private int balance; . . . . public void processDeposit( int amount ) { balance = balance + amount ; } // modified toString() method public String toString() { return "Account: " + actNum + "\tName: " + nameOnAct + "\tBalance: " + amount ; } } b. public class CheckingAct { private String actNum; private String nameOnAct; private int balance; . . . . public void processDeposit( int amount ) { // scope of amount starts here balance = balance + amount ; // scope of amount ends here } public void processCheck( int amount ) { // scope of amount starts here int charge; incrementUse(); if ( balance < 100000 ) charge = 15; else charge = 0; balance = balance - amount - charge ; // scope of amount ends here } } c. is the…arrow_forwardpublic class Number { private int num; public Number(int n) { num = n; } /* Type your code here */ public int getNum() { return num; } public void setNum(int n) { num = n; } public static void main(String [] args) { Number yourNum = new Number(723); System.out.print(yourNum); }}arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education
Memory Management Tutorial in Java | Java Stack vs Heap | Java Training | Edureka; Author: edureka!;https://www.youtube.com/watch?v=fM8yj93X80s;License: Standard YouTube License, CC-BY