Question

Can someone please help me with the following java assignment. So in this assignment you will...

Can someone please help me with the following java assignment.

So in this assignment you will begin with the starterProject I provide and then add to it.  I am also asking that before you begin you really look at the starterProject because this is the object-oriented basics. The starterProject is the exact same as the ClassClockExample.zip in Module 5.  I’ve also done this using a clock because it is something that you already know how it works.  Remember that OOD and OOP is an organizational change from the functional programming method.  This is because we could create a clock without using OOP and it would work.  

You will create another class called dateTime.  See below for the details.  Then you will inherit the clock class and the dateTimeApp will test it.

Requirements:

  1. Your dateTime.java must be the class and inherit the clock class.
  2. Your dateTimeApp.java is the main program.
  3. You will create the following public member functions for the dateTime class.
    1. dateTime()

//Default constructor with parameters

//Post: date is set to 1-1-2000

//day = 1; month = 1; year = 2000

//don’t forget to call the default constructor for the

//the clock class.

  1. dateTime(intday, intmonth, intyear, inthours, intminutes, intseconds)

//Constructor with parameters

//Post: The date and time is set according to

//the parameters

//The day, month and year get validated and set

//The hours, minutes and seconds get passed on to the clock

//constructor

  1. voidsetDate(intday, intmonth, intyear)

//Function to set the date

//Post: time is set according to the

//parameters

voidsetTime(inthours, intminutes, intseconds)

//Function to set the time

//Post: time is set according to the

//parameters

  1. voidprintTime()

//Function to print the time

//Time is printed in the form hh:mm:ss

  1. voidprintDate()

//Function to print the date

//Date is printed in the form day-month-year

  1. voidprintDateTime()

//Function to print the time

//Date and then Time is printed in the form

//day-month-year hh:mm:ss

  1. voidincrementSeconds() *should still work

//Function to increment the time by 1 second

//Post: The time is incremented by 1 second

//If the before-increment time is 23:59:59, the time

//is reset to 00:00:00

  1. voidincrementMinutes()

***should still work

//Function to increment the time by 1 minute

//Post: The time is incremented by 1 minute

//If the before-increment time is 23:59:53, the time

//is reset to 00:00:53

  1. voidincrementHours()

***should still work

//Function to increment the time by 1 hour.

//Post: The time is incremented by 1 hour.

//If the before-increment time is 23:45:53, time

//is reset to 00:45:53

  1. boolequalTime(dateTime otherClock)

***should still work

//Function to compare the two times

//Function returns true if this time is equal to

//otherClock; otherwise it returns false

  1. voidincrementDays()

//Function to increment the date by 1 day

//Post: The time is incremented by 1 day

//If the before-increment date is 31-12-2009, the date

//is reset to 1-1-9010

  1. voidincrementMonths()

//Function to increment the date by 1 month

//Post: The month is incremented by 1 month

//If the before-increment date is 31-12-2009, the date

//is reset to 31-1-9010

  1. voidincrementYears()

//Function to increment the date by 1 year.

//Post: The year is incremented by 1 year.

  1. boolequalDate(dateTime otherDate)

//Function to compare the two dates

//Function returns true if this date is equal to

//otherwise it returns false

  1. The dateTimeApp will then run the clock and the date.  You need to test all of the functionality you have built in.
  2. Be sure you also update or change the header file to yours.

INFO 1521 - StarterProject

The following is what I might have given you if I wanted you to create the starterProject. “You are going to create a clock in this project and use a class while doing it.  So the class will be the clock called Clock.java and then you will have another JAVA file that runs it called ClockApp.java.  Below are the requirements for the clock and the clockapp that runs it. “

Requirements:

  1. Your Clock.java must be the class.
  2. Your ClockApp.java is the main program.
  3. Your clock will be a 24 hour clock
  4. You will create the following public member functions for the clock class.
    1. clock()

//Default constructor with parameters

//Post: time is set to 00:00:00

