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
Web Development and Design Foundations with HTML5 (8th Edition)
Elementary Surveying: An Introduction To Geomatics (15th Edition)
Starting Out with Programming Logic and Design (5th Edition) (What's New in Computer Science)
SURVEY OF OPERATING SYSTEMS
Starting Out With Visual Basic (8th Edition)
Degarmo's Materials And Processes In Manufacturing
- 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
- 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_forwardPART B: Create two linkedBag objects of type string in main. Place 5 strings in the first bag and five strings in the second bag. Then your code must test if the two linkedBag objects are equal or not. You must traverse both linkedBags and test each items to see if they are the same. Then you must display a message saying the two linkedBags are the same or different. PART C: Write a method in the class that gets an item of type T and finds out how many of the items in the linkedBag are bigger than that item. Return that count.arrow_forwardFor the following class: 1. write a toString method to return a String that represents the information stored in a Person object including name, lastName, and age. //2 points 2. write an equals(Object obj) to return false if the passed object is null or not a Person. The method equal returns false, if one of name, lastName, and age of the object which it is applied to is not equal to name, lastName, and age of the object that is passed as argument. Otherwise, the method returns true. //3 points public class Person { private String name; private String lastName; private int age; public Person (String name, String lastName, int age) { this.name = name; this.lastName = lastName; this.age age; }arrow_forward
- FOR JAVA Create a class named Product that has ID, price and stock as fields. This class must have two constructors; one constructor must take all its fields as parameters, second constructor must take ID and price as parameters and set stock to 0. Also implement the following methods: • String toString(): Returns a brief summary about the object. • void sell(int): Takes a parameter that represents the amount to sell. Checks if stocks are sufficient. If so, it updates the stock and prints the total price. Else it prints a warning to user. Create 3 instances of Product class and test your methods.arrow_forwardIn Java, Use the Phone class as a baseline, and write a method isUSA. It should return true if the country code is 1 and false otherwise. Also expanding the Phone class, write a method that determines the location of an area code. It should return the name of the area code's city. For example, if cc = 1 and area code = 510 East Bay Area, 650 SF Peninsula, 415 San Francisco, 408 South Bay Area. For this assignment, use literal strings as return values.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
- create 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_forwardanswer should be in java with a easy methodarrow_forwardin JAVA Assume that a receipt id contains characters that represent information or that can be used as a code to determine something about the purchase. For example: if an id has an 'x' followed by two 'y's, it means that the purchase was a final sale and cannot be returned. Or if an id has an 'a' followed by three 'b's, it means that a coupon was used for purchase. Write a static method for the Receipt class to test whether a receipt id meets such a criteria. Does the id meet the criteria? The criteria is described by three pieces of data, passed in as parameters: char firstTarget char second Target int countOfSecond After First A receipt id meets the criteria if: the id contains the first target character and the second target character appears exactly the specified number of times after the first target character appears Note: the first and second char could be the same char! Carefully review the provided driver program for examples of ids that meet and don't meet criteria. For full…arrow_forward
- Microsoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,EBK JAVA PROGRAMMINGComputer ScienceISBN:9781305480537Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT