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
thumb_up100%
Chapter 4, Problem 15AW
Complete the following
// Write the necessary import statement(s) here.
public class ReviewQuestion15
{
public static void main(String[] args)
{
// Write the necessary code here.
}
}
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Part 2 - OddOrEven ClassWrite a program that prompts the user to enter an integer. The program should display “The input is odd" to the screen if the input is odd and displays “The input is even" to the screen if the input is even. Hint: Consider using the mod (%) operator
Language: JAVA
Leap-Year
Write a program to find if a year is a leap year or not. We generally assume that if a year number is divisible by 4 it is a leap year. But it is not the only case. A year is a leap year if −
It is evenly divisible by 100
If it is divisible by 100, then it should also be divisible by 400
Except this, all other years evenly divisible by 4 are leap years.
So the leap year algorithm is, given the year number Y,
Check if Y is divisible by 4 but not 100, DISPLAY "leap year"
Check if Y is divisible by 400, DISPLAY "leap year"
Otherwise, DISPLAY "not leap year"
For this program you have to take the input, that is the year number from an input file input.txt that is provided to you. The input file contains multiple input year numbers. Use a while loop to input the year numbers from the input file one at a time and check if that year is a leap year or not.
Create a class named LeapYear which will contain the main method and write all your code in the main…
*1. This program takes in user input and calculates each persons share of the cost from a trip.*2. This program uses Scanner for input/*3. This code calculates the final cost less a discount discount..*4. This code displays and formats the result.*/import java.util.*;public class NdunaJoyDiscuss4Wk4 {
public static void main(String[] args) { String name = "Joy Nduna"; //My given name String date = "April 08, 2023";//Date code is implemented int course = 141; // The course number int section = 7382; // The section number int numDiscuss = 4; // Assignment week number // Displaying my name, course/section number, discussion week number, date System.out.println("Name: "+name+("\n")+"Class CMIS: "+course+"\n"+"Section : "+section+("\n")+"Assignment 1: Week: "+numDiscuss+("\n")+"Date: "+date); // Create a scanner object to read user inputScanner stdin = new Scanner(System.in);// Prompt for two integers separated by a spaceint…
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
Explain the meaning of the term object persistence.
Database Concepts (7th Edition)
The only language a computer can directly understand is that computers.
Java How To Program (Early Objects)
Describe the three types of anomalies that can arise in a table and the negative consequences of each.
Modern Database Management
An inverter performs the NOT operation changes a HIGH to a LOW changes a LOW to a HIGH does all of the above
Digital Fundamentals (11th Edition)
When displaying a Java applet, the browser invokes the _____ to interpret the bytecode into the appropriate mac...
Web Development and Design Foundations with HTML5 (9th Edition) (What's New in Computer Science)
What modifier should you use on a class so a class in the same package can access it, but a class in a differen...
Introduction to Java Programming and Data Structures, Comprehensive Version (11th 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
- Python Language Useful websites: : http://en.wikipedia.org/wiki/Radix http://www.purplemath.com/modules/numbbase.htm Special Rules: Use only Boolean/math expressions and conditional statements (if-statements). Do not use built-in functions for converting integers into a string representation. Here to start with: kthDigit(x: int, b: int, k: int) -> int .........arrow_forwardExercise 3: The following code asks a user to enter her/his age then determines if a user is an adult or not. Trace the code, to find and solve the syntax errors. You need to identify the errors and rewrite the correct code. import java.util.Scanner; public class Ex3 { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.println(("Enter your age:"); int age = input.nextInt(); double flag = isAdult(double age); if(flag) { System.out.println("You are an adult."); } else { System.out.println("You are not an adult."); } } public boolean isAdult(int age) { if(age > 18) { return true; } else { return false;arrow_forwardFind and fix any logic and syntax errors. Program runs and produce the following output. Tips are The tip should be at least 7.5 The tip should be at least 2.99 // 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 void calcTip(double bill) { final double RATE = 0.15; double tip; tip = check * RATE; System.out.println("The tip should be at least " + tip); } }arrow_forward
- Problem Description. Arguments for the main method are passed as strings. Strings enclosed in quotation marks are considered as one argument. Write a program to parse arguments from a string. Arguments are separated by spaces. Enclosed strings are considered as one argument. Your program should prompt the user to enter a string and display the arguments, each per line, as shown in the following sample run. <input> Enter the arguments: a friend "good morning" "good afternoon" b <output> a friend good morning good afternoon b please provide the answer in JAVAarrow_forwardEach of the following definitions and program segments has errors. Locate as many as you can and correct the errors. a) void showValues (int nums) { for (int i = 0; i<8; i++) cout<arrow_forward2) class selection_statements { public static void main(String args[]) { int var1 5; int %D var2 = 6; if ((var2 = 1) : System.out.print(v ar2); else System.out.print(++var2); var1) == } а) 1 b) 2 c) 3 d) 4arrow_forward# Data conversion with format method(PYTHON) 1- As discussed in the chapter string formatting could be used to simplify the dataconvert2.py Redo this program making use of the string-formatting method. Please explain your answer I’m really confused??arrow_forwardc# onlyarrow_forwardIn C++ Find the five errors. For each error, state the line number, explain the error and show a correction. #include<iostream> #include<iomanip> using namespace std; class colorCode { public: void setRGB(int); //accepts an int parameter and sets the RGB to the value of the parameter void setName(string);//accepts a string parameter and sets the name of the object to the value of the parameter string getName() const;//returns the name of the object int getRGB() const;//returns the RGB of the object void changeColor();// adds 10 to the RGB value private: string name; int RGB; } int main() { colorCode paintCans[10]; int i; for (i = 0; i < 10; i++){ paintCans.setRGB[i] = 0;} paintCans[5].setName(GREEN); paintCan[5].setRGB(192000); cout << paintCans[5].getName << ' ' << paintCans[5].getRGB() << endl; return 0; }arrow_forwardC++arrow_forwardCOMPUTER FUNDAMENTALS AND PROGRAMMING 2 USING JAVA Problem 1: Using Scanner format, create a program that computes the discount amount and the discounted price of any items sold at KADS store, the store gives 5% discount on all items.arrow_forwardVoid Do1 (int: &, a. int &b) { a = 5; a = a + b; b = a + 2; } Int main() { Int x = 10; Do1 (x,x); Cout << x << endl; } The output of this program isarrow_forwardarrow_back_iosSEE MORE QUESTIONSarrow_forward_ios
Recommended textbooks for you
- Microsoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningEBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Java random numbers; Author: Bro code;https://www.youtube.com/watch?v=VMZLPl16P5c;License: Standard YouTube License, CC-BY