abstract class:
An abstract class is a class which may or may not include abstract methods and cannot be instantiated but rather can be sub classed.
Program Code:
Filename: TestCalendar.Java
//Import the packages
import java.util.*;
//class definition
public class TestCalendar
{
//main function definition
public static void main(String[] args)
{
/* Construct a Gregorian calendar for the current date and time*/
Calendar calendar = new GregorianCalendar();
//print current time by using object Calender
System.out.println("Current time is " + new Date());
System.out.println("YEAR: " + calendar.get(Calendar.YEAR));
System.out.println("MONTH: " + calendar.get(Calendar.MONTH));
System.out.println("DATE: " + calendar.get(Calendar.DATE));
System.out.println("HOUR: " + calendar.get(Calendar.HOUR));
System.out.println("HOUR_OF_DAY: " +
calendar.get(Calendar.HOUR_OF_DAY));
System.out.println("MINUTE: " + calendar.get(Calendar.MINUTE));
System.out.println("SECOND: " + calendar.get(Calendar.SECOND));
//print the current day of the week
System.out.println("DAY_OF_WEEK: " calendar.get(Calendar.DAY_OF_WEEK));
//print the current day of the month
System.out.println("DAY_OF_MONTH: " +
calendar.get(Calendar.DAY_OF_MONTH));
//print the current day of the year
System.out.println("DAY_OF_YEAR: " +
calendar.get(Calendar.DAY_OF_YEAR));
//print the current week of the month
System.out.println("WEEK_OF_MONTH: " +
calendar.get(Calendar.WEEK_OF_MONTH));
//print the current week of the year
System.out.println("WEEK_OF_YEAR: " +
calendar.get(Calendar.WEEK_OF_YEAR));
//print whether time is in A.M or P.M.
System.out.println("AM_PM: " + calendar.get(Calendar.AM_PM));
// Construct a calendar for December 25, 1997
Calendar calendar1 = new GregorianCalendar(1997, 11, 25);
String[] dayNameOfWeek = {"Sunday", "Monday", "Tuesday", "Wednesday","Thursday", "Friday", "Saturday"};
//print day of the week
System.out.println("December 25, 1997 is a " +
dayNameOfWeek[calendar1.get(Calendar.DAY_OF_WEEK) - 1]);
}
}
Want to see the full answer?
Check out a sample textbook solutionChapter 13 Solutions
Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
- Is it possible to modify the scope of the subclass's overridden method?arrow_forwardTrue or False? Interface can be used to store a common method implementation.arrow_forwardMust be written in Python. Please include docstring and show how output should look like. Remember that all data members should be private. An object can access it's own private data members directly. It can also access the private data members of other objects of the same class directly. But when accessing a private data member of an object of another class, it needs to call the appropriate get method. If that sounds complicated, just remember this: if a method is in the same class as a private data member, then it can access that data member directly, otherwise, it needs to use a get method. Write a class named Point that has two data members, x_coord and y_coord, representing the two coordinates of the point. It should have: an init method that takes two arguments, an x-coordinate and y-coordinate (in that order), and uses them to initialize the two data members. get methods for the two data members: get_x_coord and get_y_coord. a method named distance_to that takes a Point object…arrow_forward
- what is the generic term for a method that creates an instance of a class (constructors?) and how would you call it for a class named MyClass that does not take any parameters in PYTHON?arrow_forwardRequirement: In this assignment, you are going to build classes that handle bank accounts to support foreign currencies. In the attached files, there is a new class ForeignCurrencyAccount that extends the Account class that you developed in the previous assignment. Please complete the implementation of ForeignCurrencyAccount, because it only includes method headers, and TO DO comments for you to complete. You will use the Account class that you have developed earlier. Copy your version of Account.java to same src folder for Assignment #3. Add this method to Account class before you start: public double getBalanceInCAD() {return balance;} Also download Test2.java and Transaction.java to your project's src folder. Test2.java file is a test program that creates Account and ForeignCurrencyAccount objects with different currencies and makes some financial transactions on the accounts. Test2 class will display account information while doing transactions. Transaction class is used to buy /…arrow_forwardWhat is method overloading? Is it permissible to define two methods that have the same name but different parameter types? Is it permissible to define two methods in a class that have identical method names and parameter lists, but different return value types or different modifiers?arrow_forward
- What are the differences between the static method and instance method.arrow_forwardNot all dogs like to bark, but some like to make a lot of noise! In this exercise we have a Dog superclass and a LoudDog subclass. You do not need to modify the Dog class. Your task is to write two override methods in the LoudDog class. You will override the speak method to return BARK!. You will then override the toString so that it returns Clover is loud and likes to BARK! where Clover is replaced by the name variable. Create and print at least one Dog and one LoudDog to test. public class DogTester{public static void main(String[] args){// Start here}} public class Dog{private String name;public Dog(String name){this.name = name;}public String getName(){return name;}public String speak(){return "Bark!";}public String toString(){return name + " likes to " + speak();}} public class LoudDog extends Dog{public LoudDog(String name){super(name);}// Override the speak method here//Override the toString here.//Remember, you can access the name using super.getName()}arrow_forwardCreate a deck of cards class. Internally, the deck of cards should use another class, a card class. Your requirements are: The Deck class should have a deal method to deal a single card from the deck After a card is dealt, it is removed from the deck. There should be a shuffle method which makes sure the deck of cards has all 52 cards and then rearranges them randomly. The Card class should have a suit (Hearts, Diamonds, Clubs, Spades) and a value (A,2,3,4,5,6,7,8,9,10,J,Q,K)arrow_forward
- Which classes in the java.util package are abstract? Some of them have Abstract in the class name, but is there any other way to tell from the documentation? Which concrete classes extend them?arrow_forwardSuppose two parent classes provide a method with the same name. Which one do we use in the child? Can we access both?arrow_forwardIts missing order and tester class plus look at the question information again i need you to redo it with the new classes tooarrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education