//hr = 0; min = 0; sec = 0

  1. clock(inthours, intminutes, intseconds)

//Constructor with parameters

//Post: The time is set according to

//the parameters

//hr = hours; min = minutes; sec = seconds

  1. voidsetTime(inthours, intminutes, intseconds)

//Function to set the time

//Post: time is set according to the

//parameters: hr = hours; min = minutes; sec = seconds

  1. voidprintTime()

//Function to print the time

//Time is printed in the form hh:mm:ss

  1. voidincrementSeconds()

//Function to increment the time by 1 second

//Post: The time is incremented by 1 second

//If the before-increment time is 23:59:59, the time

//is reset to 00:00:00

  1. voidincrementMinutes()

//Function to increment the time by 1 minute

//Post: The time is incremented by 1 minute

//If the before-increment time is 23:59:53, the time

//is reset to 00:00:53

  1. voidincrementHours()

//Function to increment the time by 1 hour.

//Post: The time is incremented by 1 hour.

//If the before-increment time is 23:45:53, time

//is reset to 00:45:53

  1. boolequalTime(constclockType otherClock)

//Function to compare the two times

//Function returns true if this time is equal to

//otherClock; otherwise it returns false

  1. The ClockApp will then run the clock.  You need to test all of the functionality you have built in.
  2. Don’t forget your header file
  3. While testing the functionality create a loop and increment the seconds for a while.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

clock.java

//clock class
public class clock
{
   int hours;       // variable to store the hours
   int minutes;   // variable to store the minutes
   int seconds;   // variable to store the seconds
  
//Default constructor
public clock()
{  
hours = 0;
minutes = 0;
seconds = 0;
}
  
//parameterized constructor
public clock(int hours, int minutes, int seconds)
{
   this.hours = hours;
this.minutes = minutes;
this.seconds = seconds;
}
  
//method to set time
public void setClock(int hours, int minutes, int seconds)
{
   this.hours = hours;
this.minutes = minutes;
this.seconds = seconds;
}
}
  

dateTime.java

//dateTime class, subclass of clock
public class dateTime extends clock
{
   private int month;    // variable to store the month
   private int day;    // variable to store the day
   private int year;     // variable to store the year
  
//Default constructor
public dateTime()
{
   super();
month = 1;
day = 1;
year = 2000;
}

//parameterized constructor
public dateTime(int day, int month, int year, int hours, int minutes, int seconds)
{
   super(hours, minutes, seconds);
  
if(isValidDate(month, day, year))
{
this.month = month;
this.day = day;
this.year = year;
}
else
{
System.out.println("Invalid Date!");
month = 1;
   day = 1;
   year = 2000;
}
}

//method to set date
public void setDate(int day, int month, int year)
{
if(isValidDate(month, day, year))
{
this.month = month;
this.day = day;
this.year = year;
}
else
{
System.out.println("Invalid Date!");
month = 1;
   day = 1;
   year = 2000;
}
}
  
//method to set time
public void setTime(int hours, int minutes, int seconds)
{
this.hours = hours;
this.minutes = minutes;
this.seconds = seconds;
}

//method to check leap year
private boolean isLeapYear(int y)
{
if(y%400==0 || y%4==0 && y%100!=0 )
return true;
return false;
}

//method to check valid date
private boolean isValidDate(int mm, int dd, int yy)
{

if (yy > 9999 || yy < 1900)
return false;
if (mm < 1 || mm > 12)
return false;
if (dd < 1 || dd > 31)
return false;

if (mm == 2)
{
if (isLeapYear(yy))
return (dd <= 29);
else
return (dd <= 28);
}

if (mm == 4 || mm == 6 ||
mm == 9 || mm == 11)
return (dd <= 30);

return true;
   }
  
