Starting Out with Java: Early Objects (6th Edition)
Starting Out with Java: Early Objects (6th Edition)
6th Edition
ISBN: 9780134462011
Author: Tony Gaddis
Publisher: PEARSON
bartleby

Concept explainers

bartleby

Videos

Textbook Question
Book Icon
Chapter 4, Problem 14PC

Days in a Month

Write a class named MonthDays. The class’s constructor should accept two arguments:

  • An integer (or the month (1 = January, 2 = February, etc.)
  • An integer for the year

The class should have a method named getNumberOfDays that returns the number of days in the specified month. The method should use the following criteria to identify leap years:

  1. 1. Determine whether the year is evenly divisible by 100. If it is, then it is a leap year if and only if it is evenly divisible by 400. For example, 2000 is a leap year, but 2100 is not.
  2. 2. If the year is not evenly divisible by 100, then it is a leap year if and only if it is evenly divisible by 4. For example, 2008 is a leap year but 2009 is not.
  3. 3. Demonstrate the class in a program that asks the user to enter the month (letting the user enter an integer in the range of 1 through 12) and the year. The program should then display the number of days in that month. Here is a sample run of the program:

Enter a month (1–12): 2 Enter

Enter a year: 2020 Enter

29 days

Blurred answer
Students have asked these similar questions
Instructions This assignment must follow directions exactly. Create a class Lab02 with a main method, and put all of the following code into the main method: Print the prompt shown below and ask the user for the number of exemptions. The number of exemptions is an integer. Print the prompt shown below and ask the user for their gross salary. The gross salary represents dollars, which can be entered with or without decimal points. Print the prompt shown below and ask the user for their interest income. The interest income represents dollars, which can be entered with or without decimal points. Print the prompt shown below and ask the user for their capital gains income. The capital gains represents dollars, which can be entered with or without decimal points. Print the prompt shown below and ask the user for the amount of charitable contributions. The charitable contributions represents dollars, which can be entered with or without decimal points. Perform the calculation of…
0o.Absolutely answer please Write a program that calculates the average of courses, overall grade, and letter grade. Suppose that your students take four courses - English, Mathematics, Science, and History. You should design a class that accepts all four course's numeric scores, calculates average and overall grade, and decides letter grade based on the overall grade. Your class should have a constructor, get and set methods of each course, a method that calculates the average of four courses, a method that calculates overall grade, and a method that decides letter grade. The overall grades are calculated as the following rate: Average of All four courses: 50% Quiz: 40% Attendance: 10% The letter grade is based on the following: 90.0 to 100.0 - A 80.0 to 89.9 - B 70.0 to 79.9 - C 65.0 to 69.9 - D less than 65 - F Your program demonstrates the class by asking the user to input four-course numeric scores, creating an object, and then reporting each course's score, average, overall…
7)Circle Class  Write a Circle class that has the following fields: radius: a double  PI:a final double initialized with the value 3.14159 The class should have the following methods: Constructor. Accepts the radius of the circles as an argument. Constructor. A no-arg constructor that sets the radius field to 0.0. setRadius. A mutator method for the radius field. getRadius.An accessor method for the radius field. area. Returns the area of the circle, which is calculated as area. Returns the area of the circles, which is calculated as area= PI * radius * radius diameter. Returns the diameter of the cirlce, which is calculated as diameter = radius * 2 circumference. Returns the circumference of the circle, which is calculated as circumference = 2 * PI * radius Write a program that demonstrates the Circle class by asking the user for the circles's radius, creating a Circle object, and then reporting the cirlce's area, diameter, and circumference.

Chapter 4 Solutions

Starting Out with Java: Early Objects (6th Edition)

Ch. 4.2 - Write an if-else statement that assigns 0 to the...Ch. 4.4 - Write nested if statements that perform the...Ch. 4.4 - Write code that tests the variable x to determine...Ch. 4.5 - What will the following program display? public...Ch. 4.5 - The following program is used in a bookstore to...Ch. 4.6 - Prob. 4.16CPCh. 4.6 - Assume the variables a = 2, b = 4, and c = 6....Ch. 4.6 - Write an if statement that displays the message...Ch. 4.6 - Write an if statement that displays the message...Ch. 4.7 - Assume the variable name references a String...Ch. 4.7 - Prob. 4.21CPCh. 4.7 - Prob. 4.22CPCh. 4.9 - Rewrite the following if-else statements as...Ch. 4.10 - Complete the following program skeleton by writing...Ch. 4.10 - Rewrite the following if-else-if statement as a...Ch. 4.10 - Explain why you cannot convert the following...Ch. 4.10 - What is wrong with the following switch statement?...Ch. 4.10 - What will the following code display? int funny =...Ch. 4 - The if statement is an example of a __________. a....Ch. 4 - This type of expression has a value of either true...Ch. 4 - , , and = = are __________. a. relational...Ch. 4 - , | |, and ! are __________. a. relational...Ch. 4 - Prob. 5MCCh. 4 - To create a block of statements, you enclose the...Ch. 4 - This is a boolean variable that signals when some...Ch. 4 - How does the character A compare to the character...Ch. 4 - This is an if statement that appears inside...Ch. 4 - Prob. 10MCCh. 4 - When determining whether a number is inside a...Ch. 4 - Prob. 12MCCh. 4 - The conditional operator takes this many operands....Ch. 4 - This section of a switch statement is branched to...Ch. 4 - True or False: The = operator and the == operator...Ch. 4 - True or False: A conditionally executed statement...Ch. 4 - Prob. 17TFCh. 4 - True or False: When an if statement is nested in...Ch. 4 - True or False: When an if statement is nested in...Ch. 4 - True or False: The scope of a variable is limited...Ch. 4 - Find the errors in the following code: 1. //...Ch. 4 - Find the errors in the following code: 2. //...Ch. 4 - Find the errors in the following code: 3. //...Ch. 4 - Prob. 4FTECh. 4 - Find the errors in the following code: 5. The...Ch. 4 - Find the errors in the following code: 6. The...Ch. 4 - The following statement should determine whether...Ch. 4 - Find the errors in the following code: 8. The...Ch. 4 - Prob. 9FTECh. 4 - Write an if statement that assigns 100 to x when y...Ch. 4 - Write an if-else statement that assigns 0 to x...Ch. 4 - Using the following chart, write an if-else-if...Ch. 4 - Write an if statement that sets the variable hours...Ch. 4 - Write nested if statements that perform the...Ch. 4 - Write an if statement that prints the message The...Ch. 4 - Write an if statement that prints the message The...Ch. 4 - Write an if statement that prints the message The...Ch. 4 - Write an if-else statement that displays the...Ch. 4 - Convert the following if-else-if statement into a...Ch. 4 - Match the conditional expression with the if-else...Ch. 4 - Explain what is meant by the phrase conditionally...Ch. 4 - Explain why a misplaced semicolon can cause an if...Ch. 4 - Why is it good advice to indent all the statements...Ch. 4 - What happens when you compare two String objects...Ch. 4 - Prob. 5SACh. 4 - What risk does a programmer take when not placing...Ch. 4 - Prob. 7SACh. 4 - Prob. 8SACh. 4 - Why are the relational operators called...Ch. 4 - How do you use private methods in a class to...Ch. 4 - Roman Numerals Write a program that prompts the...Ch. 4 - Time Calculator Write a program that asks the user...Ch. 4 - TestScores Class Design a TestScores class that...Ch. 4 - Software Sales A software company sells a package...Ch. 4 - BankCharges Class A bank charges 10 per month,...Ch. 4 - ShippingCharges Class The Fast Freight Shipping...Ch. 4 - FatGram Class Design a class with a method that...Ch. 4 - Running the Race Write a program that asks for the...Ch. 4 - The Speed of Sound The following table shows the...Ch. 4 - Freezing and Boiling Points The following table...Ch. 4 - Mobile Service Provider A mobile phone service...Ch. 4 - Mobile Service Provider, Part 2 Modify the program...Ch. 4 - Body Mass Index Write a program that calculates...Ch. 4 - Days in a Month Write a class named MonthDays. The...Ch. 4 - Book Club Points Serendipity Booksellers has a...Ch. 4 - Magic Dates The date June 10, 1960, is special...Ch. 4 - Hot Dog Cookout Calculator Assume that hot dogs...Ch. 4 - Roulette Wheel Colors On a roulette wheel, the...Ch. 4 - Wi-Fi Diagnostic Tree Figure 3-23 shows a...Ch. 4 - Restaurant Selector You have a group of friends...

Additional Engineering Textbook Solutions

Find more solutions based on key concepts
Knowledge Booster
Background pattern image
Computer Science
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
SEE MORE QUESTIONS
Recommended textbooks for you
  • Text book image
    EBK JAVA PROGRAMMING
    Computer Science
    ISBN:9781337671385
    Author:FARRELL
    Publisher:CENGAGE LEARNING - CONSIGNMENT
    Text book image
    EBK JAVA PROGRAMMING
    Computer Science
    ISBN:9781305480537
    Author:FARRELL
    Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781305480537
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Introduction to Classes and Objects - Part 1 (Data Structures & Algorithms #3); Author: CS Dojo;https://www.youtube.com/watch?v=8yjkWGRlUmY;License: Standard YouTube License, CC-BY