Concept explainers
Circle Class
Write a Circle class that has the following fields:
- radius: a double
- PI: a final double initialized with the value 3.14159
The class should have the following methods:
- Constructor. Accepts the radius of the circle as an argument.
- Constructor. A no-arg constructor that sets the radi us field to 0.0.
- setRadius. A mutator method for the radius field.
- GetRadius. An accessor method for the radius field.
- area. Returns the area of the circle, which is calculated as
area = PI * radius * radius
- diameter. Returns the diameter of the circle, which is calculated as
diameter = radius * 2
- circumference. Returns the circumference of the circle, which is calculated as
circumference = 2 * PI * radius
Write a
Learn your wayIncludes step-by-step video
Chapter 6 Solutions
Starting Out with Java: From Control Structures through Objects (7th Edition) (What's New in Computer Science)
Additional Engineering Textbook Solutions
Differential Equations: Computing and Modeling (5th Edition), Edwards, Penney & Calvis
Java: An Introduction to Problem Solving and Programming (8th Edition)
Problem Solving with C++ (10th Edition)
Starting out with Visual C# (4th Edition)
C How to Program (8th Edition)
C Programming Language
- Focus on classes, objects, methods and good programming style Your task is to create a BankAccount class(See the pic attached) The bank account will be protected by a 4-digit pin number (i.e. between 1000 and 9999). The pin should be generated randomly when the account object is created. The initial balance should be 0. get_pin()should return the pin. check_pin(pin) should check the argument against the saved pin and return True if it matches, False if it does not. deposit(amount) should receive the amount as the argument, add the amount to the account and return the new balance. withraw(amount) should check if the amount can be withdrawn (not more than is in the account), If so, remove the argument amount from the account and return the new balance if the transaction was successful. Return False if it was not. get_balance() should return the current balance. Finally, write a main() to demo your bank account class. Present a menu offering a few actions and perform the action the user…arrow_forwardin C# languageDesign a Book class that holds the title, author’s name, and price of the book. Books’s constructor shouldinitialize all of these data members except the price which is set to 500/-. Create a display method thatdisplays all fields.All Books are priced at 500/- unless they are PopularBooks. The PopularBooks subclass replaces theBookprice and sets each Book’s price to 50,000/- through PopularBooks construcor. Override the displaymethod to display all fields.Write a Main () method that declares an array of five Book objects. Ask the user to enter the title andauthor for each of the 5 Books. Consider the Book to be a PopularBook if the author is one of the following:Khaled Hosseini, Oscar Wilde, or Rembrandt. Display the five Books’ details.arrow_forwardTemp Class - Create Temp class whos job is to hold a temp in degrees F and gives methods to get the temp in F, Celsius, and Kelvin. The class should follow the instance variable (field): ftemp (double type that holds F temp)Follow these methods with the class.. Constructor --Will accept Fahrenheit temperature as a double to store it in the ftemp field. setFahrenheit - The setFahrenheit method accepts a Ftemperature as a doubleto stores it in the ftemp field. getFahrenheit - Returns the value of the ftemp field, as a Fahrenheit temperature (no conversion required). getCelsius - Returns the value of the ftemp field converted to Celsius. [C e l s i u s = ( 5.0 / 9.0 ) × ( F a h r e n h e i t − 32 )] getKelvin - Returns the value of the ftemp field converted to Kelvin. [K e l v i n = ( ( 5.0 / 9.0 ) × ( F a h r e n h e i t − 32 ) ) + 273] Exemplify the temp class by writing a (test) program that is separate and promotes users for an F Fahrenheit temp. The program must create an…arrow_forward
- 2. Car Class Write a class named car that has the following fields: ▪ yearModel. The year Model field is an int that holds the car's year model. ▪ make. The make field is a String object that holds the make of the car, such as "Ford", "Chevrolet", "Honda", etc. ▪ speed. The speed field is an int that holds the car's current speed. In addition, the class should have the following methods. ■ Constructor. The constructor should accept the car's year model and make as arguments. These values should be assigned to the object's year Model and make fields. The constructor should also assign 0 to the speed field.arrow_forwardQuestionarrow_forwardINVENTORY CLASS You need to create an Inventory class containing the private data fields, as well as the methods for the Inventory class (object). Be sure your Inventory class defines the private data fields, at least one constructor, accessor and mutator methods, method overloading (to handle the data coming into the Inventory class as either a String and/or int/float), as well as all of the methods (methods to calculate) to manipulate the Inventory class (object). The data fields in the Inventory class include the inventory product number (int), inventory product description (String), inventory product price (float), inventory quantity on hand (int), inventory quantity on order (int), and inventory quantity sold (int). The Inventory class (java file) should also contain all of the static data fields, as well as static methods to handle the logic in counting all of the objects processed (counter), as well as totals (accumulators) for the total product inventory and the total product…arrow_forward
- Design a Ship class that the following members: A field for the name of the ship (a string). A field for the year that the ship was built (a string). A constructor and appropriate accessors and mutators. 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 field for the maximum number of passengers (an int). A constructor and appropriate accessors and mutators. 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 maximum number of passengers. Design a CargoShip class that extends the Ship class. The CargoShip class should have the following members: A field for the cargo capacity in tonnage (an int). A constructor and appropriate accessors and mutators. A toString method that overrides the toString method in the base class. The…arrow_forwardpackage assignment; public class Circle2D2 { //data fields specifying the center of the circle private double x, y; //data field radius private double radius; //default circle with (0, 0) for (x, y) and 1 for radius Circle2D2() { this(0, 0, 1); } //circle with the specified x, y, and radius Circle2D2(double x, double y, double radius) { this.x = x; this.y = y; this.radius = radius; } //return x public double getX() { return x; } //return y public double getY() { return y; } //return radius public double getRadius() { return radius; } //return the area of the circle public double getArea() { return Math.PI * Math.pow(radius, 2); } //return the perimeter of the circle public double getPerimeter() { return 2 * Math.PI * radius; } //return true if the specified point (x, y) is inside this circle public boolean contains(double x, double y) { return Math.sqrt(Math.pow(x - this.x, 2) + Math.pow(y - this.y, 2)) < radius; } //return true if…arrow_forwardPet ClassDesign a class named Pet, which should have the following fields: name: The name field holds the name of a pet. type: The type field holds the type of animal that a pet is. Example values are "Dog", "Cat", and "Bird". age: The age field holds the pet’s age. The Pet class should also have the following methods: setName: The setName method stores a value in the name setType: The setType method stores a value in the type setAge: The setAge method stores a value in the age getName: The getName method returns the value of the name getType: The getType method returns the value of the type getAge: The getAge method returns the value of the age Once you have designed the class, design a program that creates an object of the class and prompts the user to enter the name, type, and age of his or her pet. This data should be stored in the object. Use the object’s accessor methods to retrieve the pet’s name, type, and age and display this data on the screen. *** I need help…arrow_forward
- Pet ClassDesign a class named Pet, which should have the following fields: name: The name field holds the name of a pet. type: The type field holds the type of animal that a pet is. Example values are "Dog", "Cat", and "Bird". age: The age field holds the pet’s age. The Pet class should also have the following methods: setName: The setName method stores a value in the name setType: The setType method stores a value in the type setAge: The setAge method stores a value in the age getName: The getName method returns the value of the name getType: The getType method returns the value of the type getAge: The getAge method returns the value of the age Once you have designed the class, design a program that creates an object of the class and prompts the user to enter the name, type, and age of his or her pet. This data should be stored in the object. Use the object’s accessor methods to retrieve the pet’s name, type, and age and display this data on the screen. The output Should be…arrow_forwardA field has access that is somewhere between public and private. static final Opackage Oprotectedarrow_forwardTrue/False: When instantiating an object of an abstract class, you can do it with the keyword new.arrow_forward
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,