Question

In: Computer Science

Complete the following Java program to, using BigDecimal, calculate and display the radius of the circle...

  1. Complete the following Java program to, using BigDecimal, calculate and display the radius of the circle whose diameter is stored in the variable diameter.  The radius is calculated as half of the diameter. For example, since diameter is 7.5, the program should calculate and display the radius like this:  (2 points)   (CLO 1)

package q1;

import java.math.BigDecimal;

public class Q1 {

    public static void main(String[] args) {

        float diameter=7.5f;

        

    

        

}

}

                                            Radius = 3.75

  1. Consider the following Java program and then answer the questions that follow.  (CLO 4)

Output:

public class TestInheritance{

            public static void main(String args[]){  

            Dog d=new Dog();

            d.eat();    

            d.bark();  

           }

  }

class Animal{  

    void eat()  {System.out.print("eating...");}  

}  

  class Dog __________ Animal {  

        void bark()  {System.out.println("barking...");}  

        void eat() {

              super.eat();

              System.out.println("only dog food");

         }

  }  

  

  

4.1 Fill in the missing keyword in the class Dog declaration to make it a subclass of   Animal.  (0.5 points)

4.2 In the box provided above, show the output of the program. (2 points)

  1. Consider the earnings method of the subclass BasePlusCommissionEmployee, given below, then answer the question that follows:  (2.5 points)  (CLO 4)

  public double earnings()

   {

      return getBaseSalary() + Super.earnings();

   }    

  Find and fix the syntax error that is likely to be generated in the above method.

Solutions

Expert Solution

package q1;

import java.util.*;
import java.math.BigDecimal;

public class Main
{
   public static void main(String[] args) {
  
   Scanner sc=new Scanner(System.in);
   BigDecimal diameter = sc.nextBigDecimal();//taking input diameter from user
   BigDecimal conv = BigDecimal.valueOf(2);//converting the value 2 to BigDecimal because radius=diameter/2
   BigDecimal radius=diameter.divide(conv);// this will divide diameter by 2
System.out.println(radius); //print the radius
   }
}

==============================================================

4.1

public class TestInheritance{

            public static void main(String args[]){  

            Dog d=new Dog();

            d.eat();    

            d.bark();  

           }

  }

class Animal{  

    void eat()  {System.out.print("eating...");}  

}  

  class Dog extends Animal {  

        void bark()  {System.out.println("barking...");}  

        void eat() {

              super.eat();

              System.out.println("only dog food");

         }

  }  4.2 The output of the

above program is

eating...only dog food

barking...

=================  

@Override
public double earnings() {
return getBaseSalary() + super.earnings();
}


Related Solutions

Write a Java program named CircleZapper that displays a circle with a radius of 10 pixels,...
Write a Java program named CircleZapper that displays a circle with a radius of 10 pixels, filled with a random color at a random location on the screen. When you click the circle, it disappears and a new random color circle is displayed at another random location (see display below). After twenty circles are clicked, display the time spent in the pane. To detect whether a point is inside the circle, use the contains method defined in the Node class....
Write the program in Java (with a graphical user interface) and have it calculate and display...
Write the program in Java (with a graphical user interface) and have it calculate and display the mortgage payment amount from user input of the amount of the mortgage, the term of the mortgage, and the interest rate of the mortgage. Allow the user to loop back and enter new data or quit. You need to include Calculate, Reset, and Exit buttons on your GUI. Please insert comments in the program to document the program. Allow the user to enter...
(Display a Circle and Its Attributes) Write a program that displays a circle of random size...
(Display a Circle and Its Attributes) Write a program that displays a circle of random size and calculates and displays the area, radius, diameter and circumference. Use the following equations: diameter = 2 × radius, area = π × radius2, circumference = 2 × π × radius. Use the constant Math.PI for pi (π). All drawing should be done on a subclass of JPanel, and the results of the calculations should be displayed in a read-only JTextArea.
Write a program in java that uses methods to input data for calculation, calculate, and display...
Write a program in java that uses methods to input data for calculation, calculate, and display the results of the calculations. That is, there are at least three methods. The problem is to write a program that calculates the area of a rectangle. This action should be repeatable.
8) Create the following program using Java. Circle calculation using methods Create scanner declare double variable...
8) Create the following program using Java. Circle calculation using methods Create scanner declare double variable radius = -999 declare character choice create do while loop inside of do loop write: System.out.println(); System.out.println("*** CIRCLE CALCULATIONS ***"); System.out.println(); System.out.println("1. Enter the radius of the circle"); System.out.println("2. Display the area of the circle"); System.out.println("3. Display the circumference of the circle"); System.out.println("4. Quit"); System.out.println(); System.out.println("Enter a number from 1 - 4"); System.out.println(); Declare choice character and relate to scanner declare switch (choice) case...
Java - Write a program to calculate a user’s BMI and display his/her weight status. The...
Java - Write a program to calculate a user’s BMI and display his/her weight status. The status is defined as Underweight, Normal, Overweight and obese if BMI is less than 18.5, 25, 30 or otherwise respectively. You need to read weight (in kilogram) and height (in metre) from the user as inputs. The BMI is defined as the ratio of the weight and the square of the height. [10 marks]
Write a C++ program that prompts the user for the radius of a circle and then...
Write a C++ program that prompts the user for the radius of a circle and then calls inline function circleArea to calculate the area of that circle. It should do it repeatedly until the user enters -1. Use the constant value 3.14159 for π Sample: Enter the radius of your circle (-1 to end): 1 Area of circle with radius 1 is 3.14159 Enter the radius of your circle (-1 to end): 2 Area of circle with radius 2 is...
Write a JAVA program to display your complete names, your matric number and your course of...
Write a JAVA program to display your complete names, your matric number and your course of study, using the two access modifiers stated in (a) and (b) (a) Use static access modifier for the method declaration of the program class, also use class name Eee532MakeUp. Use any method name of your choice. (b) Use public access modifier for the method declaration of the program class, also use class name EceCourseJava. (2) Which of the programs in (a) or (b) is...
Java program that display ATM booth line by using data sturcture Queue.
Java program that display ATM booth line by using data sturcture Queue.
In java processing 3, write a program that draws a circle. The center of the circle...
In java processing 3, write a program that draws a circle. The center of the circle would be first point on the canvas where the mouse is pressed on it. While the mouse is pressed, the circle can be drawn by moving the mouse cursor farther than the first point that mouse was pressed (circle center). As soon as the code is run, a timer at the bottom of the canvas should start working. Also, the radius of the circle...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT