Concept explainers
Write a method called makeItNewYears that could be added to the class DateFirstTry in Display 4.1. The method makeItNewYears has no parameters and sets the month instance variable to "January" and the day instance variable to 1. It does not change the year instance variable.
Question reference: The method, makeItNewYears, which having the no parameter, also sets the instance variable named month to “January� and set the current day to 1.
Method Explanation:
The definition of the method, makeItNewYears, sets the value of month and day.
Month and day are the instance variables of class, DateFirstTry.
The method sets the month variable to January, the day variable to 1.
Explanation of Solution
Method:
//Method definition
public void makeItNewYears()
{
       month=�January�; //sets the month variable
      day=1; //sets the day variable
}
Want to see more full solutions like this?
Chapter 4 Solutions
Absolute Java (6th Edition)
Additional Engineering Textbook Solutions
Starting Out with Python (3rd Edition)
Starting out with Visual C# (4th Edition)
Digital Fundamentals (11th Edition)
Artificial Intelligence: A Modern Approach
Modern Database Management (12th Edition)
- 1A. Create a Die class with one integer instance variable called sideUp. Give it a constructor and a getSideUp() method that returns the value of sideUp and a void roll() method that changes sideUp to a random value from 1 to 6. [Note: To generate a random integer between 1 and 6, use Math.random() method] Then create a DieDemo class with a main method that creates two Die objects, rolls them, and then prints the sum of the two sides up.arrow_forwardThe following is a class definition for a simple Ebook. Two instance variables and one parameterless constructor are provided. Part 1: Write a second constructor that takes a String array of pages as input and sets the String array instance variable equal to the input. Continue to default the current page number to zero. Part 2: Write a getter and a setter method for the page number variable. The setter should check to make sure that the input is a valid page number and only update the variable if the new value is valid. Part 3: Write a getCurrentPage method that returns the String of the current page indexed by current_page. public class Ebook{ private String[] pages; private int current_page; //constructor public Ebook() { this.pages = {"See Spot.", "See Spot run.", "Run, Spot, run."}; this.current_page = 0; }}arrow_forward2A. Create a Date class with three integer instance variables named day, month, year. It has a constructor with three parameters for initializing the instance variables, and it has one method named daysSinceJan1(). It computes and returns the number of days since January1ofthe same year, including January 1 and the day in the Date object. For example, if day is a Date object with day = 1, month = 3, and year = 2000, then the call date.daysSinceJan1( ) should return 61 since there are 61 days between the dates of January 1, 2000, and March 1, 2000, including January1 and March 1. Include a DateDemo class that tests the Date class. Don't forget leap years. %3D %3Darrow_forward
- Create a class called Student to represent a Student exam grades. The class has four instance variables: A String variable for the name, and three double variables to store three exams grades for the student. Write a mutator method that takes four parameters—A String and three doubles. Use these parameters to initialize the instance variables declared earlier. Write a getAverage method that calculates and returns the average of the three exam grades. Write a separate program that creates 2 Student objects to hold the following data. First Name Exam#1 Exam#2 Exam#3 Ahmed 83.0 95.5 90.0 Kareema 75.25 83.0 89.0 Output the name and average grade for each of the above students.arrow_forwardCreate a class called FinalGrade that is used to represent the points obtained in the letter grade of CSC 110 by different students. The FinalGrade class should include three pieces of information as instance variables—studentName (type String), studentID (type String), and pointsObtained (type int). Your class should have a constructor that initializes the three instance variables. Provide a set and a get method for each and every instance variable. In addition, provide a method named computeLetterGrade that returns the letter grade obtained by the student taking the pointsObtained as an argument. For the grading policy refer to CSC 110 grading scheme specified in syllabus. Write a test application named FinalGradeDriver that creates at least 3 different objects of class FinalGrade and test all the methods of class FinalGrade. Sample Output Student Name : Homer SimpsonStudent ID : S123456Points Obtained : 99Letter Grade : A Student Name : Marge SimpsonStudent ID : S234567Points…arrow_forwardCreate a new project for this program called TestOldMaid and add a class with a main() method. In the project: Copy your Deck and Card class from the earlier project into it. Create a subclass of Deck called OldMaidDeck. It is special because one of the Queens is missing so it only has 51 cards. Create a constructor method that calls the super class constructor, then removes a queen. Override the toString method so it returns the name of the deck and the number of cards in it. Write the test main() method. Create an OldMaidDeck object and deal all the cards to six players. It is ok if not everyone has an equal number of cards. Use arrays or ArrayLists for the players hands. Show the hands of all 6 players. Refer to the web to find out more about the Old Maid card game: https://bicyclecards.com/how-to-play/old-maid/ Fully document all classes with your name, date and description. And each data member and method is documented. Each block that does something is also documented.arrow_forward
- Create a new project for this program called TestOldMaid and add a class with a main() method. In the project: Copy your Deck and Card class from the earlier project into it. Create a subclass of Deck called OldMaidDeck. It is special because one of the Queens is missing so it only has 51 cards. Create a constructor method that calls the super class constructor, then removes a queen. Override the toString method so it returns the name of the deck and the number of cards in it. Write the test main() method. Create an OldMaidDeck object and deal all the cards to six players. It is ok if not everyone has an equal number of cards. Use arrays or ArrayLists for the players hands. Show the hands of all 6 players. Refer to the web to find out more about the Old Maid card game. Fully document all classes with your name, date and description. And each data member and method is documented. Each block that does something is also documented. Without removing the Queensarrow_forwardWrite a class Cylinder that contains information about a cylindrical object. The Cylinder class must have two instance variables: self.r is a floating point value describing the radius of the cylinder self.h is a floating point value describing the height of the cylinder The Cylinder class should also have a constructor and two methods: • _init__(self, diameter, height) takes in two parameters other than self, representing the diameter of the cylinder, and the height, and uses this information to set up self.r and self.h. Note that to get the radius (self.r) from the diameter, you'll need to divide by 2. • get_surface_area(self) returns the surface area of the cylinder, given by the formula: A = 2лr² + 2лrh You should import math and use math.pi to get an accurate value for get_volume (self) returns the volume of the cylinder, given by the formula: V = πr²harrow_forwardalso need help Write a second constructor that takes a String array of pages as input and sets the String array instance variable equal to the input. Continue to default the page number to zero. Part 2: Write a getter and a setter method for the current page number variable. The setter should check to make sure that the input is a valid page number and only update the variable if the new value is valid. Part 3: Write a getCurrentPage method that returns the String of the current page indexed by current_page. public class Ebook{ private String[] pages; private int current_page; //constructor public Ebook() { this.pages = {"See Spot.", "See Spot run.", "Run, Spot, run."}; this.current_page = 0; }}arrow_forward
- Create a class called Employee that includes three pieces of information as instance variables—a first name (typeString), a last name (typeString) and a monthly salary (double).Provide a set and a get method for each instance variable.Keep in mind you should get values from user.There should be a method called calculateSalary() witch deducts the income tax from the salary on the following basis: 20% income tax if the salary is above Rs 30000. 15% income tax if the salary is between Rs.20000 and Rs.30000. 10% income tax if the salary is below Rs. 20000. Write a test application named EmployeeTest that demonstrates class Employee’s capabilities. Create Employee objects and display each object’s full name ,salary , income tax and net salary of employees. note.....This is java programmmarrow_forwardCreate a class called Employee that includes three pieces of information as instance variables—a first name (typeString), a last name (typeString) and a monthly salary (double).Provide a set and a get method for each instance variable.Keep in mind you should get values from user.There should be a method called calculateSalary() witch deducts the income tax from the salary on the following basis: 20% income tax if the salary is above Rs 30000. 15% income tax if the salary is between Rs.20000 and Rs.30000. 10% income tax if the salary is below Rs. 20000. Write a test application named EmployeeTest that demonstrates class Employee’s capabilities. Create Employee objects and display each object’s full name ,salary , income tax and net salary of employees.arrow_forwardP1. In this question, you are provided a completed superclass – Shape (Do not make any changes to this class!). This class represents generic shapes and has several methods that you will have to override in the Circle and Rectangle subclasses, whose code skeletons are provided as well. You are required to complete these two classes so that they can correctly describe and calculate their attributes. For the Circle class, create the following: A private double instance variable m radius. A constructor that takes two parameters (in the order of color, radius). It should use the parameter for radius to set the m_radius instance variable and then explicitly call the parent class constructor using the super keyword and pass in the color parameter. A method that overrides the calcArea method of the superclass and calculates the area of the circle. The area of a circle can be calculated as 3.14 x r² (where r is the radius). A method that overrides the calcPerimeter method of the superclass and…arrow_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