Add a constructor for Animal class shown. The constructor should pass in a string parameter named "sound". 1 using System; 2 3 public class Animal 4 { 50 public string Sound { get; set; } public void Speak() { Console.Wiriteline("The dog says " + Sound); 8. 9. 10 11 } 12 13 public class Program 14 { 15 public static void Main() 16 { 17 18 19 }
Q: An encapsulation violation occurs when private information that should not be changed by external…
A: The given feature Encapsulation is one of the most favorite features of Object-oriented programming…
Q: (Java) Make the 2 following classes: Employee.java EmployeeTest.java Copy and paste the below…
A: In Java, the most searching program is of employee details. An employee is an entity that can have…
Q: Write a class named Person with data attributes for a person’s name, address, and telephone number.…
A: Given:- Write a class named Person with data attributes for a person’s name, address, and telephone…
Q: Given the following super class and subclasses: public abstract class ThemePark String name: //…
A: Default constructors are the constructors that has no parameters whereas normal constructors are the…
Q: Write a Java class Person for dealing with persons. Your class must have the following features:…
A: As per the requirement person class is developed. Note: As per our guidelines we are suppose to…
Q: 4. Create an interface Wheel with methods setWheels (int c) and getWheels () and a class Vehicle…
A: Solution: Given,
Q: The BankAccount class models changes to the balance of a person's savings account. public class…
A: Below are the answers with code and explanation respectively:
Q: Write a class named Person with data attributes for a person’s name, address, and telephone number.…
A: Python program for the above problem is given below:-
Q: Consider the classes shown below: public class Parent { private int value = 100; public int…
A: Inheritance is a mechanism in which one object acquires all the properties and behaviors of a parent…
Q: Write a Java class Person for dealing with persons. Your class must have the following features:…
A: class Person{ long person_id; String name,gender; //default constructor Person(){…
Q: Consider the following class definition. public class Liquid { private double boilingPoint; private…
A: Here is the explanation about the behavior of the program:
Q: Using the concept of classes in object-oriented programming Write java project for Medical Center…
A: Code: import java.io.*; import java.util.*; import java.util.Calendar; /* Hospital Management System…
Q: Implement the following classes / abstract classes below. Monster abstract class which has health…
A: public class Main { public static void main (String[] args) { //create 3 instances and…
Q: Make a class Employee with a name and salary. Make a class Manager inherit from Employee. Add an…
A: Programming instructions: Create a class Employee. In the Employee class, create the instance…
Q: Add the following new constructor in the BMI class:/** Construct a BMI with the specified name, age,…
A: Program code: File name: BMICalculation.java //import the required packages import…
Q: hispe Define a public class Whisperer that provides a single class method named vhisper.whisper…
A: Note: Since you have not provided the language to write the code so I am using java language to…
Q: (Java) 3. public class person{ 4. private double salary; 5. public person(){ 6. salary =…
A: Non-parameterized Constructor/Default Constructor: Non-parameterized constructors are those that…
Q: thod
A: Create classes Name, DebitCard and TestClass as per the requirements of the question. In 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: Write a class HouseBuilder with private class members as houseArea(double, e.g. 20 square feet),…
A: abstract class HouseBuilder{ protected double houseArea; protected String houseLocation;…
Q: Code is in Java find the error in the following class definition: public class MyClass {…
A: public void MyClass(int a, double b) The Above Line Is Incorrect. There Won't be any Return Type…
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: Include the following methods: - A constructor with 3 parameters. Initialize the 3 member variables…
A: Name.java class: public class Name { String firstname,middlename,lastname; public Name(String…
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: 2. Consider the following class definitions: public class BClass private int x; public void set(int…
A: Lets see the solution in the next steps
Q: Write a class HouseBuilder with private class members as houseArea(double, e.g. 20 square feet),…
A: using static System.Console; namespace ConsoleApp1 public class HouseBuilder { private double…
Q: Java always provides a default constructor. That is, a constructor that can be caller with no…
A: We have to explain whether this statement is true or false. Java always provides a default…
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: Modify the given codes to remove the compilation errors. 1. public interface Carnivore {…
A: Answer: Ans-1: The code will not compile and it will be given you the two compile-time errors…
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: 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: What is the output of the following code? public interface yourInterface { int x = 10, y = 20; void…
A: Interface: Interface in java is abstract type. The methods of interface are implemented by classes.…
Q: public abstract class Plant { } public abstract void breathe (); Consider the class shown above.…
A: Solution- Before solving this problem first need to under the concept of the abstract class.…
Q: public abstract class Landmark { public abstract int countVisitors(); } Consider the class shown…
A: Data Abstraction is an OOP concept that hides the background details. It shows only those…
Q: Consider the following class definition and answer the following questions: public class MyClass {…
A: We need to find the output of the given Java code. MyClass object1=new MyClass(12,15); //This sets…
Q: Write a java program Write a class named Employee with name and salary as private data fields. Add…
A: The main objective of the program is to create three java files. Employee.java Manager.java…
Q: Fill in the blanks for the method signature of a Deep Copy constructor for the Plant class. public…
A: Please find the answer below
Q: Java: Derive the class ExtClock from the class Clock by adding a data member to store the time zone.…
A: Inheritance is a feature of java object-oriented programming. The property of acquiring the parent…
Q: What is the output of the following code? public interface yourInterface { int x = 10; %3D int y =…
A: Operators are the fundamental building blocks of all programming languages. Java, too, has a variety…
Q: Solve the programming exercise P9.8 on Page 490 on the book. Implement a superclass Person. Make two…
A: // Screenshot of the code & output
Q: An encapsulation violation occurs when private information that should not be changed by external…
A: Encapsulation in object-oriented programming usually known as binding the data altogether with the…
Q: Create a base class, cell phone and derive a class smartphone from it. In cell phone, create…
A: Abstract classes are parent classes or base classes. Abstract classes contain the common…
Q: b) Following program contains two different kind of errors. Identify and explain those errors?…
A: Here we have abstract class A which contains two methods private abstract method m1() and final…
Q: public abstract class Building { } public abstract String increaseSize(); Consider the class shown…
A: The following question is in Java Programming Language and Uses the Concept of Java Extends.
Q: Write a class Battery that models a rechargeable battery. A battery has a constructor
A: public class BatteryTester{ public static void main (String[] args) { Battery battery=new…
Q: Implement all the classes using Java programming language from the given UML Class diagram.
A: public class Shape { //declaring instance variables private String color; private boolean filled;…
Q: A class called MyPoint, which models a 2D point with x and y coordinates, is designed as shown in…
A: A class called MyPoint, which models a 2D point with x and y coordinates, is designed as shown in…
Q: class Employee { String name; double salary; public Employee() { }
A: The class is EMPLOYEE. It has got a constructor of same name. Attributes are: 1. name of type…
Q: Please define two interface Auto and Sprinkler, and three classes Car, Truck and FireTruck. Car and…
A: Code: interface Auto{ public abstract void move(); public abstract void stop(); public…
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…
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 images
- 2. Complete the application below. public class CarApp { public static void main() { string color = blue; string model = C2021;i int speed 80; %3D // declare necessary object matching to the constructor definition // display the color and model on the screen // call the calspeed) method and display the new speed after calculation. } }9 public class PictureViewer 10{ public static void main(String[] args) 11 12 // Step 2: Fix the syntax errors and submit it to Codecheck to pass the test. // Note: Do not add or remove any statements 13 // 14 15 // Do not change the semantics of each statement Do not add or remove any variables Do not add or remove any objects Magic numbers are allowed 16 17 18 // 19 // 20 // Create an object of Picture by loading an image Picture pic = Picture("starry_night.png"); 21 22 23 // Display the width and height System.out.println("Width : " + pic.getWidth()); System.out.println("Height: 24 25 + pic.getHeight()); %3D 26 27 // Increase the width by 50 on both sides and // increase the height by 40 on both sides. // Must use dw and dh when calling method grow(). int dw, dh = 40; pic.grow(dw, dh); 28 29 30 31 32 33 // Display the width and height System.out.println("Width : System.out.println("Height: 34 + pic.getWidth()); + pic.getHeight()); 35 36 37 // Draw the picture draw(); 38 39 40 //…3 public class ShippingCalculator { public static void main(StringO args) { new Scanner(System.in); 1 st passed 5 Scanner scnr int shipWeightPounds; int shipCostCents = 0; final int FLAT_FEE_CENTS = 75; 7 Altasts passed 8 10 final int CENTS_PER_POUND = 25; System.out.print("Enter shipping weight: "); shipWeightPounds = scnr.nextInt(); shipCostCents = FLAT_FEE_CENTS + shipWeightPounds * CENTS_PER_POUND; 11 12 13 14 15 16 17 System.out.println("Weight(lb): " + shipWeightPounds); 19 Suctom Aut nnin+1nr"Elnt foofconte): ELAT CCE CETS): Run X Testing shipWeightPounds = 10 Output differs. See highlights below. Special character legend Enter shipping weight: Weight (lb) : 10 Flat fee (cents): 75 Your output Cents per pound: 25 Shipping cost (cents) : 325 Weight (1b) : 10 Flat fee (cents): 75 Expected output Cents per pound: 25 Shipping cost (cents): 325 X Testing shipWeightPounds = 2
- public class LabProgram { public static void main(String args[]) { Course course = new Course(); String first; // first name String last; // last name double gpa; // grade point average first = "Henry"; last = "Cabot"; gpa = 3.5; course.addStudent(new Student(first, last, gpa)); // Add 1st student first = "Brenda"; last = "Stern"; gpa = 2.0; course.addStudent(new Student(first, last, gpa)); // Add 2nd student first = "Jane"; last = "Flynn"; gpa = 3.9; course.addStudent(new Student(first, last, gpa)); // Add 3rd student first = "Lynda"; last = "Robison"; gpa = 3.2; course.addStudent(new Student(first, last, gpa)); // Add 4th student course.printRoster(); } } // Class representing a student public class Student { private String first; // first name private String last; // last name private double gpa; // grade point average…QUESTION 15 public class numClass { private int a; private static int y = 10; public numClass(int newX) {a=newx; } public void set(int newx) { a=newx; y+=a; } public void setY(int newy) { y=newY; } public static int getY() { return y; } }// end of class public class output { public static void main(String[] args) { numClass one = new numClass(10); numClass two = new numClass (2); try{ one. sety(30); two.set(4); if(one.getY()==30) throw new Exception ("30"); one.setY(40); } catch (Exception e) { two.sety (50); } System.out.println(two.getY()); }// end of main } // end of classpublic class Application { public static void main(String[] args) { Employee empl = new Employee(); empl.firstName = "Ali"; empl.lastName = "Omar"; empl.salary = 20000; Employee emp2 = new Employee(); emp2.firstName = "Mohamed"; emp2.lastName = "Nour"; emp2.salary = 30000; System.out.println("- System.out.printin("- empl.employeeSalary(); System.out.println("- empl.checkEmployeeSalary(emp1.salary, emp2.salary); System.out.printin("- System.out.println("- printEmployee(emp2); System.out.printin("- Employee employeeArr[] = new Employee[2]: employeeArr[0] = empl; employeeArr[1] = emp2; Application a = new Åpplication(); a.printArrayofEmployee(employeeArr); Non static (instance) start to call Static function to print ---------"); "); - Non Static function to print - --"); Non static (instance) start to call same class Static function to print --------); -"); Non Static function to print ----); System.out.println("- System.out.printin("- System.out.printin("Salary : " + Employee.salary);…
- public static class Lab2{public static void Main(){int idNum;double payRate, hours, grossPay;string firstName, lastName;// prompt the user to enter employee's first nameConsole.Write("Enter employee's first name => ");firstName = Console.ReadLine();// prompt the user to enter employee's last nameConsole.Write("Enter employee's last name => ");lastName = Console.ReadLine()// prompt the user to enter a six digit employee numberConsole.Write("Enter a six digit employee's ID => ");idNum = Convert.ToInt32(Console.ReadLine());// prompt the user to enter the number of hours employeeworkedConsole.Write("Enter the number of hours employee worked =>");// prompt the user to enter the employee's hourly pay rateconsole.Write("Enter employee's hourly pay rate: ");payRate = Convert.ToDouble(Console.ReadLine());// calculate gross paygrossPay = hours * payRate;// output resultsConsole.WriteLine("Employee {0} {1}, (ID: {2}) earned {3}",firstName, lastName, idNum,…8. OOPS Theory #6 public class Car { public void horn() { System.out.println("Horn horn"); } } public class Ferrari extends Car { public void horn() { System.out.println("Ferarriiiiii"); } } public static void main(String[] args) { Ferrari ferrari = new Car(); ferrari.horn(); } Pick ONE option Horn horn Ferarriiii Cannot compile Runtime exception Clear Selection 9. OOPS Theory #7 In Java, we can achieve the abstraction by creating the blueprint of an object and only have abstract methods. What do we call this? Pick ONE option Interface Encapsulation Instance Protected Clear Selectionclass Student { private int age = 18; public Student() { age = 19; } } public class Test { public static void main (String[] args){ Student s = new Student(); System.out.println (s.age); } }
- 7. public class Father { public String name; public int age; // customer name Father(){ name="Hassan"; age=50;} public void display(){ System.out.println("Name:"+name); System.out.println("Age:"+age); }} Figure 3 i. Based on Figure 3, create a class named Child that inherits the Father class. Declare an instance name location (String) for class Child. ii. Define a constructor in class Child and give an appropriate initial values for the instance (name, age, location). Define a method display () in class Child, execute the display () method in superclass using the keyword super. Method display () in class Child should print the information of name, age and location. ii.public class Author2 {3 private String name;4 private int numberOfAwards;5 private boolean guildMember;6 private String[] bestsellers;78 public String Author()9 {10 name = "Grace Random";11 numberOfAwards = 0;12 guildMember = false;13 bestsellers = {"Minority Report", "Ubik", "The Man in the HighCastle"};14 }1516 public void setName(String n)17 {18 name = n;19 }20 public String getName()21 {22 return name;23 }2425 public void winsAPulitzer()26 {27 System.out.println(name + " gave a wonderful speech!");28 }29 } 1. This class includes a constructor that begins on line 8; however, it contains an error. Describe the error. 2. Rewrite the constructor header on line 8 with the error identied in part c of this question corrected. 3. Demonstrate how you might overload the constructor for this class. Write only the header. 4. Write a line of Java code to create an instance (object) of this class. Name it someAuthor. 5. Write a line of code to demonstrate how you would use the someAuthor object…5 points Save Answer QUESTION 4 What is printed? public class Puppy { private int puppyAge; private String puppyName; Puppy(String name){ puppyName = name ;} public void setAge( int age ) { puppyAge = ++age; } public int getAge(){ return puppyAge; } %3D public class TestPuppy{ public static void main(String []args) { Puppy myPuppy = new Puppy( "tommy" ); myPuppy.setAge( 2 ); System.out.print("Puppy's age is :" + myPuppy.getAge()); System.out.print(" %3D Name chosen is :" + myPuppy.puppyNname ); D Puppy's age is : 2 Name chosen is : tommy Puppy's age is : 3 Name chosen is : tommy O Syntax Error O Run Time Error Save All Answers Close Window Save and Submit - Save and Submit to save and submit. Click Save All Answers to save all answers. MacBook Pro 888 ES F6 F3 96 7