A complex number has two parts: real value and imaginary value. In mathematics, we learnt how to add and multiply two complex numbers. Write a class Complex which will have two fields for real and imaginary values. The constructor will set the values in these fields (there could be multiple overloaded constructors). The class should also have method like this: Complex add (Complex c) This add() method takes a complex object and return a new complex object after adding the complex number c with itself(Use general complex number addition rule).

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

A complex number has two parts: real value and imaginary value. In mathematics, we
learnt how to add and multiply two complex numbers. Write a class Complex which will
have two fields for real and imaginary values. The constructor will set the values in these
fields (there could be multiple overloaded constructors). The class should also have
method like this:
Complex add (Complex c)
This add() method takes a complex object and return a new complex object after adding
the complex number c with itself(Use general complex number addition rule). 

6.
Which of the below code contains correct overloading code? Why would the other won't
work?
Code 1
double myMultiply. (int x){
return 10 x;
Code 2
int awMultielx (int x){
return 10 x;
}
double yMultirly. (double x){ double yMultiely (int x){
return 20 x;
return 2e * x;
7.
What would be the output for the following program and why ( explain in short):
Bublis static void nain(String acsal))(
String.";
String si - "Testing Java Program
String s2 - sukstriui13);
8.
Write the code in Java for the following class from the UML diagram below:
Vehicle
-passengers: int
-maxSpeed: double
-color: String
+Vehiclelint,double.String)
+setColor(): void
+getColor(): String
+findCaracityl): double
The findCapacityl) method return the capacity of the vehicle by the following formula:
Capacity = passengers * 75 L0.20 * maxSpeed)
Transcribed Image Text:6. Which of the below code contains correct overloading code? Why would the other won't work? Code 1 double myMultiply. (int x){ return 10 x; Code 2 int awMultielx (int x){ return 10 x; } double yMultirly. (double x){ double yMultiely (int x){ return 20 x; return 2e * x; 7. What would be the output for the following program and why ( explain in short): Bublis static void nain(String acsal))( String."; String si - "Testing Java Program String s2 - sukstriui13); 8. Write the code in Java for the following class from the UML diagram below: Vehicle -passengers: int -maxSpeed: double -color: String +Vehiclelint,double.String) +setColor(): void +getColor(): String +findCaracityl): double The findCapacityl) method return the capacity of the vehicle by the following formula: Capacity = passengers * 75 L0.20 * maxSpeed)
Write a class 'Box' which has three private members height, width and depth; To set values
and use these members, write mutator(setter) and accessor(getter) functions for these
members. (Hint: there would be 3 Accessor and 3 Mutator functions). Also write a
constructor function that takes 3 parameters to initialize these fileld members.
9.
10. Write a class for 'LabRoom'; it will have member fields for no of chairs, no of tables, no of
computers. The class should also contain methods to add or remove these elements: the
amount to be added or removed should be given as parameter. There should be 2
overloaded add methods: one taking 3 parameters and the other taking no parameters
(write the body of the methods as per your wish). Now, Create 2 LabRoom objects with
arbitrary values and call and use the add() and remove() methods.
11. A complex number has two parts: real value and imaginary value. In mathematics, we learnt
how to add and multiply two complex numbers. Write a class Complex which will have two
fields for real and imaginary values. The constructor will set the values in these fields (there
could be multiple overloaded constructors). The class should also have method like this:
Complex add (Complex c)
This add() method takes a complex object and return a new complex object after adding the
complex number c with itself(Use general complex number addition rule).
12. Suppose a String name is given in a format where the firstname and lastname are separated
by a semicolon like 'Zigul;Hossain' ; the general format would be 'firstname;lastname
(firstname and lastname can be any String). Write a program which will separate the
lastname into a different string. (Hint: use a function from String class to find the positionte V
of semicolon and then take substring from that position).
Go to Setting
Transcribed Image Text:Write a class 'Box' which has three private members height, width and depth; To set values and use these members, write mutator(setter) and accessor(getter) functions for these members. (Hint: there would be 3 Accessor and 3 Mutator functions). Also write a constructor function that takes 3 parameters to initialize these fileld members. 9. 10. Write a class for 'LabRoom'; it will have member fields for no of chairs, no of tables, no of computers. The class should also contain methods to add or remove these elements: the amount to be added or removed should be given as parameter. There should be 2 overloaded add methods: one taking 3 parameters and the other taking no parameters (write the body of the methods as per your wish). Now, Create 2 LabRoom objects with arbitrary values and call and use the add() and remove() methods. 11. A complex number has two parts: real value and imaginary value. In mathematics, we learnt how to add and multiply two complex numbers. Write a class Complex which will have two fields for real and imaginary values. The constructor will set the values in these fields (there could be multiple overloaded constructors). The class should also have method like this: Complex add (Complex c) This add() method takes a complex object and return a new complex object after adding the complex number c with itself(Use general complex number addition rule). 12. Suppose a String name is given in a format where the firstname and lastname are separated by a semicolon like 'Zigul;Hossain' ; the general format would be 'firstname;lastname (firstname and lastname can be any String). Write a program which will separate the lastname into a different string. (Hint: use a function from String class to find the positionte V of semicolon and then take substring from that position). Go to Setting
Expert Solution
steps

Step by step

Solved in 4 steps with 3 images

Blurred answer
Knowledge Booster
Developing computer interface
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education