Suppose we have a Farmer class defined as follows: public class Farmer{ String name; double weight; int x, y; public Farmer (String name, double weight, int x, int y) { this.name = name; this.weight = weight; this.x = x; this.y = y; Can the following code be executed? If yes, what is the result? If no, why not? public class Test { public void main(String[] args){ Farmer mark = new Farmer(); }
Q: Write a Java class that would match a string. The class has method match with String as a return…
A: Coded using Java.
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: QUESTION 31 What is the output of running class Test? public class FinalExam { public static void…
A: Answer: B. ywvz
Q: TestCakeProgram.java:30: error: cannot find symbe ob[i] = new orderCake(w,name,rateO); symbol:…
A: 1- I have checked the entire code, there is only one mistake. 2- ob[i] = new…
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: (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: Observe the classes given below. Choose the option that gives a compile error. class One { class Two…
A: Two obj = new One(); , Option 3rd will give the compilation error because One is super class and…
Q: After the introduction of classes, in a java class, Adongo a student of the class came out with the…
A: Find the required correct code given as below and output :
Q: What will be the output of the code snippet? class MyClass { int[] a = {1, 2, 3, 4, 5,…
A: Question. What will be the output of the code snippet? class MyClass { int[] a = {1, 2,…
Q: 4. Consider the following program segment: public class Ch7_PrExercise4 public static void main…
A: we can only solve one question in one post. solving first. please post second question saperatly.…
Q: Consider the following instance variables and method from a class: private String descriptor; public…
A: Given descriptor is "regular" Called makeSentence(3, false) Thus, quant=3, sign=false
Q: Suppose an object of this class is initialized so the value of descriptor is "regular". What would…
A: Given descriptor is "regular" Called makeSentence(3, false) Thus, quant=3, sign=false
Q: public class Main 2- public static void main(String args[]) 3 static_out obji - new static_out();…
A: Classes and objects in java: Java is an object-oriented programming language and makes use of…
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 output{ public static int find (int a1, int a2) { if(a1==0) return(a1+1); else if(a1>0…
A: There is a class output in which two method are there find and main. Find method is recursively…
Q: a. After the introduction of classes, in a java class, Adongo a student of the class came out with…
A: A. Class Abelewas is not an abstract or interface therefore the methods should be implemented, No…
Q: public class Team { private String name; private int wins, int losses; public…
A: Program Approach: In the given code a class "Team" is declared that defines one string "name"…
Q: a. After the introduction of classes, in a java class, Adongo a student of the class came out with…
A: A. Сlаss Аbelewаs is nоt аn аbstrасt оr interfасe therefоre the methоds shоuld be…
Q: public class Myclass{ private static int count=0; private int x; //} public Myclass(int i) {…
A: To solve the question, let us first save the programming example that you have provided into two…
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: public class output{ public static int check (int a, int b, int c) { if(a==0) return (b); else if…
A: Given:
Q: What is the error(s) in the following Java program? class Person{ public class Test{ int Age; public…
A: Following are the errors: 1. When the constructor is defined then we have passed a parameter with…
Q: There are common attributes and methods between kids and trainers. What is the best choice for…
A: Answer: Main.java public class Main { public static void main(String[] args) { // create 7…
Q: Define class StringCheck with required instance variables 2) The StringCheck class should have…
A: In cases with multiple questions, we are needed to solve first three.
Q: Define class StringCheck with required instance variables 2) The StringCheck class should have…
A: In cases with multiple questions, we are needed to solve first three.
Q: public class GraduateStudent extends Student{ public int a ge; eoverride public String toString () {…
A: output in line number 20 and 21 for the above java code
Q: public class Dog { private String name; private double weight; private static int…
A: public class Dog { private String name; private double weight; private…
Q: Consider the following class defintion for class named MyClass and answer the following questions.…
A: The syntax for creating object of the class is as follows: 1. For default constructor Classname…
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: Begin with the following code, and the class you defined in #1 (you can assume it works even if you…
A: 1) Create an ArrayList(java) or List(C#) called Deck of PlayingCard(the class you defined in the…
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: Consider the following classes: public class Top{ int x; public Top (int x){ this.x = x + 1; } }…
A: The solution to the give java program is given below.
Q: Suppose we have a class for songs. A partial definition of this class is: public class Song { …
A: Find the code attached.
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: 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: 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: Given: 1. public class Foo { 2. public static void main (String[] args) { 3. int i = 1: 4. int j…
A: In this question we have to find the related output for the following code given in JAVA programming…
Q: Write a simple cash register class. (Use Java) Each cash register should keep track of the number…
A: ############################################################## The code for your class is given…
Q: Based on the java source code given , how can i add a simple payment system in the code. Please…
A: Errros
Q: identify the errors in the following class and how it can be fixed? public class Test { public…
A: If we look at the variables x and y , they are not initialized with any value. And this value give…
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: 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: Consider the following design for a Product class that keep track of product inventory:
A: 1. Create two product soft roll with name soft roll and quantity 25 and Hard rolls with name Hard…
Q: Consider the following Rectangle Class: public class Rectangle { private int width; private int…
A: Here we are creating in Rectangle object ar1 by passing 3 as width and 0 as length. By…
Q: Consider the following class public class Ketchup extends Food implements Tasty{ public String…
A: Imрlements meаns yоu аre using the elements оf а Jаvа Interfасe in yоur сlаss. extends…
Q: Suppose writing the Rectangle class (Java): public class Rectangle { private final double…
A: Getter and Setter in java: The get method returns the variable value, and the set method sets the…
Q: public abstract class Bird { private int x; private int y; private int z; public void…
A: The solution for the above given question is given below:
Q: public class P2 { public static void main(String[] args) { int[][] a2 = new int[3][3]; for (int i=0;…
A: According to the information given:- We have to compile this code and find out its output.
Step by step
Solved in 2 steps
- Given the following class definition,public class Pen{ private String name; public Pen(String n) { name = n; } @Override public String toString() { return this.name + "-"; }}public class Brush extends Pen{ private int ink; public Brush(String n, int m) { super(n); ink = m; } @Override public String toString() { return super.toString() + this.ink + "-"; }}What is the output of the following program? Brush fluffy = new Brush("Fluffy", 5); System.out.print(fluffy);If there is no output, please specify "nothing" (no quotes) in the blank for the output. No hand written and fast answer with explanationwhat is the problem with the following code. Give reason for your answer. public class MyClass\{ public static void main(String[] args) \{ int n[]={1,3,5,6} ; int b[]; b=n; \} \}An arithmetic progression is a sequence of numbers such that the difference between the consecutive terms is constant. For instance, the sequence 5, 7, 9, 11, 13, 15 is an arithmetic progression with a common difference of 2.Given the class IntNumber:1 public class IntNumber2 {3 public final int value;45 public IntNumber(int number) {6 this.value = number;7 }8 }where value is an immutable field, that can be directly accessed (public), implement a class called ArithmeticProgressionthat implements the following methods:•1 public static IntNumber getArithmeticProgressionDifference(ArrayList<IntNumber> list)which returns the difference between terms of the arithmetic progression (as an object of type IntNumber) if thevalues of the IntNumber objects are an arithmetic progression. The method returns null in any other case.•1 public static void printIsArithmeticProgression(ArrayList<IntNumber> list)which prints on the console:The list is an arithmetic progression with difference =…
- 1/ Write a BankAccountTester class whose main method constructs a bank account, deposits $1,000, withdraws $500, withdraws another $400, and then prints the remaining balance. Also print the expected result 2/ Implement a class Employee. An employee has a name (a string) and a salary (a double). Provide a constructor with two arguments public Employee(String employeeName, double currentSalary) and methods public String getName() public double getSalary() public void raiseSalary(double byPercent) These methods return the name and salary, and raise the employee's salary by a certain percentage. Sample usage: Employee harry = new Employee("Hacker, Harry", 50000); harry.raiseSalary(10); // Harry gets a 10 percent raise Supply an EmployeeTester class that tests all methods. 3/Implement a class Car with the following properties. A car has a certain fuel efficiency (measured in miles/gallon or liters/km—pick one) and a certain amount of fuel in the gas tank. The efficiency is specified in…*using java* Create a class AnimalCreate a class Cat, and a class Dog, and a class Bearded Dragon which extend Animal. Add to your Animal class: Member: name Methods: Public Animal(String name) //constructor public void makesSound()with the implementation printing out a generic animal sound. Next, override (add) the makesSound()method to your Cat and Dog class, with the implementation specific to each animal (i.e, cat says purr..). Do not override the makesSound() for your Dragon (bearded dragons don’t make sounds!)Note, you’ll also need a constructor in each of your subclasses which calls super(name) to initialize the common ‘name’ member of Animal. --- Next (in your test harness) create a List of different Animals ( a couple cats, a dog, a dragon... ) and add these Animals to your list. Iterate through your list & call makeSound on each. ( you should observe the implementation of the makeSound() method called will be: cat -> from Cat class, dog-> from Dog class,…use Java. Given the following class. public class FamilyMember { public String drink( ) {return “cup”;} public String eat( ) {return “fork”;} } Write a Baby class that is derived from the FamilyMember class. The Baby class has an instance variable for the age, a default constructor, and a constructor that accepts an integer. Include any other necessary methods. If a baby is older than 3 years, print that “it eats with its fork”; otherwise, “it eats with its hands”.
- The following is in Java: public class MyClass { private int x; private double y; public static void setValues(int a, double b) { x = a; y = b; } } 1) What is the problem? 2) In a few sentences how can the issue be fixed?Consider the following class definitions: public class Thing {public void string_method(String word) {word = word.substring(word.length() - 1);System.out.print(word);} }public class Thing2 extends Thing {public void string_method(String word) {super.string_method(word);System.out.print(word.substring(0,1));}} The following code segment appears in a class other than Thing or Thing2 Thing2 thing = new Thing2();thing.string_method("Tacky"); What is printed as a result of running the code segment? Group of answer choices yT yy Index Out of Bounds Error TT TackyTackyAn arithmetic progression is a sequence of numbers such that the difference between the consecutive terms is constant. For instance, the sequence 5, 7, 9, 11, 13, 15 is an arithmetic progression with a common difference of 2. Given the class IntNumber: 1. public class IntNumber 2. { 3. public final int value; 4. 5. public IntNumber(int number) { 6. this.value = number; 7. } 8. } where value is an immutable field, that can be directly accessed (public), implement a class called ArithmeticProgression that implements the following methods: •1 public static IntNumber getArithmeticProgressionDifference(ArrayList< IntNumber> list) which returns the difference between terms of the arithmetic progression (as an object of type IntNumber) if the values of the IntNumber objects are an arithmetic progression. The method returns null in any other case. • public static void printIsArithmeticProgression(ArrayList<IntNumber> list ) which prints on the console: The list is an arithmetic…
- Consider a class that keeps track of the sales of an item. An object of thisclass will have the attributes• Number sold• Total sales• Total discounts• Cost per item• Bulk quantity• Bulk discount percentageand the following methods:• registerSale(n) records the sale of n items. If n is larger than the bulkquantity, the cost per item will be reduced by the bulk discount.• displaySales displays the number sold, the total sales, and totaldiscount.a. Implement the class in Java.b. Write some Java statements that test the class.Consider the following code in Java 8:public interface Runnable{void run() ;}public final class Caller {public static void call (String before, String after, Runnable r) (System.out.println(before);r. run() ;System.out.println(after);} }public class MyClass{public static void main(String args[]) (Caller.call("BEFORE", "AFTER",); } }Complete the blark line with some code so that the program prints the folowing to the output: BEFOREHi there!AFTERJava program Make a class Employee with a name and salary. Make a class Manager inherit from Employee. Add an instance variable, named department, of type String. Supply a method toString that prints the manager’s name, department, and salary. Make a class Executive inherit from Manager. Supply appropriate toString methods for all classes. Supply a test program that tests these classes and methods.