Concept explainers
Write a method called printDetails for a class that has a field of type String called name. The printDetai1s method should print out a string of the form "The name of this person is", followed by the value of the name field. For instance, if the value of the name field is "Helen", then printDetails would print:
The name of this person is Helen
Want to see the full answer?
Check out a sample textbook solutionChapter 2 Solutions
Objects First with Java: A Practical Introduction Using BlueJ (6th Edition)
Additional Engineering Textbook Solutions
Starting Out with C++ from Control Structures to Objects (8th Edition)
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
Database Concepts (7th Edition)
C How to Program (8th Edition)
Problem Solving with C++ (9th Edition)
Starting Out with C++: Early Objects (9th Edition)
- javaaa Write a class with a constructor that accepts a String object as its argument. The class should have a method that returns the number of vowels in the string, and another method that returns the number of consonants in the string. Demonstrate the class in a program by invoking the methods that return the number of vowels and consonants. Print the counts returned. Imagine you are developing a software package for an online shopping site that requires users to enter their own passwords. Your software requires that users’ passwords meet the following criteria: The password should be at least six characters long. The password should contain at least one uppercase and at least one lowercase letter. The password should have at least one digit. Write a program that asks the user to enter a password, then displays a message indicating whether it is valid or not.arrow_forwardWrite a program that test methods in the class. • Hint: the employee deserved retirement if he has year of Service >25 or his age >=65. 5. Design a class named MyInteger. The class contains: • An int data field named value(int) Methods isEven() and respectively. Write a program that test methods in the class. isOdd() that return true if the value is even or odd.arrow_forwardCreate a class Rectangle. The class has attribute length and width, each of which defaults to 1. It has methods that calculate the perimeter and area of the rectangle. It has set and get methods for both length and width. The set method 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_forward
- Write a program that test methods in the class. • Hint: the employee deserved retirement if he has year of Service >25 or his age >=65. 5. Design a class named MyInteger. The class contains: • An int data field named value(int) ● Methods isEven() and respectively. Write a program that test isOdd() that return true if the value is even or odd. methods in the class.arrow_forwardIt has been realized that hackers have started hacking and changing the account detains of some banks, to stop this practice, you have been tasked to create a class called Abaaneke, your class should contain three variables (deposit, oldBalance, newBalace) all of type float and a variable of type String (name of the account holder) Your class should also have a method that takes three arguments – name of account holder, amount deposited and old balance. The method should add the deposit to the oldBalance and call it new balance. Using the right setters and getters, initialize the private variables and call the method to display the following in main a. Account holders name b. Amount deposited c. Old balance d. And new balancearrow_forwardWrite an equals method for the Car class given here. Two Cars are equal if their Vehicle Identification Numbers (VIN) are the same. HINT: The String class has an equals method that can be called from the Car class equals method.arrow_forward
- Write a class with a constructor that accepts a String object as its argument. The class should have a method that returns the number of b, c, d, f, g, h, and z in the string. Demonstrate the class in a program that asks the user to enter a string and returns the number of b, c, d, f, g, h, and z in the user string.arrow_forwardJAVA 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_forwardThe Hal9000 has one constructor which takes a String parameter of a name of the crew member it is interacting with. It has methods: public String getName() which gets the name public void setName(String newName) which sets a new name public String greet() which returns a string consisting of "Greetings, name" where name is the name supplied in the constructor. public String reportStatus() which returns a string consisting of "All systems are operating normally, name" where name is the name supplied in the constructor. public String execute(String command) which returns a string consisting of "I am sorry, name. I can't " + command where name is the name supplied in the constructor and command is the parameter. Supply Javadoc for the constructor and all the methodsarrow_forward
- Modify the Car class example and add the following: A default constructor that initializes strings to “N/A” and numbers to zero. An overloaded constructor that takes in initial values to set your fields (6 parameters). accel() method: a void method that takes a double variable as a parameter and increases the speed of the car by that amount. brake() method: a void method that sets the speed to zero. To test your class, you will need to instantiate at least two different Car objects in the main method in the CarDemo class. Each of your objects should use a different constructor. For the object that uses the default constructor, you will need to invoke the mutator methods to assign values to your fields. Invoke the displayFeatures() method for both objects and display the variables. Demonstrate the use of the accessor method getColor() by accessing the color of each car and printing it to the console. Use the method accel to increase the speed of the first car by 65 mph. Use…arrow_forwardThe Hal9000 has one constructor which takes a String parameter of a name of the crew member it is interacting with. It has methods: public String getName() which gets the name public void setName(String newName) which sets a new name public String greet() which returns a string consisting of "Greetings, name" where name is the name supplied in the constructor. public String reportStatus() which returns a string consisting of "All systems are operating normally, name" where name is the name supplied in the constructor. public String execute(String command) which returns a string consisting of "I am sorry, name. I can't " + command where name is the name supplied in the constructor and command is the parameter.arrow_forwardWrite Rectangle class to represent a rectangle. The class contains:a. Two double data fields named width and height that specify the width and height ofthe rectangle. The default values are 1 for both width and height.b. A no-arg constructor that creates a default rectangle.c. A constructor that creates a rectangle with the specified width and height.d. A method named getArea() that returns the area of this rectangle.e. A method named getPerimeter() that returns the perimeter. in Javaarrow_forward
- Microsoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,EBK JAVA PROGRAMMINGComputer ScienceISBN:9781305480537Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT