Consider the following code: public class DemoClass{ private double PI = 3.1416; void calculateArea(double radius){ double area = PI*radius*radius; System.out.println("Area: " + area); } public static void main(String []args){ calculateArea(5.0); } } a) Suggest modification to the code so that the value of PI cannot be modified later. Also modify the above code so that it can run without any error. b) Create a non-static inner class inside the DemoClass. Move the calculateArea() function inside the inner class. Now call the calcualteArea() function from the main() function.
Q: Java Questions - (Has 2 Parts). Based on each code, which answer out of the choices "A,B,C,D,E" is…
A: Both of these questions from the inheritance part of the java. The second question is giving the…
Q: Write a Rational class. Recall a rational number is a rational number, composed of two integers with…
A: #include <iostream>#include <string>#include <stdlib.h>using namespace std;class…
Q: public class BClass { private int x; public void set(int a) { x = a; } public void print( {…
A: print() method displays the respective data member of the class. In method overriding, we need to…
Q: CLASS AND OBJECT WRITE! 1.) Write the main class of the given class Animal below that set the…
A: Step 1:- Program Approach:- 1.Create the object of the class Animal 2.call the function…
Q: Step 1) Copy the following code into an Editor public class Test{ public static void main(String a…
A: The step-by-step complete code is given below, with proper explanations.
Q: Quèstion 11 Match the following A. Public ycall a method in Java using primitive type parameters B.…
A: 1. Calling a method in java using primitive type parameters is call-by-value 2. Calling a method in…
Q: (this is question1) public abstract class Shape { public Shape() { } public abstract…
A: Here we have an abstract class shape that has an abstract method and one method that returns the…
Q: Write a SavingsAccount class for this Java program.
A: Find the following code
Q: Assume that you are applying “testing” and “inspection”, the two defect finding methods in the…
A: The answer is as follows.
Q: How do I fix the errors? Java Error 1 overloading constructor with invalid weight ERROR:…
A: There is a trick to validate the instance variable's value. You should call the setters to set the…
Q: Use Java. Given main() and the Instrument class, define a derived class, StringInstrument, for…
A: StringInstrument.java public class StringInstrument extends Instrument { private int…
Q: public class Ice extends Fire { public void method1() { System.out.print("Ice 1 "); public class…
A: Output of the given program is given below:-
Q: b. public class Dog ( String breed; int age, String color, void barking() { } void hungry) { } void…
A: Need to convert below shown image code snippet into complete encapsulation. Encapsulation is the…
Q: Q1. In the following class, how many instance variables are there? public class Car { int numDoors;…
A: - The question is to find the number of instance variable in the given code. - The second question…
Q: Consider the following class definitions public class SampleClass{ public String greet() {return…
A: In the given below code public class SubClass extends SampleClass{ public string greet() {return…
Q: Q4. Given below is the code for the controlling class with constructor overloading, analyse the code…
A: Constructor overloading a concept of having more than one constructors in class with different…
Q: Q 1: Access class members from the same package Note: ClassA and ClassB in this question are in the…
A: In order to create a variable that is not accessible outside class we must declare it as private. If…
Q: Q#1: Write the Class for Circle. Read the following code and create the attributes, method,…
A: Define the class Circle as follows: It contains a private data member for storing the radius. It…
Q: Predict the output of the following code: public class MyClass extends Test { public static void…
A: working: The code is used to print the value of the method num() present in the classes Test and…
Q: (d) Complete the following code by writing the constructor and toString method in Sub class to print…
A: Provided the Rewritten code for both of the above given questions where highlighted part represents…
Q: 2) Consider the following class class Department { private: string name; const long locationNo;…
A: Program descriptionThe class definition has the declarations of the static variables, regular…
Q: Consider the following class definition: public class AClass { private int u; private int v; public…
A: Inheritance- Inheritance is one of the feature of Object Oriented Programming.…
Q: The following code is in Java: public class Vehicle // Superclass { private…
A: Given code snippet public class Vehicle // Superclass { private double cost;…
Q: What will be the output of the following code? abstract class X { int b; abstract void print(); }…
A: abstract class X{ int b; abstract void print();}class Y extends X{ int a; void print()…
Q: what is the output of the following codes : code 1. class A { {…
A: code1: //lets trace the code for outputclass A { { System.out.print(1);//this prints 1…
Q: Given the following code: } public class Foo { public void barl () { public abstract void bar2 ();…
A: abstract method Only applicable in an abstract class, an abstract method lacks a body. The subclass…
Q: Question public class MyProgram ( if (h 30) system.out.print("Evening"); t = t + 5;…
A: I have provided the answer based on java Programming. Detailed comments are included for a better…
Q: Analyse the following Java code segment and answer the questions that follow: 1| interface Steerable…
A: Every program is written using some building blocks which are called programming constructs. The…
Q: 1. What will be the output of the code below? class Animal ( void walk() ( 3 220 | INTEGRATIVE…
A: The output of the above code are:
Q: Write a java program as shown in the following UML class diagram:(read the details below) Name…
A: The UML Diagram of class Name consists of: Data members(private): first, initial, last Constructor:…
Q: 2. Given the Baby class below: public Class Baby { String name; int birthWeight; } Write an equals…
A: class Baby { public : string name; int birthWeight; };
Q: Public class secret private int x; private static int y; public static int count; public int z;…
A: Dear learner, hope you are doing well, I will try my best to answer this question. Thank You!!
Q: (Java) CHECK IF FINAL OUTPUT MATCHES SAMPLE OUTPUT! Make the 2 following classes: Employee.java…
A: Here I have defined the methods in the class Employee. I have defined the default and parameterized…
Q: In JAVA i have a class that i have the pseudo code but im having trouble filling in the methods…
A: The setters and getters methods are used for encapsulation in object oriented paradigm. The…
Q: The following code is in Java: public class Vehicle // Superclass { private…
A: Given code snippet in java public class Vehicle // Superclass { private double cost;…
Q: Consider the following code snippet. How many times do you expect "In the constructor!" to be…
A: Please find the answer below:
Q: Problem 4) Suppose the following Course class is given: public class Course { private String…
A: If the evaluation of a logical expression exits even before the complete evaluation is done, it is…
Q: Consider the following code: 1. public class Circle { private int radius; private int x; private int…
A: C) the address of the Circle object
Q: public class Product { class Food extends Product { class Cheese extends Food { Considering the…
A: The solution to the given problem is below.
Q: You are given Car.java class public class Car { } protected double year; Car cl public Car (double…
A: given java program and the output is given below
Q: FOR JAVA Part I Create a Company class that has at least three properties. Part II Write…
A: we write java code: class Company { int company_id,turnover; String name,address,department,email;…
Q: Explain the following Java Polymorphism code in details. class Shape { public double getArea() {…
A: Lets see the solution.
Q: JAVA Create a class called Quadratic for representing a one-variable quadratic expression of the…
A: A quadratic equation is in the form of the a×x2+b×x+c=0 Where a,b, and c are the coefficients of the…
Q: public class F { private boolean x; public static void main (String[] args) { Ff = newF ();…
A: Since no information is given about whether these two classes belong to same java filer different…
Q: 7. Consider the following design for a Product class that keep track of product inventory: public…
A: public class Product { public Product(String name, double qty) { prodName = name;…
Q: public class Employee { private int hours; private double salary; private int vacationDays; public…
A: a) Java program that implements getHours(),getSalary(),getVacationDays(): class Employee{…
Q: Q1. Write two Java classes for calculating the power m" using the recursive method as follow: Class…
A: Algorithm to calculate power mn using recursion: Method: int calculatePower(n, m) 1. IF n == 1:…
Q: 1- public class Student { 2 3 public abstract double calcScore(); 4 5 } Which of the following is…
A: The given code is a java code snippet where a Student class is created. The student class has method…
Step by step
Solved in 4 steps with 2 images
- Instructions-Java Assignment is to define a class named Address. The Address class will have three private instance variables: an int named street_number a String named street_name and a String named state. Write three constructors for the Address class: an empty constructor (no input parameters) that initializes the three instance variables with default values of your choice, a constructor that takes the street values as input but defaults the state to "Arizona", and a constructor that takes all three pieces of information as input Next create a driver class named Main.java. Put public static void main here and test out your class by creating three instances of Address, one using each of the constructors. You can choose the particular address values that are used. I recommend you make them up and do not use actual addresses. Run your code to make sure it works. Next add the following public methods to the Address class and test them from main as you go: Write getters and…Need code in C++. I have answer till part 7,please go through the code and correct it if you find any mistakes. If not answer the last 4 parts(8,9,10,11) Create a class called Line with the followings:1. Private members: p1 and p2 as pointer to Point objects (code provided below), slope and length as double variables2. Define setter and getter functions.3. Define a default constructor that allocate dynamic memory for points andset everything to 0.4. Overload a constructor that allocates memory for points, initilize themwith given arguments, and calculate the slope and length.5. Overload a destructor, a copy constructor and a copy assignment operator.6. Create a function called ”parallel” that return true when given lines areparallel and returns false otherwise7. Overload the less than (<) and greater than (>) and equality (==) oper-ators (compare the length)8. Write a functions that reads lines in the format provided in the lines.txtfrom the file and stores them in a vector named…c++ Implement a BankAccount class. BankAccount must have the following members: A member variable account_no of the type unsigned int.A member variable owner_name of type std :: string.A member variable balance of the double type.A parameterized constructor that takes account_no and owner_name as input parameters.The members must be encapsulated in accordance with the usual convention. Overlay the inflow operator (>>) for the BankAccount class Input follows the format:[account_no] [owner_name] [balance] and must be loaded with the inflow operator. Output should have the following format:Account [account_no], owned by [owner_name] has the balance [balance] Note that the square brackets refer to variables or special characters and are not included.You may add necessary designers, member functions and operators at will as long as they are appropriate. input expected output123 Hansson 1000 Account 123, owned by Hansson has the…
- in c++ write aprogram to Create a class Rectangle with length and breadth as private data members and also provide the following member functions: getdata(): gets the length and breadth of rectangle. calarea(): return the area of the rectangle. calperi(): return the perimeter of the rectangle. issquare(): return true if the rectangle is squareQuestion: 3 write python program ; Implement the design of the Doctor and Engineer class derived from Person class so that the following code generates the output below:class Person: def __init__(self, name, contact): self.name = name self.contact = contact def __str__(self): s = f"Name: {self.name}\nContact: {self.contact}" return s#Write your code hered = Doctor("Dr Strange", "4585632", "Neurosurgery", "DMC")d.add_patients("Dhaka Abdur Rahim", "Dhaka John Cena", "Narayanganj John Wick", "Comilla CM Punk")print("1.=========================================================")print(d)print("2.=========================================================")d.show_patient_list("Dhaka")print("3.=========================================================")d.show_patient_list("Rajshahi")print("4.=========================================================")d.add_patients("Narayanganj Naruto…C++ 2. Define a new "Degree" class that contains a year (integer), a subject (string), and a person’s name (string). For example, a degree can have "John Smith", 2020, and "Computer Science" It should have at least the following methods:- toString method must return all the degree information: year, subject, and person’s name.Here is an example of the formatted degree string:NAME(John Smith) SUBJECT(Computer Science) YEAR(2020) - hasTheSameDegree method compares 2 degrees and returns true if both have the same year and the same subject. Otherwise, it returns false. - isLater method that compares 2 degrees and returns true if the current degree has the year later than the 2nd degree and false otherwise. Important notes: - You can add as many other methods as you need. But this class should not provide the default constructor. - Show how this class and its methods are being used, called, and produce the correct results.
- Use the following partial class definitions to answer the questions a-c public class A1 { public int x; private int y; protected int z; ... } public class A2 extends A1 { protected int a; private int b; ... } public class A3 extends A2 { private int q; ... } a) Which of the following is true with respect to A1, A2 and A3? Group of answer choices A1 is a subclass of A2 and A2 is a subclass of A3 A3 is a subclass of A2 and A2 is a subclass of A1 A1 and A2 are both subclasses of A3 A2 and A3 are both subclasses of A1 A1, A2 and A3 are all…Create parent class Shapes with protected parameters width and height and function printarea() and a virtual function cal_area(). Create two sub classes Rectangle and Sqaure. In main() create 2 pointers of Shapes and assign Rectangle and Square to it. Call printarea function with the pointers. Note: Use C++ language with well explaination. After performing this program. Implement this program using an abstract class.Problem Write a C++ program that will display multiple-choice trivia questions, accept the user's answers, and provide a full key and a score at the end. Question class Design and implement a class called Question. The Question class contains the following information: a stem (the text of the trivia question), an array of 4 multiple choice answers (the text of each possible answer) the letter of the correct answer (A, B, C, or D), called the key. This class will be used to represent trivia questions in a trivia game. The following operations should be available for Question objects (use the provided names). Construct a Question with no values (use empty strings for stem and answers and ‘X’ for the key). Construct a Question given its 3 components (). setStem: Set the stem question. getStem : Return the stem question. setAnswers : Set the 4 answers given an array. The answers will NOT include the letter (A, B, C, or D). getAnswer(i) : Return the single answer at index i. setKey: Set…
- Create parent class Shapes with protected parameters width and height and function printarea() and a virtual function cal_area(). Create two sub classes Rectangle and Sqaure. In main() create 2 pointers of Shapes and assign Rectangle and Square to it. Call printarea function with the pointers. Implement using abstract class. Note: use OOP and C++Problem 1: Java programComplete the Clothing class, the class should have the following instance variables, constructor(s) and instance methods:- An instance variable of type double named price.- An instance variable of type String named type.- An instance variable of type String named size.- A default “no-arg” constructor that sets the price to 29.9, the type to “TShirt” and the size to “Medium”. - An overloaded constructor that takes three parameters and set the instance variables accordingly. - A method named increasePrice that takes no parameters and returns no value, the method increases the instance variable price by 5.- An overloaded method increasePrice that takes a double parameter xand returns no value, the method increases the instance variable price by the value of parameter x.- A method named details which takes no parameters, returns no value, the method prints the Clothing item details in the format shown in the sample output.- Your output should look exactly the same…Describe how memory allocation is done to objects and also develop a C++ programfor employee class with following attributes such as Employee ID, Employee Name,Designation and Salary. Program should sort and display the list of employees inascending order of their salaries using object as a function argument. (Note:Employee ID must not be inputted by the user i.e., auto incremented.)