   //method to display date
   public void printTime()
   {
       System.out.print(hours + ":" + minutes + ":" + seconds);
   }

//method to display date
public void printDate()
{
   System.out.print(day + "-" + month + "-" + year);
}
  
//method to display date and time
public void printDateTime()
{
   System.out.print(day + "-" + month + "-" + year);
   System.out.print(" " + hours + ":" + minutes + ":" + seconds);
}
  
//method to increment the time by 1 second
public void incrementSeconds()
{
   if(hours==23 && minutes==59 && seconds==59)
   {
       hours = 0;
        minutes = 0;
        seconds = 0;
        incrementDays();
   }
   else if(minutes==59 && seconds==59)
   {
       hours++;
       minutes = 0;
        seconds = 0;
      
   }
   else if(seconds==59)
   {
       minutes++;
        seconds = 0;
   }
   else
       seconds++;
}
  
//method to increment the time by 1 minute
public void incrementMinutes()
{
   if(hours==23 && minutes==59)
   {
       hours = 0;
        minutes = 0;
        incrementDays();
   }
   else if(minutes==59)
   {
       hours++;
       minutes = 0;
   }
   else
       minutes++;
}
  
//method to increment the time by 1 hour
public void incrementHours()
{
   if(hours==23)
   {
       hours = 0;
        incrementDays();
   }
   else
       hours++;
}
  
//method to compare the two times
public boolean equalTime(dateTime otherClock)
{
   if(hours==otherClock.hours && minutes==otherClock.minutes && seconds==otherClock.seconds)
       return true;
   return false;
}
  
  
//method to increase the date by one day
public void incrementDays()
{
if (day == 31 && (month == 1 || month == 3 || month == 5 || month == 7
|| month == 8 || month == 10 || month == 12))
{
if (month == 12)
{
month = 1;
day = 1;
year++;
}
else
{
day = 1;
month++;
}
}
else if (day == 30 && (month == 4|| month == 6 || month == 9 || month == 11))
{
day = 1;
month++;
}
else if (isLeapYear(year)== true && day == 29 && month == 2)
{
day = 1;
month++;
}
else if(isLeapYear(year)== false && day == 28 && month == 2)
{
day = 1;
month++;
}
else

day++;
}

//method to return number of days in a month
private int noOfDaysInMonth(int month)
{
switch(month)
{
case 1: case 3: case 5: case 7: case 8: case 10: case 12: return 31;
case 4: case 6: case 9: case 11: return 30;
case 2: if(isLeapYear(year)) return 29; else return 28;
}
return 0;
}

//method to return number of days passed in the year
private int noOfDaysPassedInYear()
{
int days = day;

for(int i=1; i<month; i++)
{
days += noOfDaysInMonth(i);
}
return days;
}

//method to return number of days remaining in the year
private int noOfDaysRemainingInYear()
{
int days;

if(isLeapYear(year))
days = 366 - noOfDaysPassedInYear();
else
days = 365 - noOfDaysPassedInYear();

return days;
}
  
//method to increment the date by 1 month
public void incrementMonths()
{
   if(month==12)
   {
       month = 1;
       year++;
   }
   else
       month++;
}
  
//method to increment the date by 1 year
public void incrementYears()
{
   year++;
}
  
//method to compare the two dates
boolean equalDate(dateTime otherDate)
{
   if(year==otherDate.year && month==otherDate.month && day==otherDate.day)
       return true;
   return false;
}
}

dateTimeApp.java

//dateTimeApp class
public class dateTimeApp
{
   //main method
   public static void main (String[] args)
   {
       //create an object of dateTime class
       dateTime dt = new dateTime(31, 07, 2019, 20, 45, 22);
      
       System.out.print("Now: ");
       dt.printDateTime();       //display date and time
      
       dt.incrementDays();
      
       System.out.print("\nTomorrow: ");
       dt.printDate();           //display date
      
}
}

Output:

Now: 31-7-2019 20:45:22
Tomorrow: 1-8-2019

Add a comment
Know the answer?
Add Answer to:
Can someone please help me with the following java assignment. So in this assignment you will...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Need help with this java code supposed to be a military time clock, but I need...

    Need help with this java code supposed to be a military time clock, but I need help creating the driver to test and run the clock. I also need help making the clock dynamic. public class Clock { private int hr; //store hours private int min; //store minutes private int sec; //store seconds public Clock () { setTime (0, 0, 0); } public Clock (int hours, intminutes, int seconds) { setTime (hours, minutes, seconds); } public void setTime (int hours,int...

  • Write in C++ please In Chapter 10, the class clockType was designed to implement the time...

    Write in C++ please In Chapter 10, the class clockType was designed to implement the time of day in a program. Certain applications, in addition to hours, minutes, and seconds, might require you to store the time zone. Derive the class extClockType from the class clockTypeby adding a member variable to store the time zone. Add the necessary member functions and constructors to make the class functional. Also, write the definitions of the member functions and the constructors. Finally, write...

  • 3. write a c++ program: Design and implement a class called Clock that describes the time...

    3. write a c++ program: Design and implement a class called Clock that describes the time of a clock: a) Include in the class 3 constructors with one, two, and three parameters to set the hours, the minutes, and the seconds, respectively. b) Include also a default constructor that sets the member variables of the class to 00:00:00. c) Write a member function to increment the time by a given amount, and second member function to reset the clock. The...

  • This is a Java programming assignment and I want help with the Time class. See below...

    This is a Java programming assignment and I want help with the Time class. See below for assignment details: For this question you must write a java class called Time and a client class called TimeClient. The partial Time class is given below. (For this assignment, you will have to submit 2 .java files: one for the Time class and the other one for the TimeClient class and 2 .class files associated with these .java files. So in total you...

  • Please help with Java programming! This code is to implement a Clock class. Use my beginning...

    Please help with Java programming! This code is to implement a Clock class. Use my beginning code below to test your implementation. public class Clock { // Declare your fields here /** * The constructor builds a Clock object and sets time to 00:00 * and the alarm to 00:00, also. * */ public Clock() { setHr(0); setMin(0); setAlarmHr(0); setAlarmMin(0); } /** * setHr() will validate and set the value of the hr field * for the clock. * *...

  • Programming Assignment 1 Write a class called Clock. Your class should have 3 instance variables, one...

    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...

  • Lab Exercise #11 Assignment Overview You will work with a partner on this exercise during your la...

    help with cse problem Lab Exercise #11 Assignment Overview You will work with a partner on this exercise during your lab session. Two people should work at one computer. Occasionally switch the person who is typing. Talk to each other about what you are doing and why so that both of you understand each step Part A: Class Date . Download the files for this laboratory exercise, then run the Python shell and enter the following commands: >>>import date >>help(...

  • //Please help me out with this problem.. This problem has to be done in C++ and...

    //Please help me out with this problem.. This problem has to be done in C++ and has to strictly follow the instructions... I have given the expected output of the problem below.   1) Design a class Date: Provide 3 instance variables (int) to store the month, the day number, and the year Provide the following functions Default constructor -sets date to, 1500 Constructor with parameters - if parameters are not valid, set like default constructor setDate if parameters are not...

  • please do in java and comments the code so i can understand Requirements: Create a Java...

    please do in java and comments the code so i can understand Requirements: Create a Java class named “MyRectangle2D.java”. Your class will have double two variables named x and y. These will represent the center point of your rectangle. Your class will have two double variables named width and height. These will represent the width and height of your rectangle. Create getter and setter methods for x, y, width, and height. Create a “no argument” constructor for your class that...

  • For this project you will be writing up a simple Clock program to keep track of...

    For this project you will be writing up a simple Clock program to keep track of time. SimpleClock.java - contains your implementation of the SimpleClock class. You will need to provide the code for a constructor as well as the mutator methods set and tick and the accessor method toString. Look at the comments for each method to see how they should be implemented - the trickiest method is probably tick, which requires that you deal with the changing of...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT