Java Programming (MindTap Course List)
9th Edition
ISBN: 9781337397070
Author: Joyce Farrell
Publisher: Cengage Learning
expand_more
expand_more
format_list_bulleted
Question
Chapter 3, Problem 3PE
Program Plan Intro
Object:
- The objects are instance of class.
- In java, the fields are the members of a class. The object can contain the methods and data items of a class.
- The object should be allocated a memory. To allocate memory to an object, the user must use “new()”.
- Syntax of declaring an object,
classname objectname = new classname();
- The object of one class can access the methods and variables of another class declare as public.
- The members of the class are accessed as,
objectname.member;
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Write a class named Employee that has the following fields:
name: The name field is a String object that holds the employee's name.
idNumber: The idNumber is an integer variable that holds the employee's ID
number.
department: The department field is a String object that holds the name of the
department where the employee works.
position: The position field is a String object that holds the employee's job title.
Write mutator methods that store values in these fields and accessor methods that return
the values in these fields. Once you have written the class, write a separate program that
creates three Employee objects to hold the following data.
Name
ID Number
Azah Samsudin
Mira Kamal
Che Yah Sam
Department
Computer Science
Biomedical
Language
Position
Programmer
Researcher
Lecturer
11011
35125
80001
The program should store the data in the three objects and then display the data for each
employee on the screen.
Question
Create a class called Quadratic for performing arithmetic on and solving quadratic equations. A quadratic equation is an equation of the form
ax2 + bx + c = 0
Where a !=0. Use double variables to represent the values of a, b, and c and provide a constructor that enables objects of this class to be initialized when they are created. Give default values of a = 1, b = 0, and c = 0. Create a char variable called variable to represent the variable used in the equation and give it a default value of x. The constructor should not allow the value of a to be 0. If 0 is given, assign 1 to a). Provide public member functions that perform the following tasks.
add—adds two Quadratic equations by adding the corresponding values of a, b, and c.
The function takes another object of type Quadratic as its parameter and adds it to the calling object.
subtract—subtracts two Quadratic equations by subtracting corresponding values of a, b, and…
IN C++
Write a class named Employee that has the following member variables:
name. A string that holds the employee’s name.
idNumber. An int variable that holds the employee’s ID number.
department. A string that holds the name of the department where the employee works.
position. A string that holds the employee’s job title.
The class should have the following constructors:
A constructor that accepts the following values as arguments and assigns them to the appropriate member variables: employee’s name ( non-empty) , employee’s ID number( neither 0 nor negative numbers), department ( non-empty), and position ( non-empty).
Write appropriate setter functions that store values in these member variables and getter functions that return the values in these member variables.
Once you have written the class, write a main program that creates FOUR Employee objects to hold the above data.
The program should store this data in the four objects and then display the data in tabular form for…
Chapter 3 Solutions
Java Programming (MindTap Course List)
Ch. 3 - Prob. 1RQCh. 3 - Prob. 2RQCh. 3 - Prob. 3RQCh. 3 - Prob. 4RQCh. 3 - Prob. 5RQCh. 3 - Prob. 6RQCh. 3 - Prob. 7RQCh. 3 - Prob. 8RQCh. 3 - Prob. 9RQCh. 3 - Prob. 10RQ
Ch. 3 - Prob. 11RQCh. 3 - Prob. 12RQCh. 3 - Prob. 13RQCh. 3 - Prob. 14RQCh. 3 - Prob. 15RQCh. 3 - Prob. 16RQCh. 3 - Prob. 17RQCh. 3 - Prob. 18RQCh. 3 - Prob. 19RQCh. 3 - Prob. 20RQCh. 3 - Prob. 1PECh. 3 - Prob. 2PECh. 3 - Prob. 3PECh. 3 - Prob. 4PECh. 3 - Prob. 5PECh. 3 - Prob. 6PECh. 3 - Prob. 7PECh. 3 - Prob. 8PECh. 3 - Prob. 9PECh. 3 - Prob. 10PECh. 3 - Prob. 11PECh. 3 - Prob. 12PECh. 3 - Prob. 13PECh. 3 - Prob. 1GZCh. 3 - Prob. 2GZCh. 3 - Prob. 1CP
Knowledge Booster
Similar questions
- Write a program named SalespersonDemo that instantiates objects using classes named Real EstateSalesperson and GirlScout. Demonstrate that each object can use a SalesSpeech() method appropriately. Also, use a MakeSale() method two or three times with each object, and display the final contents of each objects data fields. First, create an abstract class named Salesperson. Fields include first and last names; the Salesperson constructor requires both these values. Include properties for the fields. Include a method that returns a string that holds the Salespersons full name—the first and last names separated by a space. Then perform the following Create two child classes of Salesperson: Real EstateSalesperson and Girl Scout. The Real EstateSalesperson class contains fields for total value sold in dollars and total commission earned (both of which are initialized to 0), and a commission rate field required by the class constructor. The Girl Scout class includes a field to hold the number of boxes of cookies sold, which is initialized to 0. Include properties for every field. Create an interface named ISell able that contains two methods: SalesSpeech() and MakeSale(). In each Real EstateSalesperson and Girl Scout class, implement SalesSpeech() to display an appropriate one- or two-sentence sales speech that the objects of the class could use. In the Real Estatesalesperson class, implement the MakeSale() method to accept an integer dollar value for a house, add the value to the Real EstateSalespersons total value sold, and compute the total commission earned. In the Girl Scout class, implement the MakeSale() method to accept an integer representing the number of boxes of cookies sold and add it to the total field.arrow_forwardDesign a Ship class that has the following members:a. A field for the name of the ship (a string).b. A field for the year that the ship was built (a string).c. A constructor and appropriate accessors and mutators.d. A toString method that displays the ship's name and the year it was built.Design a CruiseShip class that extends the Ship class. The CruiseShip class should have the following members:a. A field for the maximum number of passengers (an int).b. A constructor and appropriate accessors and mutators.c. A toString method that overrides the toString method in the base class. The CruiseShip class's toString method should display only the ship's name and the maximumnumber of passengers.Design a CargoShip class that extends the Ship class. The CargoShip class should have the following members:a. A field for the cargo capacity in tonnage (an int).b. A constructor and appropriate accessors and mutators.c. A toString method that overrides the toString method in the base class. The…arrow_forwardWhich of the statements are true about the class Magazine? 01: class Magazine { 02: public: 03: Magazine (int maxSize = 100); 04: void add (Article a); 05: int numArticles() const; 06: Article getArticle (int i); 07: private: 08: Article* array; 09: int numberOfArticles; 10: }; The compiler will provide a destructor for this class. It has a default constructor It is const-correct. It has a copy constructor The programmer should provide an assignment operatorarrow_forward
- Using pythonarrow_forwardCreate a class called Rational to be able to perform arithmetic operations with fractions. testing your class and Write a program that presents a menu to the user to perform the desired action. User enters -1 value You can trade as much as you want. Use integer variables to represent the private data members (numerator and denominator) of the class. to this class Write a constructor function that initializes an object of the property as soon as it is declared. Constructive the function must contain default values for cases where no initial values are given and use the fractional number should store it in reduced form (i.e. the fraction 2/4 should be reduced to 1 for the numerator and 2 for the denominator). Provide public member functions for each of the following: ‐ The sum of two fractions - Subtraction of two fractions ‐ Multiplication of two fractions ‐ The division of two fractions In all of the above functions, results must be stored in a reduced form. Also, write the…arrow_forwardIn Javascript, Pet Class: Design a class named Pet, which should have the following fields and methods: name: The name of a pet type: The type of animal the pet is ("Dog", "Cat", "Lizard", etc.) age: The age of the pet. setName: The setter for the name field. getName: The getter for the name field. setType: The setter for the type field. getType: The getter for the type field. setAge: The setter for the age field. getAge: The getter for the age field. Once you have designed the class, create an instance of the class and use the setter and getter methods to store data in the object and display the data.arrow_forward
- When passing an object type as parameter, changing formal parameter __ change actual parameter a. will b. will notarrow_forwardDesign a class called Date that has integer data members to store month , day, and year. The class should have two constructors; a default constructor that accepts no parameters, and a three-parameter constructor that allows the date to be set by the programmer. If the user creates a Date object without passing any arguments, or if any of the values passed are invalid, the default values of 1, 1, 2001 (i.e., January 1, 2001) should be used. The class should have three (3) member functions to print the date in the following formats: 3/15/16 March 15, 2016 15 March 2016 Demonstrate the class by writing a program that uses it. Be sure your program only accepts reasonable values for month and day. The month should be between 1 and 12. The day should be between 1 and the number of days in the selected month. I expect to see all uses of the constructors that you made, including the error checking. I also expect to see all uses of the 3 output functions in your program. You are responsible…arrow_forwardWrite a class named Aircraft that has the following member variables: xear - An variable that holds the aircraft's model year. make - A string object that holds the make of the aircraft Qwuer: A string object that holds the type of owner of the aircraft. speed - An int that holds the aircraft's current speed. altitude, An int that holds the aircraft's current altitude. engine type- a String value to hold the type of the engine the aircraft has In addition, the class should have the following member functions. Constructor - The constructor should accept the aircraft's owner and make arguments and assign these values to the object's owner and make member variables. The constructor should initialize the speed variable to 0 and the altitude variable to 0. Accessors - Appropriate accessor functions should be created to allow values to be retrieved from an object's year, make, owner, altitude, and speed member variables. Mutator - Appropriate mutator function should be created to allow the…arrow_forward
- Create a class named Employee. The class must contain private member variables: name and salary. It should contain getter methods for returning the name and salary. It should also contain setter methods for setting the name and salary. The class must include a constructor, the constructor must be designed to set both the name and the salary. In addition, the Employee class must contain a toString() method that prints both name and salary. Create a class named Test. The class must contain the mainmethod. In the main method, you should create three objects fromclass Employee and store them in an array of type Employee (youmust prompt the user to enter name and salary for each object).Then, you should print the name and salary of each object (usingeither the getters or the toStrong() method). DO NOT COPY CHEGGarrow_forwardThere are two objects-$product1 = new Shop();$product2 = new Shop();Which one of the following statements is right about them?a) $product1 and $product2 are same objects of the same type generated from a single classb) $product1 and $product2 are different objects of the same type generated from a single classc) $product1 and $product2 are same objects of the different type generated from a single classd) $product1 and $product2 are different objects of the different type generated from a single classarrow_forward1. Part 1: A point in the x-y plane is represented by its x-coordinate and y-coordinate. Design the class Point that can store and process a point in the x-y plane. Your class should contains the following methods. Default constructor without parameters that initializes the private data member to the suitable values Constructor with parameters sets the values of the instance variables to the values of the parameter. Accessor methods that return the values of the x-axis and y-axis. setPoint method which set the values of x-axis and y-axis makeCopy method that make a copy of a received object of type Point. getCopy method that returns a copy of the current object toString method that returns the object string isEqual that returns true if the current object is equal to the received object of type point distance, which receives two objects of type Point and returns the distancearrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Programming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:CengageEBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,