RECTANGLE DIMENSION CHANGE - INSTANCEOF OPERATOR
[Note :
Strictly adhere to the object-oriented specifications given as a part of the problem statement.
Follow the naming conventions as mentioned. Create separate classes in separate files.]
Consider a class Rectangle with the following private member variables/attributes.
Data Type | Variable |
Integer | length |
Integer | width |
Include appropriate getters and setters.
Prototype for the Parameterized Constructor,
public Rectangle(Integer length, Integer width)
The Rectangle class includes the following methods.
Consider the class Main and write a main() method to test the above class.
In the main( ) method,
- Display the area of the rectangle inside the main() method.
- Obtain the details of the user.
- Create an object for the Rectangle class using the parameterized constructor(length, width).
Problem Constraints:
Use instanceof operator to check the object returned by dimensionChange( ) method.
[The java instanceof operator is used to test whether the object is an instance of the specified type (class or subclass or interface).]
The link to download the template code is given below
Code Template
Input and Output Format:
Refer sample input and output for formatting specifications.
[All text in bold corresponds to input and the rest corresponds to output.]
Sample Input and Output :
Enter the length of the rectangle
5
Enter the width of the rectangle
6
Rectangle Dimension
Length:5
Width:6
Area of the Rectangle:30
Enter the new dimension
2
Rectangle Dimension
Length:10
Width:12
Area of the Rectangle:120
Problem Requirements:
Java
Keyword | Min Count | Max Count |
instanceof | 1 | - |
Display Item Type
Write a Java program to get item type, cost per day, and deposit amount from the user and display these details in a detailed view using the following classes and methods.
Follow the naming conventions as mentioned. Create separate classes in separate files.]
Consider a class named ItemType.
It must have the following private member variables/attributes.
Data Type | Variable |
String | name |
Double | costPerDay |
Double | deposit |
Include the appropriate getters and setters.
The ItemType class includes the following method.
Description
followed by the details of the ItemType in the
format as shown in the sample output.
Consider the class Main. It includes the method main
Write a code in the main method to test the ItemType class.
The following must be done inside the main method to test the ItemType class.
- Get the item type details as input.
- Create an ItemType Object with the given details using the setters of ItemType and call the display( ) method.
- The itemType details need to be displayed in the display() method
Please use the below sample convention to create getters and setters of the class ItemType
private String name;
public String getName( ) {
return name;
}
public void setName(String name) {
this.name = name;
}
Input and Output Format:
Refer sample input and output for formatting specifications.
Note:
Cost per day and Deposit value should be displayed up to 2 decimal places.
[All text in bold corresponds to input and the rest corresponds to output.]
Sample Input and Output 1:
Enter the item type name
Catering
Enter the cost per day
25000.00
Enter the deposit
10000.50
Item type details
Name : Catering
CostPerDay : 25000.00
Deposit : 10000.50
Constructors are member functions that are called when an object is created.
Write a program to get the customer details, assign the values to the object using constructors and display it.
[Note: Strictly adhere to the object-oriented specifications given as a part of the problem statement.
Follow the naming conventions as mentioned. Create separate classes in separate files.]
Consider a class named Customer with the following public member variables
Data Type | Variable Name |
---|---|
String | customerName |
String | customerEmail |
String | customerType |
String | customerAddress |
Include default and parameterized for the above class
Prototype for the parameterized constructor,
Customer(String customerName, String customerEmail, String customerType, String customerAddress)
Include the following method in the Customer class
Method Name | Description |
void displayDetails() | To display the details of the customer in the given format. |
Consider the Main class to include the main() method.
In the Main method
- Obtain the details of the customer.
- Create an object for Customer class using parameterized constructor(customerName, customerEmail, customerType, customerAddress)
- Call the method displayDetails() in the Main class.
The link to download the template code is given below
Code Template
Input and Output Format:
Refer sample input and output for formatting specifications.
[All text in bold corresponds to input and the rest corresponds to the output]
Sample Input and Output 1:
Enter the Customer Details
Enter the name
Rose
Enter the email
rose@mail.com
Enter the type
Domestic
Enter the location
India
Name: Rose
E-mail: rose@mail.com
Type: Domestic
Location: India
Sample Input and Output 2:
Enter the Customer Details
Enter the name
Kate
Enter the email
kate@a.com
Enter the type
Domestic
Enter the location
Australia
Name: Kate
E-mail: kate@a.com
Type: Domestic
Location: Australia