EBK JAVA PROGRAMMING
9th Edition
ISBN: 9781337671385
Author: FARRELL
Publisher: CENGAGE LEARNING - CONSIGNMENT
expand_more
expand_more
format_list_bulleted
Question
Chapter 4, Problem 6PE
Program Plan Intro
Calculate the area and diameter of Circle
Program plan:
Filename: “Circle.java”
- Define the “Cirle” class
- Declare the required variables.
- Define constructor
- Set the radius value as 1.
- Call the “calc” method.
- Define the “setRadius” method
- Set the value
- Call the “calc” method
- Define the “getRadius” method
- Return the radius
- Define the “getDiameter” method
- Return the diameter
- Define the “getArea” method
- Return the area
- Define the “calc” method
- Calculate the diameter of the circle
- Calculate the area of the circle.
Filename: “TestCircle.java”
- Define the “TestCircle” class
- Define the main method.
- Create the objects for “Circle” class
- Call the “setRadius” method with different values
- Call the “display” method
- Define the “display” method
- Display the radius, diameter, and area of the circle.
- Define the main method.
Expert Solution & Answer
Trending nowThis is a popular solution!
Students have asked these similar questions
0o.Absolutely answer please
Write a program that calculates the average of courses, overall grade, and letter grade. Suppose that your students take four courses - English, Mathematics, Science, and History. You should design a class that accepts all four course's numeric scores, calculates average and overall grade, and decides letter grade based on the overall grade. Your class should have a constructor, get and set methods of each course, a method that calculates the average of four courses, a method that calculates overall grade, and a method that decides letter grade. The overall grades are calculated as the following rate:
Average of All four courses: 50%
Quiz: 40%
Attendance: 10%
The letter grade is based on the following:
90.0 to 100.0 - A
80.0 to 89.9 - B
70.0 to 79.9 - C
65.0 to 69.9 - D
less than 65 - F
Your program demonstrates the class by asking the user to input four-course numeric scores, creating an object, and then reporting each course's score, average, overall…
Instructions
This assignment must follow directions exactly. Create a class Lab02 with a main method, and put all of the following code into the main method:
Print the prompt shown below and ask the user for the number of exemptions.
The number of exemptions is an integer.
Print the prompt shown below and ask the user for their gross salary.
The gross salary represents dollars, which can be entered with or without decimal points.
Print the prompt shown below and ask the user for their interest income.
The interest income represents dollars, which can be entered with or without decimal points.
Print the prompt shown below and ask the user for their capital gains income.
The capital gains represents dollars, which can be entered with or without decimal points.
Print the prompt shown below and ask the user for the amount of charitable contributions.
The charitable contributions represents dollars, which can be entered with or without decimal points.
Perform the calculation of…
Create a class called Point which will have 2 co-ordinate value x & y and will be able to calculate the distance between two points. Write appropriate constructor and method of the class. Create another class called Shape, which takes different number of points to create a triangle, rectangle and circle. And also able to calculate the area and perimeter for the different shapes. Write the appropriate overloading method for this shape class. Write appropriate main function to test the shape class.
Chapter 4 Solutions
EBK JAVA PROGRAMMING
Ch. 4 - Prob. 1RQCh. 4 - Prob. 2RQCh. 4 - Prob. 3RQCh. 4 - Prob. 4RQCh. 4 - Prob. 5RQCh. 4 - Prob. 6RQCh. 4 - Prob. 7RQCh. 4 - Prob. 8RQCh. 4 - Prob. 9RQCh. 4 - Prob. 10RQ
Ch. 4 - Prob. 11RQCh. 4 - Prob. 12RQCh. 4 - Prob. 13RQCh. 4 - Prob. 14RQCh. 4 - Prob. 15RQCh. 4 - Prob. 16RQCh. 4 - Prob. 17RQCh. 4 - Prob. 18RQCh. 4 - Prob. 19RQCh. 4 - Prob. 20RQCh. 4 - Prob. 1PECh. 4 - Prob. 2PECh. 4 - Prob. 3PECh. 4 - Prob. 4PECh. 4 - Prob. 5PECh. 4 - Prob. 6PECh. 4 - Prob. 7PECh. 4 - Prob. 8PECh. 4 - Prob. 9PECh. 4 - Prob. 10PECh. 4 - Prob. 11PECh. 4 - Prob. 1GZCh. 4 - Prob. 2GZ
Knowledge Booster
Similar questions
- Thanks in advance. Modify a class named Circle with fields named radius, diameter, and area. Include a constructor that sets the radius to 1 and calculates the other two values. Also include methods named setRadius() and getRadius(). The setRadius() method not only sets the radius, but it also calculates the other two values. (The diameter of a circle is twice the radius, and the area of a circle is pi multiplied by the square of the radius. Use the Math class PI constant for this calculation.) class Circle {private double radius;private double area;private double diameter;Circle() {}public void setRadius(double r) {}public double getRadius() {}private void computeDiameter() {}private void computeArea() {}public double getDiameter() {}public double getArea() {}} class TestCircle {public static void main (String args[]) {Circle a = new Circle();Circle b = new Circle();Circle c = new Circle(); a.setRadius(1.5);b.setRadius(1500.50); System.out.println("The area of a is "…arrow_forwardConstruct a class named Circle with attributes named radius, diameter and area. Include a constructor that sets the radius to 1 and calculates the other two values. Include get and set methods for all the attributes. The setRadius(0 method not only sets the radius, it also calculates the other two values. The diameter of a circle is twice the radius and the area of a circle is pi multiplied by the square of the radius. Use the Math class PI constant for this calculation.arrow_forwardJava programarrow_forward
- Create a Class Pet with the following data members Identification: String species : String (e.g. cat, dog, fish etc) breed: String Age (in days): int Weight: float Dead: boolean 1. Provide a constructor with parameters for all instance variables. 2. Provide getters for all and setters for only breed, and weight 3. Provide a method growOld() that increases the age of the pet by one day. A dead pet wont grow old 4. Provide a method growHealthy(float w) that increases the weight of the pet by the given amount w. A dead pet cannot grow healthy. 5. Provide a method fallSick(float w) that reduces the weight of the pet by the given amount. The least weight a pet can have is 0 which will mean that the pet has died. If the value of weigh is 10 kg and the method is called with an argument of 11 kg then you will set it to 0 and set the dead to an appropriate value to mark the death of the pet 6. Provide a toString method that shows an appropriate well formatted string…arrow_forwardSlide Type Slide • Exercise # 1: Define a class Point that represents a point in 2 – D plane. The point has x and y coordinates. Define the following: • A constructor to initialize the x, y coordinates. • A method translate(self, dx,dy) to translate the point object dx , and dy units in x and y directions, respectively. • A method distanceTo (self, point2) to return the distance between the point referenced by self and point2. • getX(self) to return the value of x coordinate. • getY(self) to return the value of y coordinate Test the above class by: • Creating 2 point objects; one with (3,5) as x,y coordinates; the second with (-10,30) as x,y coordinates. • Move the first point 5.5 units in x direction and -12.5 units in y direction using translate method • Find the distance between the 2 points in their current location using distance To method A Sample output resulting from running the above test class is shown below new coordinates of point1= (8.5 , -7.5) Coordinates of point 2 =…arrow_forwardClass RightTriangle Represents a right triangle by the length of each of its two legs Includes the default and overloaded constructor, methods to set the length of each of the two legs, amethod to get the area, a method to scale the size of the triangle, a method to invert the triangle(swap the lengths of its two legs), and a method to print its dimensions.Class TestRightTriangle Creates and initializes two triangles. Calls the various associated methods to set its size, compute its area, scale its size, invert, and print itsdimensions.You are required to implement both classes according to the requirements specified in the commentsdisplayed in the .java files. The following is an example of possible output:triangle1 dimensions: 6.0 3.5triangle1 area: 10.5triangle2 dimensions: 3.0 4.0triangle2 area: 6.0triangle1 dimensions: 18.0 10.5triangle2 dimensions: 5.5 6.5triangle1 dimensions: 4.5 2.625triangle1 dimensions after invert: 2.625 4.5A few details: Do NOT modify any of the code…arrow_forward
- Construct a class named Circle with attributes named radius, diameter and area. Include a constructor that sets the radius to 1 and calculates the other two values. Include get and set methods for all the attributes. The setRadius() method not only sets the radius, it also calculates the other two values. The diameter of a circle is twice the radius and the area of a circle is pi multiplied by the square of the radius. Use the Math class PI constant for this calculation.arrow_forwardApologize for the miscommunication, The language is in Python Create a simple empty Vehicle class. Update the Vehicle class with two instance variables maximum speed and mileage of the car. Create a class variable of the manufacturer and initialize all class and instance variables. different objects among them two are from one manufacturer and the remaining two are from another manufacturer. Write two methods in the class Vehicle, one for displaying the seating capacity of the vehicle and another one is for calculating fuel used by the car by the equation: Maximum Distance Covered / Mileage of the car. and Display the result from the method. Create two children from the Vehicle class: Bus and Car. Both the child classes will inherit all the variables and methods of the Vehicle class. The car class will modify the members of the parent class in their own way and display it from its class object. Bus will be inherited to another class called MiniBus. Create a new method in…arrow_forwarduse java to answerand Thank youarrow_forward
- JAVAWrite a program that calculates the average of courses, overall grade, and letter grade. Suppose that your students take four courses - English, Mathematics, Science, and History. You should design a class that accepts all four course's numeric scores, calculates average and overall grade, and decides letter grade based on the overall grade. Your class should have a constructor, get and set methods of each course, a method that calculates the average of four courses, a method that calculates overall grade, and a method that decides letter grade. The overall grades are calculated as the following rate: Average of All four courses: 50% Quiz: 40% Attendance: 10% The letter grade is based on the following: 90.0 to 100.0 - A 80.0 to 89.9 - B 70.0 to 79.9 - C 65.0 to 69.9 - D less than 65 - F Your program demonstrates the class by asking the user to input four-course numeric scores, creating an object, and then reporting each course's score, average, overall grade, and letter grade.…arrow_forwardthis is question number 2i need answer within 6 or 7 hoursarrow_forward#this is a python programtopic: operation overloading, Encapsulation please find the attached imagearrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT