Logbook

  • May 2020
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Logbook as PDF for free.

More details

  • Words: 395
  • Pages: 3
//-------------------------------------------------------------------// // Laboratory 1 Logbook.java // // Definitions for the Logbook ADT // // // //-------------------------------------------------------------------import java.io.*; import java.util.*;

// For reading (keyboard) & writing (screen) // For GregorianCalendar class

class Logbook { // Data members private int logMonth, logYear; private int[] entry = new int[31]; private GregorianCalendar logCalendar;

// Logbook month // Logbook year // Array of Logbook entries // Java's built-in Calendar

// Constructor public Logbook ( int month, int year ) // Creates an empty logbook for the specified month and year. { int j; if(!((month-1)>=0&&(month-1)<=11)) logCalendar=new GregorianCalendar(); // Today's Date else { // Assumes a default DAY_OF_MONTH as first day of month logCalendar=new GregorianCalendar(year,month-1,1); logMonth=month; logYear=year; } // Set each entry to 0 for(j=0;j<=30;j++) entry[j]=0; } // Methods public void putEntry ( int day, int value ) // Stores entry for the specified day. { if(day>0 && day<=daysInMonth()) entry[day-1]=value; } public int getEntry ( int day ) // Returns entry for the specified day. { if(day>0 && day<=daysInMonth()) return entry[day-1]; else return -1;

} public int month ( ) // Returns the logbook month. { return logMonth; } public int year ( ) // Returns the logbook year. { return logYear; } public int daysInMonth ( ) // Returns the number of days in the logbook month. { int a[]={31,28,31,30,31,30,31,31,30,31,30,31}; if((logMonth-1)==1) if(leapYear()) return 29; else return 28; else return a[logMonth-1]; } // Facilitator (helper) method private boolean leapYear ( ) // If the logbook month occurs during a leap year, then returns true. // Otherwise, returns false. { boolean b=logCalendar.isLeapYear(logYear); return b; } //-------------------------------------------------------------------// // In-lab operations // //-------------------------------------------------------------------private int dayOfWeek ( int day ) // Returns the day of the week corresponding to the specified day. { logCalendar.set(logYear,logMonth-1,day); int t=logCalendar.get(Calendar.DAY_OF_WEEK); // Returns the days numbered from 1 to 7 return (t-1); } public void displayCalendar () // Displays a logbook using the traditional calendar format. {

int dnb=dayOfWeek(1); System.out.println("

"+logMonth+" / "+logYear);

System.out.println("Sun"+"\t"+"Mon"+"\t"+"Tue"+"\t"+"Wed"+"\t"+"Thu"+"\t"+"Fri"+"\ t"+"Sat"); //System.out.print(" "); for(int j=0;j
public void plus ( Logbook rightLogbook ) // Combine logbooks. { }*/

} // class Logbook

Related Documents

Logbook
May 2020 43
Logbook
May 2020 44
Logbook
June 2020 32
Master Logbook
November 2019 47
Logbook Ptgmi
October 2019 33
Logbook Background.docx
November 2019 29