Java: An Introduction to Problem Solving and Programming (8th Edition)
Java: An Introduction to Problem Solving and Programming (8th Edition)
8th Edition
ISBN: 9780134462035
Author: Walter Savitch
Publisher: PEARSON
Question
Book Icon
Chapter 6, Problem 2E
Program Plan Intro

Time calculation

Program plan:

  • • Import necessary header files.
  • • Define the class “Time”.
    • ○ Declare the necessary variables.
    • ○ Define the empty constructor “Time()”.
      • ■ Initialize the necessary variables.
    • ○ Define the parameterized constructor.
      • ■ Declare the function “setTime()”.
    • ○ Define the function “isValid()”.
      • ■ Return the value.
    • ○ Define the function “setTime()”.
      • ■ Check the necessary condition.
      • ■ Assign value to the necessary variables.
    • ○ Define the function “getTime12()”.
      • ■ Initialize the variable “response”.
      • ■ Check the necessary condition.
      • ■ Return, the value of the variable “response”.
    • ○ Define the function “getTime24()”.
      • ■ Initialize the variable “response”.
      • ■ Check the necessary condition.
      • ■ Return, the value of the variable “response”.
    • ○ Define the function “toString()”.
      • ■ Return the value.
    • ○ Define the “main()” function.
      • ■ Create object for the class “Time”.
      • ■ Print the necessary statements.
      • ■ Call the necessary methods to print the result on the screen.

Blurred answer
Students have asked these similar questions
Implement a class that simulates a traffic light. The next method advances the color in the usual way, from green to yellow to red, then again to green. Provide two constructors, as described in the documentation of the public interface. Also supply a method that yields the number of times that this traffic light has been red. /**   A simulated traffic light.*/public class TrafficLight{   private String color;   private int reds;   /**      Constructs a green traffic light.   */   public TrafficLight()   {      /* Your code goes here */   }      /**      Constructs a traffic light.      @param initialColor the initial color "green", "yellow", or "red"   */   public TrafficLight(String initialColor)   {      /* Your code goes here */   }    /**      Moves this traffic light to the next color.   */   public void next()   {      /* Your code goes here */   }    /**      Returns the current color of this traffic light.      @return the current color   */   public String getColor()   {…
Write a java program in a class CountPoor that counts the number of families that are considered poor. Write and use a class Family that has the attributes.                                                                                                                                               income—a double value that is the income for the family size—the number of people in the family and the following methods: Family(income, size)—a constructor that sets the attributes isPoor(housingCost, foodCost)—a method that returns true if housingCost + foodCost * size is greater than half the family income (foodCost is the average food cost for an individual, while housingCost is for the family) toString—a method that returns a string containing the information about the family The program should read an integer k from the keyboard and then create an array of size k whose base type is Family. It should then create k objects of type Family and put them in the array, reading the income…
1/ Write a BankAccountTester class whose main method constructs a bank account, deposits $1,000, withdraws $500, withdraws another $400, and then prints the remaining balance. Also print the expected result   2/ Implement a class Employee. An employee has a name (a string) and a salary (a double). Provide a constructor with two arguments public Employee(String employeeName, double currentSalary) and methods public String getName() public double getSalary() public void raiseSalary(double byPercent) These methods return the name and salary, and raise the employee's salary by a certain percentage. Sample usage: Employee harry = new Employee("Hacker, Harry", 50000); harry.raiseSalary(10); // Harry gets a 10 percent raise Supply an EmployeeTester class that tests all methods.   3/Implement a class Car with the following properties. A car has a certain fuel efficiency (measured in miles/gallon or liters/km—pick one) and a certain amount of fuel in the gas tank. The efficiency is specified in…

Chapter 6 Solutions

Java: An Introduction to Problem Solving and Programming (8th Edition)

Ch. 6.2 - Can you reference an instance variable by name...Ch. 6.2 - Is the following valid, given the class...Ch. 6.2 - Prob. 13STQCh. 6.2 - Prob. 14STQCh. 6.2 - Prob. 15STQCh. 6.2 - Is the following valid, given the class...Ch. 6.2 - What values are returned by each of the following?...Ch. 6.2 - Suppose that speed is a variable of type double...Ch. 6.2 - Repeat the previous question, but instead assign...Ch. 6.2 - Suppose that nl is of type int and n2 is of type...Ch. 6.2 - Define a class CircleCalculator that hat only two...Ch. 6.2 - Which of the following statements are legal?...Ch. 6.2 - Write a Java expression to convert the number in...Ch. 6.2 - Consider the variable 5 of type String that...Ch. 6.2 - Repeat the previous question, but accommodate a...Ch. 6.2 - Write Java code to display the largest and...Ch. 6.3 - Prob. 27STQCh. 6.3 - Consider the variable allCents in the method...Ch. 6.3 - What is wrong with a program that starts as...Ch. 6.3 - Prob. 30STQCh. 6.3 - In your definition of the class OutputFormat. In...Ch. 6.4 - Prob. 32STQCh. 6.4 - Prob. 33STQCh. 6.4 - Prob. 34STQCh. 6.4 - Consider the class Species in Listing 5.19 of...Ch. 6.4 - Repeat the previous question for a method...Ch. 6.4 - Still considering the class Species in Listing...Ch. 6.4 - Rewrite the method add in Listing 6.16 so that it...Ch. 6.4 - In Listing 6.16, the set method that has a String...Ch. 6.5 - Give the definitions of three accessor methods...Ch. 6.6 - If cardSuit is an instance of Suit and is assigned...Ch. 6.7 - Suppose you want to use classes in the package...Ch. 6.7 - Prob. 43STQCh. 6.7 - Can a package have any name you might want, or are...Ch. 6.7 - On your system, place the class Pet (Listing 6.1)...Ch. 6.8 - The previous section showed you how to change the...Ch. 6 - Prob. 1ECh. 6 - Prob. 2ECh. 6 - Write a default constructor and a second...Ch. 6 - Write a constructor for the class...Ch. 6 - Consider a class characteristic that will be used...Ch. 6 - Create a class RoomOccupancy that can be used to...Ch. 6 - Write a program that tests the class RoomOccupancy...Ch. 6 - Sometimes we would like a class that has just a...Ch. 6 - Create a program that tests the class Merlin...Ch. 6 - In the previous chapter, Self-Test Question 16...Ch. 6 - Create a class Android whose objects have unique...Ch. 6 - Prob. 12ECh. 6 - Modify the definition of the class Species in...Ch. 6 - Prob. 2PCh. 6 - Using the class Pet from Listing 6.1, write a...Ch. 6 - Do Practice Program 4 from Chapter 5 except define...Ch. 6 - The following class displays a disclaimer every...Ch. 6 - Do Practice Program 5 from Chapter 5 but add a...Ch. 6 - We can improve the Beer class from the previous...Ch. 6 - Define a utility class for displaying values of...Ch. 6 - Write a new class TruncatedDollarFormat that is...Ch. 6 - Complete and fully test the class Time that...Ch. 6 - Complete and fully test the class Characteristic...Ch. 6 - Write a Java enumeration LetterGrade that...Ch. 6 - Complete and fully test the class Per n that...Ch. 6 - Write a Temperature class that represents...Ch. 6 - Repeat Programming Project 8 of the previous...Ch. 6 - Write and fully test a class that represents...Ch. 6 - Write a program that will record the votes for one...Ch. 6 - Repeat Programming Project 10 from Chapter 5, but...Ch. 6 - Create a JavaFX application that displays a button...
Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education