Starting Out with Java: From Control Structures through Data Structures (3rd Edition)
3rd Edition
ISBN: 9780134038179
Author: Tony Gaddis, Godfrey Muganda
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Textbook Question
Chapter 4, Problem 3FTE
// This code contains ERRORS!
int choice, num1, num2;
Scanner keyboard = new Scanner(System.in);
do
{
System.out.print(“Enter a number: ”);
num1 = keyboard.nextInt();
System.out.print(“Enter another number: ”);
num2 = keyboard,nextInt();
System.out.println(“Their sum is ” + (num1 + num2));
System.out.println(“Do you want to do this again? ”);
System.out.print(“1 = yes, 0 = no ”);
choice = keyboard.nextInt();
} while (choice = 1)
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
int stop = 6;
int num =6;
int count=0;
for(int i = stop; i >0; i-=2)
{
num += i;
count++;
}
System.out.println("num = "+ num);
System.out.println("count = "+ count);
}
}
Fix all the errors and send the code please
// Application looks up home price
// for different floor plans
// allows upper or lowercase data entry
import java.util.*;
public class DebugEight3
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
String entry;
char[] floorPlans = {'A','B','C','a','b','c'}
int[] pricesInThousands = {145, 190, 235};
char plan;
int x, fp = 99;
String prompt = "Please select a floor plan\n" +
"Our floorPlanss are:\n" + "A - Augusta, a ranch\n" +
"B - Brittany, a split level\n" +
"C - Colonial, a two-story\n" +
"Enter floorPlans letter";
System.out.println(prompt);
entry = input.next();
plan = entry.charAt(1);
for(x = 0; x < floorPlans.length; ++x)
if(plan == floorPlans[x])
x = fp;
if(fp = 99)
System.out.println("Invalid floor plan code entered"));
else
{
if(fp…
//Assignment 06 */public static void main[](String[] args) { String pass= "ICS 111"; System.out.printIn(valPassword(pass));}
/*
public static boolean valPassword(String password){ if(password.length() > 6) { if(checkPass(password) { return true; } else { return false; } }else System.out.print("Too small"); return false;}
public static boolean checkPass (String password){ boolean hasNum=false; boolean hasCap = false; boolean hasLow = false; char c; for(int i = 0; i < password.length(); i++) { c = password.charAt(1); if(Character.isDigit(c)); { hasNum = true; } else if(Character.isUpperCase(c)) { hasCap = true; } else if(Character.isLowerCase(c)) { hasLow = true; } } return true; { return false; }
}
Chapter 4 Solutions
Starting Out with Java: From Control Structures through Data Structures (3rd Edition)
Ch. 4.1 - What will the following program segments display?...Ch. 4.2 - How many times will Hello World be printed in the...Ch. 4.2 - How many times will I love Java programming! be...Ch. 4.3 - Write an input validation loop that asks the user...Ch. 4.3 - Write an input validation loop that asks the user...Ch. 4.3 - Write an input validation loop that asks the user...Ch. 4.5 - Name the three expressions that appear inside the...Ch. 4.5 - You want to write a for loop that displays I love...Ch. 4.5 - What will the following program segments display?...Ch. 4.5 - Write a for loop that displays your name 10 times.
Ch. 4.5 - Write a for loop that displays all of the odd...Ch. 4.5 - Write a for loop that displays every fifth number,...Ch. 4.6 - Write a for loop that repeats seven times, asking...Ch. 4.6 - In the following program segment, which variable...Ch. 4.6 - Prob. 4.15CPCh. 4.10 - What is the difference between an input file and...Ch. 4.10 - What import statement will you need in a program...Ch. 4.10 - What class do you use to write data to a file?Ch. 4.10 - Write code that does the following: opens a file...Ch. 4.10 - What classes do you use to read data from a file?Ch. 4.10 - Write code that does the following: opens a file...Ch. 4.10 - You are opening an existing file for output. How...Ch. 4.10 - What clause must you write in the header of a...Ch. 4.11 - Assume x is an int variable, and rand references a...Ch. 4.11 - Assume x is an int variable, and rand references a...Ch. 4.11 - Assume x is an int variable, and rand references a...Ch. 4.11 - Assume x is a double variable, and rand references...Ch. 4 - Prob. 1MCCh. 4 - Prob. 2MCCh. 4 - Prob. 3MCCh. 4 - What is each repetition of a loop known as? a....Ch. 4 - This is a variable that controls the number of...Ch. 4 - The while loop is this type of loop. a. pretest b....Ch. 4 - The do-while loop is this type of loop. a. pretest...Ch. 4 - The for loop is this type of loop. a. pretest b....Ch. 4 - This type of loop has no way of ending and repeats...Ch. 4 - This type of loop always executes at least once....Ch. 4 - This expression is executed by the for loop only...Ch. 4 - Prob. 12MCCh. 4 - This is a special value that signals when there...Ch. 4 - To open a file for writing, you use the following...Ch. 4 - To open a file for reading, you use the following...Ch. 4 - Prob. 16MCCh. 4 - This class allows you to use the print and println...Ch. 4 - This class allows you to read a line from a file....Ch. 4 - True or False: The while loop is a pretest loop.Ch. 4 - True or False: The do-while loop is a pretest...Ch. 4 - True or False: The for loop is a posttest loop.Ch. 4 - True or False: It is not necessary to initialize...Ch. 4 - True or False: One limitation of the for loop is...Ch. 4 - True or False: A variable may be defined in the...Ch. 4 - True or False: In a nested loop, the inner loop...Ch. 4 - True or False: To calculate the total number of...Ch. 4 - // This code contains ERRORS! // It adds two...Ch. 4 - Prob. 2FTECh. 4 - // This code contains ERRORS! int choice, num1,...Ch. 4 - Prob. 4FTECh. 4 - Write a while loop that lets the user enter a...Ch. 4 - Write a do-whi1e loop that asks the user to enter...Ch. 4 - Write a for loop that displays the following set...Ch. 4 - Write a loop that asks the user to enter a number....Ch. 4 - Write a for loop that calculates the total of the...Ch. 4 - Write a nested loop that displays 10 rows of #...Ch. 4 - Convert the while loop in the following code to a...Ch. 4 - Convert the do-while loop in the following code to...Ch. 4 - Convert the following while loop to a for loop:...Ch. 4 - Convert the following for loop to a while loop:...Ch. 4 - Write an input validation loop that asks the user...Ch. 4 - Write an input validation loop that asks the user...Ch. 4 - Write nested loops to draw this pattern:Ch. 4 - Write nested loops to draw this pattern: ## # # #...Ch. 4 - Complete the following program so it displays a...Ch. 4 - Complete the following program so it performs the...Ch. 4 - Prob. 17AWCh. 4 - Prob. 18AWCh. 4 - Modify the code you wrote in Question 18 so it...Ch. 4 - Write code that opens a file named NumberList.txt...Ch. 4 - Prob. 1SACh. 4 - Why should you indent the statements in the body...Ch. 4 - Describe the difference between pretest loops and...Ch. 4 - Why are the statements in the body of a loop...Ch. 4 - Describe the difference between the while loop and...Ch. 4 - Which loop should you use in situations where you...Ch. 4 - Which loop should you use in situations where you...Ch. 4 - Which loop should you use when you know the number...Ch. 4 - Why is it critical that accumulator variables are...Ch. 4 - What is an infinite loop? Write the code for an...Ch. 4 - Prob. 11SACh. 4 - What does it mean to let the user control a loop?Ch. 4 - What is the advantage of using a sentinel?Ch. 4 - Prob. 14SACh. 4 - Describe a programming problem requiring the use...Ch. 4 - How does a file buffer increase a programs...Ch. 4 - Why should a program close a file when its...Ch. 4 - What is a files read position? Where is the read...Ch. 4 - When writing data to a file, what is the...Ch. 4 - What does the Scanner classs hasNext method return...Ch. 4 - What is a potential error that can occur when a...Ch. 4 - Prob. 22SACh. 4 - How do you open a file so that new data will be...Ch. 4 - Sum of Numbers Write a program that asks the user...Ch. 4 - Distance Traveled The distance a vehicle travels...Ch. 4 - Distance File Modify the program you wrote for...Ch. 4 - Pennies for Pay Write a program that calculates...Ch. 4 - Prob. 5PCCh. 4 - File Letter Counter Write a program that asks the...Ch. 4 - Hotel Occupancy A hotels occupancy rate is...Ch. 4 - Average Rainfall Write a program that uses nested...Ch. 4 - Population Write a program that will predict the...Ch. 4 - Largest and Smallest Write a program with a loop...Ch. 4 - Celsius to Fahrenheit Table Write a program that...Ch. 4 - Bar Chart Write a program that asks the user to...Ch. 4 - File Head Display Write a program that asks the...Ch. 4 - Line Numbers Write a program that asks the user...Ch. 4 - Uppercase File Converter Write a program that asks...Ch. 4 - Budget Analysis Write a program that asks the user...Ch. 4 - Random Number Guessing Game Write a program that...Ch. 4 - Random Number Guessing Game Enhancement Enhance...Ch. 4 - ESP Game Write a program that tests your ESP...Ch. 4 - Square Display Write a program that asks the user...Ch. 4 - Dice Game Write a program that plays a simple dice...Ch. 4 - Prob. 22PCCh. 4 - Personal Web Page Generator Write a program that...
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
What is the general problem with static scoping?
Concepts Of Programming Languages
Write a program that determines whether your particular computer performs an arithmetic or a logical right shif...
Programming in C
What will the following code display? number 1 = 10 number 2=5 number 1 = number 1 + number 2 print(number1) pr...
Starting Out with Python (3rd Edition)
What is pseudocode?
Starting Out With Visual Basic (7th Edition)
3.12 (Date Create a class called Date that includes three pieces Of information as data
members—a month (type ...
C++ How to Program (10th Edition)
How many hello output lines does this program print?
Computer Systems: A Programmer's Perspective (3rd 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
- Don't put wrong code else downvotearrow_forwardfunction performTask () { var valuel; valuel - document.getElementById ("FirstBox").value; if (valuel == "Yes") { document.getElementById ("paragraphl").innerHTML = "Agreed"; ) else if (valuel =- "No") { document.getElementById ("paragraphl").innerHTML = "Sorry"; ) else ( alert ("Error") Describe the purpose of the following JavaScript statements from the function performTask (). i. alert("Error"), ii. value1 = document.getElementByld("FirstBox").value; iii. document.getElementByld("paragraph1").innerHTML = "Agreed";arrow_forward#includecstdio.h> int x=10; void func1() 7 printf("x=%d\n", x); return; 8 10 int func2(int a, int b) 15 return a+b; 16 18 19 ... func3(...) 20 21 .. return ... int main() 27 { int x-1, y=2; func1(); 28 29 30 int z=func2(x, y); printf("z-%d\n", z); 31 34 Figure 2. C Program for Q2 What is the output after execution of line 29 and 32? a. b. func3() in line 19 to 23 is incomplete. Write the function, func30 to compute and print the volume of cuboid with length x, width y and height z. c. Complete line 33 to call func3() that you created in part (b).arrow_forward
- JAVA:arrow_forward// DebugFive1 // Adds your lunch bill // Burger and hot dog are $2.59 // Grilled cheese and fish are $1.99 // Fries are 89 cents import java.util.*; public class DebugFive1 { publicstaticvoidmain(Stringargs[]) { Scanner input =newScanner(System.in); finaldouble HIGH_PRICE =2.59; finaldouble MED_PRICE =1.99; finaldouble LOW_PRICE =0.89; String usersChoiceString; int usersChoice; double bill; System.out.println("Order please\n1 - Burger\n2 - Hotdog" + "\n3 - Grilled cheese\n4 - Fish sandwich"); usersChoiceString = input.next(); usersChoice == Integer.parseInt(usersChoiceString); if(usersChoice ==1&& usersChoice ==2) bill = bill + HIGH_PRICE; else bill = bill + MED_PRICE; System.out.println("Fries with that?\n1 - Yes\n2 - No"; usersChoiceString = input.next() usersChoice = Integer.parseInt(usersChoiceString); if (usersChoice =1) bill = bill + LOW_PRICE; System.out.println("Bill is " + bill); } }arrow_forwardWhich aggregating procedures are permitted for struct variables but not array variables, and which are not allowed for array variables?arrow_forward
- а. int GreaterThan(int no) { if (no > 10) printf("%d is greater than 10", no); else printf("%d is less than 10", no); }arrow_forwardint nums[] = {7,2,5,6,7,2,3,4,6); int target = 12; int loc = 0; int iterations = 0; boolean found = false; while (!found && locarrow_forwardgetRandomLib.h: // This library provides a few helpful functions to return random values// * getRandomInt() - returns a random integer between min and max values// * getRandomFraction() - returns a random float between 0 and 1// * getRandomFloat() - returns a random float between min and max values// * getRandomDouble() - returns a random double between min and max values// * getRandomBool() - returns a random bool value (true or false)// * getRandomUpper() - returns a random char between 'A' and 'Z', or between min/max values// * getRandomLower() - returns a random char between 'a' and 'z', or between min/max values// * getRandomAlpha() - returns a random char between 'A' and 'Z' or 'a' and 'z'// * getRandomDigit() - returns a random char between '0' and '9', or between min/max values// * getRandomChar() - returns a random printable char//// Trey Herschede, 7/31/2019 #ifndef GET_RANDOM_LIB_H#define GET_RANDOM_LIB_H #include <cstdlib>#include <random>#include…arrow_forwardInt cube ( int x){ // returns cube of x : return x.x.x. :)* O False Truearrow_forwardHomework - identical arrays for one-dimensional: Write a test program which prompts a user to enter the size of two arrays as well as to fill their elements. After that, the program checks the same contents of the elements of the two arrays. If these arrays are equal, the program displays message which is "The two arrays are identical". If not equal, displaying "The two arrays are not identical". Write an equals method that reads two arrays and displays these messages above.arrow_forwardTrue or FalseReference variables can be used only to reference objects.arrow_forwardarrow_back_iosSEE MORE QUESTIONSarrow_forward_ios
Recommended textbooks for you
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781305480537Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781305480537
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
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