Write a method called happyGreeting that could be added to the class DateSecondTry in Display 4.2. The method happyGreeting writes the string "Happy Days ! " to the screen a number of times equal to the value of the instance variable day. For example, if the value of day is 3, then it should write the following to the screen:
Happy Days!
Happy Days!
Happy Days!
Use a local variable.
Want to see the full answer?
Check out a sample textbook solutionChapter 4 Solutions
Absolute Java (6th Edition)
Additional Engineering Textbook Solutions
Java How to Program, Early Objects (11th Edition) (Deitel: How to Program)
Experiencing MIS
Experiencing MIS
Starting Out with Java: From Control Structures through Objects (7th Edition) (What's New in Computer Science)
Java: An Introduction to Problem Solving and Programming (8th Edition)
Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
- JAVA HELP PLEASE! Write a class Rectangle that has only the following public methods (you can add other non-public methods if you think you need them): Write a constructor that creates a rectangle using the x, y coordinates of its lower left corner, its width and its height (the parameters must be in that order). Creating a rectangle with non-positive width or height should not be allowed; throw an IllegalArgumentException for those cases. The values of x and y are allowed to be negative. Write a method overlap(Rectangle other). This method should return true if this rectangle overlaps with other, false otherwise. Rectangles that touch each other are not considered to be overlapping. Write a method toString that returns a String. The string should be formatted exactly as:“x:2, y:3, w:4, h:5”without the quotation marks and replacing the numbers with the actual attribute values of the object. A class called Rectangle exists in Java already. You are not allowed to use this class in any…arrow_forwardJAVA Write an application to simulate the rolling of two dice. The application should use an object of class Random once to roll the first die and again to roll the second die. The sum of the two values should then be calculated. Each die can show an integer value from 1 to 6, so the sum of the values will vary from 2 to 12, with 7 being the most frequent sum, and 2 and 12 the least frequent.arrow_forwardSome Websites impose certain rules for passwords, involving use of certain numbers and special characters. Write a Python program (Console and GUI) that prompts the user to enter a password and displays "valid password" if the rule is follows rules of the company, or "invalid password" otherwise. Write a method or a function for implementing the password checking rules for the method/function as follows: A password must have at least eight characters. A password must consist of only letters and digits. A password must contain at least two digits. Sample 1 Enter a string for password: wewew43x valid password Sample 2 Enter a string for password: 343a invalid passwordarrow_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 Course, which has one field: String courseName Create the constructor, accessor, and mutator for the class. Then, in the main method of this class, create an instance of the class with the name "CST1201". Write an equivalent while statement to replace the following for statement for (int i=2; i<100; i=i+2) { System.out.println(i); }arrow_forwardCreate a class named Player with a default name as "player", a default level as 0, and a default class type of "fighter". Feel free to add any other attributes you wish! python program Create an instance method in the Player class called attack that takes another player as a parameter. This function should compare the level of the two players, and return whether the player won, lost, or tied.Finally create a loop that allows the user to input a name and a class type for two players; the level of both players should be determined at random (between 1 and 99). Print out the name and attributes of each player, and have the first player attack the second. Print whether the player won, lost, or tied. Ask if the user wants to try again.arrow_forward
- in computer programming: java Create a rectangle class that can compute the area and the sum of its sides. Create a specialized method that will allow the class to compare other rectangle objects. The comparison should identify the larger rectangle according to the object’s area. You should be able to implement the class where the user provides rectangle dimensions. The program should be able to display which of the rectangle inputs is larger using the Rectangle class method that you defined. Sample output: Enter Length R1: 1 Enter Width R1: 1 Enter Length R2: 2 Enter Width R2: 2 Results: R1 Area: 1 R1 Sum: 2 R2 Area: 4 R2 Sum: 4 R2 is the bigger Rectangle! Note: All characters in boldface are user inputs.arrow_forwardcreate a class rectangle with attributes length and width both encapsulated, each of which defaults to 1. provide methods that calculate the rectangle’s perimeter and area. write set and get methods for both length and width tp allow their access through behaviors. the set methods should verify that length and width are each floating-point numbers larger than 0.0 and less than 20.0. write a program to test class rectanglearrow_forwardCreate a rectangle class that can compute the area and the sum of its sides. Create a specialized method that will allow the class to compare other rectangle objects. The comparison should identify the larger rectangle according to the object’s area. You should be able to implement the class where the user provides rectangle dimensions. The program should be able to display which of the rectangle inputs is larger using the Rectangle class method that you defined. Sample output: Enter Length R1: 1 Enter Width R1: 1 Enter Length R2: 2 Enter Width R2: 2 Results: R1 Area: 1 R1 Sum: 2 R2 Area: 4 R2 Sum: 4 R2 is the bigger Rectangle! Note: All characters in boldface are user inputs.arrow_forward
- The 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_forwardPlease provide JAVA source code for following assignment. Please attach proper comments and read the full requirements. The local Driver’s License Office has asked you to write a program that grades the written portion of the driver’s license test The test has 20 multiple choice questions. Here are the correct answers: B D A A C A B A C D B C D A D C C D D A A student must correctly answer 15 of the 20 questions to pass the exam. Write a class named Drivertest that holds the correct answers to the test in an array field. The class should also have an array field that holds the student’s answers. The class should have the following methods: passed. Returns true if the student passed the test, or false if the student failed totalCorrect. Returns the total number of correctly answered questions totalIncorrect. Returns the total number of incorrectly answered questions questionsMissed. An int array containing the…arrow_forwardWrite a program that accepts two numbers. Use Scanner class to get the user input. Create 4 classes, the first one is the Main Class that has the main method, the other three classes are Su m, Subtract and Multiply. These three classes should have their constructors which has a parameter of type int. Create a method for each class that returns the result of the computation of two numbers. In the main method, after accepting the user input, it should call the three methods from the three classes and display its result.arrow_forward
- Microsoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,EBK JAVA PROGRAMMINGComputer ScienceISBN:9781305480537Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT