SOURCE CODE:
*Please follow the comments to better understand the code.
**Please look at the Screenshot below and use this code to copy-paste.
***The code in the below screenshot is neatly indented for better understanding.
This is a very
big question.
I have solved all of them.
Please give me an upvote dear, Much
Appreciated.!!
using System;
public class MyTime {
// fields
private int hour;
private int minute;
private int second;
// Constructor
public MyTime(){
hour=0;
minute=0;
second=0;
}
public MyTime(int hour, int minute, int second){
// check the conditions here
if(hour<0 || hour>23){
throw new ArgumentException("Invalid hour");
}
if(minute<0 || minute>59){
throw new ArgumentException("Invalid minute");
}
if(second<0 || second>60){
throw new ArgumentException("Invalid second");
}
this.hour=hour;
this.minute=minute;
this.second=second;
}
// methods
public void SetTime(int hour, int minute, int second){
// check the conditions here
if(hour<0 || hour>23){
throw new ArgumentException("Invalid hour");
}
if(minute<0 || minute>59){
throw new ArgumentException("Invalid minute");
}
if(second<0 || second>59){
throw new ArgumentException("Invalid second");
}
this.hour=hour;
this.minute=minute;
this.second=second;
}
public void setHour(int hour){
// check the conditions here
if(hour<0 || hour>23){
throw new ArgumentException("Invalid hour");
}
this.hour=hour;
}
public void setMinute(int minute){
// check the conditions here
if(minute<0 || minute>59){
throw new ArgumentException("Invalid minute");
}
this.minute=minute;
}
public void setSecond(int second){
// check the conditions here
if(second<0 || second>59){
throw new ArgumentException("Invalid second");
}
this.second=second;
}
// more get methods here
public int getHour()
{
return this.hour;
}
public int getMinute()
{
return this.minute;
}
public int getSecond()
{
return this.second;
}
// ToString
public override string ToString(){
return string.Format("{0:D2}:{1:D2}:{2:D2}",this.hour, this.minute,
this.second);
}
// next times
public MyTime NextSecond(){
// check the conditions here
if(this.second==59){
if(this.minute==59)
return new MyTime((this.hour+1)%24, 0,0);
else
return new MyTime(this.hour, (this.minute+1)%60,0);
}
else
return new MyTime(this.hour, this.minute, this.second+1);
}
public MyTime NextMinute(){
// check the conditions here
if(this.minute==59)
return new MyTime((this.hour+1)%24, 0,this.second);
else
return new MyTime(this.hour, this.minute+1,this.second);
}
public MyTime NextHour(){
// check the conditions here
if(this.hour==23)
return new MyTime(0, this.minute,this.second);
else
return new MyTime(this.hour+1, this.minute,this.second);
}
// Previous times
public MyTime PreviousSecond(){
// check the conditions here
if(this.second==0){
if(this.minute==0){
if(this.hour==0){
return new MyTime(23,59,59);
}
else{
return new MyTime(this.hour-1, 59, 59);
}
}
else {
return new MyTime(this.hour, this.minute-1, 0);
}
}
else{
return new MyTime(this.hour, this.minute, this.second-1);
}
}
public MyTime PreviousMinute(){
// check
if(this.minute==0){
if(this.hour==0){
return new MyTime(23, 59, this.second);
}
else{
return new MyTime(this.hour, 59, this.second);
}
}
else{
return new MyTime(this.hour, this.minute-1, this.second);
}
}
public MyTime PreviousHour(){
// check
if(this.hour==0){
return new MyTime(23, this.minute, this.second);
}
else{
return new MyTime(this.hour-1, this.minute, this.second);
}
}
}
public class MyTimeDemo {
static public void Main (){
//Code here
MyTime time = new
MyTime(12,58,58);
Console.WriteLine("The time is
{0}",time);
Console.WriteLine("\nNext Hour is
{0}",time.NextHour());
Console.WriteLine("Next Minute is
{0}",time.NextMinute());
Console.WriteLine("Next Second is
{0}",time.NextSecond());
Console.WriteLine("\nPrevious
Hour is {0}",time.PreviousHour());
Console.WriteLine("Previous Minute
is {0}",time.PreviousMinute());
Console.WriteLine("Previous Second
is {0}",time.PreviousSecond());
// try another
Console.WriteLine("\n===================================");
time = new MyTime(23,59,59);
Console.WriteLine("\nThe time is
{0}",time);
Console.WriteLine("\nNext Hour is
{0}",time.NextHour());
Console.WriteLine("Next Minute is
{0}",time.NextMinute());
Console.WriteLine("Next Second is
{0}",time.NextSecond());
Console.WriteLine("\nPrevious
Hour is {0}",time.PreviousHour());
Console.WriteLine("Previous Minute
is {0}",time.PreviousMinute());
Console.WriteLine("Previous Second
is {0}",time.PreviousSecond());
}
}
===============




OUTPUT:


In this practical task, you need to implement a class called MyTime, which models a time...
I need help with this java programming question
Due Wednesday by 11:59pm Points 10 Submitting a file upload Write a program in Java that implements the following class. Time hour [0, 23] minute [0, 59] second = [0, 59] No input validation needed. hour:int -minute:int second:int +Time (hour:int,minute:int, second:int) +getHour():int +getMinute():int +getSecond ():int +setHour(hour:int) void +setMinute(minute:int):void +setSecond(second:int):void +setTime (hour:int,minute:int, '."hh:mm:ss" with leading zero second:int):void. +toString():String +nextSecond():TimeA +previousSecond() Time Advance by 1 second and return this instance
Programming Assignment 1 Write a class called Clock. Your class should have 3 instance variables, one for the hour, one for the minute and one for the second. Your class should have the following methods: A default constructor that takes no parameters (make sure this constructor assigns values to the instance variables) A constructor that takes 3 parameters, one for each instance variable A mutator method called setHour which takes a single integer parameter. This method sets the value of...
You are to create a class Appointment.java that will have the following: 5 Instance variables: private String month private int day private int year private int hour private int minute 1 default constructor public Appointment() 1 non-default constructor that accepts arguments for all instance variables, your constructor must call the setter methods below to set the values of the instance variables public Appointment(String monthPassed, int dayPassed, int yearPassed, int hourPassed, int minutePassed) 5 setter methods (one for each instance variable)...
Java Programming
The program template represents a complete working Java program
with one or more key lines of code replaced with comments. Read the
problem description and examine the output, then study the template
code. Using the problem-solving tips as a guide, replace the /* */
comments with Java code. Compile and execute the program. Compare
your output with the sample output provided. Modify class Time2 to
include a tick method that increments the time stored in a Time2
object...
Using the Die class defined in this chapter, design and implement a class called PairOfDice, composed of two Die objects. Include methods to set and get the individual die values, a method to roll the dice, and a method that returns the current sum of the two die values. Create a driver class called RollingDice2 to instantiate and use a PairOfDice object. I need the main method or test class public class Die { private final int MAX = 6;...
Instructions: Refer to the Timel class provided in Figure 8.1 in your Deitel book to complete the exercise. Make sure that you follow the Program Style and Readability guidelines found in the Start Here Folder. 1. Write a Point class. The Point class should be written as an abstract data type. 2. Include the following instance variables: a. an integer representing the x coordinate b. an integer representing the y coordinate c. The instance variables in your program should only...
Design a JAVA program with the class named Computer that creates a computer object that stores the computer's brand, model, memory (in GB) and storage (in GB). The class must contain the following instance variables and methods. All variable and method names must match the specifications listed below exactly. Instance Variables: - a String variable named brand - a String variable named model - an int variable named memory - an int variable named storage Methods: The accessor and mutator...
This is for my c++ class and im stuck. Complete the Multiplex.cpp file with definitions for a function and three overloaded operators. You don't need to change anything in the Multiplex.h file or the main.cpp, though if you want to change the names of the movies or concession stands set up in main, that's fine. Project Description: A Multiplex is a complex with multiple movie theater screens and a variety of concession stands. It includes two vectors: screenings holds pointers...
Write a class called Book. Here are the relevant attributes: title author yearPublished bookPriceInCAD Provide a constructor that takes parameters to initialize all the instance variables. The constructor calls the mutator (set) methods to initialize the instance variables. Provide an accessor (get) and mutator (set) for each instance variable. The mutators all validate their parameters appropriately and use them only if valid. If the passed parameter was invalid an IllegalArgumentException will be thrown with a proper error message A...
Hello. I need help writing the following Java Program. Thank you Develop a class encapsulating the concept of a college course, assuming that a course has following attributers: code (for instance COSC1337), a description, and a number of credits (for instance 3). Include a constructor, the accessors, mutators and methods ‘toString’, ‘equals’, and ‘finalize’. Write a client class to test the behavior of the class and its methods. The outline of the class is given as follows: public class Course...