VII Show what is printed by the following program and the work space with the values of the variables. public class VII{ public static void main(String[]args) { int a = 1, b = 4, c = 5; a = funny (b,c); System.out.println("first: "+a+" "+b+" "+c); a = 4; b = 8; c = 10 + funny (a+2,b); System.out.println("then: "+ c); System.out.println("next: "+funny (b, a)); public static int funny(int t, int v) { int w; if (t + 1 > v) w =t + 3 * v; //watch for arithmetic precedence else w = 20; System.out.println("w is now: " + w); return W;
Q: 14 What will be the output of the given program class A { int m-20, 3D303B void display() f out of…
A: By Running the above code :- class A { int m = 20 , n = 30 ;void display(){System.out.println(m); }}…
Q: 3. Construct a simple purchasing program based on the UML Class Diagram below. LabExer2 itemName:…
A: The program will encapsulate the data and bind data and method. Data encapsulation is taking place.…
Q: Write a simple java program with the following specifications: In the main method add the following…
A: According to the Question below the Solution: As per our company guidelines we are supposed to…
Q: ite a simple java program with the following specifications: In the main method add the following…
A: In the main method add the following declarations: int[ ] arr1 = {1,2,3,4,5,6,7,8,9,10}; int[ ]…
Q: Create a flowchart for this Java program. public class QexamA { /** * @param args the command line…
A: Flowchart: It can be defined as separate steps of a process in sequential order and that can be…
Q: Create a program in Java that implements Polymorphism and asks the users input to compute the wages…
A: Given: Create a program in Java that implements Polymorphism and asks the users input to compute the…
Q: here is my Java program.I don't know what's wrong, I can't run it. package four;public class…
A: Assumption: - Since any specific editor is not mentioned, I am working in Eclipse. ISSUE: - The…
Q: The java program is saved as ExampleAssignment.java. Complete the missing lines of code for the…
A: Given data, The java program is saved as ExampleAssignment.java public class ___________________ {…
Q: // Step 1: Import the Java Scanner class /** * The Java program inputs the original cost for a sale,…
A:
Q: Write the appropriate METHOD HEADINGS using the provided method name for the following processes.…
A: The method headings provide the method name, the input parameters and their data types, and the…
Q: Write a Java program that implements the system shown in the following UML class diagram, which…
A: //Nameable.java public interface Nameable { void name(String name);String name();}interface Moveable…
Q: 1. What is the output of the following program? Explain why? public class Boy{ int age = 10; }…
A: //lets trace the code for outputpublic class Boy{ int age=10;//data member}public class School{…
Q: 9. Consider the method headings: void funcOne(int [] alpha, int size) int funcSum(int x, int y) void…
A: In Java static methods are called normally but the methods which are not static are called through…
Q: Complete the following program in java to implement the user interface of the preceding exercise.…
A: A Java program is as follows, File name: “UnitConverter.java” import java.util.Scanner; import…
Q: PROGRAM Employee.java //Abstract class Employee abstract class Employee { // Attributes of the…
A: Answer: our guidelines is answer the first three sub part form the first part. So I have converted…
Q: Write a C++ program to read two lengths l1, l2 in the form of meters and centimeters by using a…
A: #include<iostream>using namespace std; class Length { public: int meter; int…
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: Given an incomplete program in Program 2, complete the program by filling in the blanks with an…
A: (a) The following statement can be used to declare a class Flower1 that inherits or extends the…
Q: 1) Show and explain the output in Java program below: public class Exercisel { public static void…
A: According to the Question below the solution: Output:
Q: 2. What is the output of the following program? Explain why? public class Boy{ static int age = 10;…
A: Output of above is : Age = 10 Age = 12 Age = 12
Q: 1. Compute and return the average speed of a car, given the distance traveled (as type double) and…
A: There are three parameters to represent distance, hours and minutes and we return average speed So…
Q: Write a C++ program to read two objects -lengths l1, l2 in the form of yards and foots by using a…
A: Programs: Programs are used to read the input from the user, process the input according to the…
Q: QUESTION 3: Advanced Java Programming Analyse the following Java code segment and answer the…
A: Dear Student, Error is present in the line numbers 4,10 and 11. You also need to import…
Q: .What will be the output when the following program is executed? public class Recur{ public…
A: using the function the code is called directly and indirectly which is called the recursive function…
Q: 1. Class Human: a. Fields: age (int), weight (double), height (double) b. Methods: getAge,…
A: Answer: Below is the solution to the problem in Java:
Q: Complete the below code in such a way to produce output 2 public class Main public static void…
A: This is a JAVA langauge problem. In this question, we have to fill in the two blanks. So that the…
Q: Convert this Java Program below into simplest form. It should still produce the same result as…
A: Your Java program is given below in easy form with a same output.
Q: Write the output of the following program, as it would appear on the console. import java.util.*; //…
A: Your output of the java program is given below as you required.
Q: Solve the question with python Design Foodcart class and Food class so that the following code…
A: Actually, python is a easiest programming language. It has a concise(less) code. It is a…
Q: Question public class MyProgram ( public static void main(String[] args) { int h=10, t-22;…
A: Answer the above question are as follows:
Q: Write a Java program that solves a set of quadratic equations as per Requirement #1 (without using…
A: import java.util.Scanner; public class Tester{ public static void main(String[] args){ Scanner…
Q: Problem 1) The following Java Code class is given public class Point { private int xCor; private int…
A: public class Point { private int xCor; private int yCor; public Point(int x,int y) { this.xCor=x;…
Q: Write a C++ program with classes to find the roots of a degree 2 polynomial ( a x+bx+c%3D0, ). Use…
A: The Complete code is given below with the output.
Q: Review Methods, Implement the following code, make sure it runs without errors. 3 import…
A: Solution: Java code to calculate sum of three numbers: Main.java import java.util.Scanner;…
Q: (I want to draw a flow chart for these codes ) import java.util.Scanner; public class Main {…
A: Flow Chart is a pictorial representation of the flow of a problem Here we are mostly using menus and…
Q: Please write the script and introduction for the program so that the number of words is between…
A: We need to write an introduction and functionality for the given program.
Q: Java provides a set of methods in the Graphics class that make it easy to draw geometric figures…
A: To draw the given geometric figures using Graphics class of JAVA. The code is written in the…
Q: A two-dimensional random walk simulates the behavior of a particle moving in a grid of points. At…
A: A java program that takes an integer command-line argument “n” and simulates the motion of a random…
Q: 1.Is "balance" the same, yes or no, why? class CheckingAct{ . . . . private int balance; . . . .…
A: Please only post one part in one question. we are not allowed to solve more than one question in one…
Q: III. Write the appropriate method (Java) headings using the provided method name for the following…
A: Solution 1. float getAverageSpeed(int distance, int hours,int minutes) float : return type…
Q: Write a program using classes ,methods and objects concept to do the following tasks. a) Read input…
A: In Java, Math. pow() is used to calculate a number raise to the power of some other number.…
Q: What will be the output of the following program snippet: With static scoping a) 2 4 b) 3 1…
A: Please upvote. I am providing you the correct answer below. Please please please.
Q: 3. Write a java program as in the next class diagram, such as: SimpleCalc2 SimpleCalc2() method only…
A: ALGORITHM:- 1. Create class SimpleCalc2(). 2. Define all the member functions inside it. 3. Test the…
Q: (IN JAVA) Run the following program to find the output public class FinalProgramTwo { public…
A: Refer to step 2 for the answer.
Q: Why the given Java code is not getting compiled and giving error? Remove the errors as well. class…
A: There are two errors in the given code: The first error is the wrong initialization of the array.…
Q: Select the correct output of the given code below: public class Person{ public void talk () {…
A: public class Person{ public void talk(){ System.out.println("I am a Person");} } public…
Q: Step 1: Import Java classes Arrays, Random, and Scanner /** * A class to generate a random int array…
A: The exception, InputMismatchException is a java in-built exception class and it is in the java. util…
Q: Write a Java program that implements the system shown in the following UML class diagram, which…
A: The question seems incomplete, specifically the functionality playNextMatch and which team it should…
Q: Java Questions - Based on each code, which answer out of the choices "A, B, C, D, E" is correct.…
A: Note: we are only allowed to solve one question in one post. I am solving the first on here. To get…
Java
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 1 images
- (Java) Q 4,5 COMPLETE BOTH STEPS Explain the answer step-by-step and include verbal explanation. Thank you! Given the below class: public class Dog { private String name; private double weight; private static int numDogs = 0; public Dog(String name, double weight) { this.name = name; this.weight = weight; numDogs++; } public String getName() { return name; } public double getWeight() { return weight; } public static int getNumDogs() { return numDogs; }public static void increaseNumDogs() {numDogs++;}public void printGreeting() { System.out.println("Woof!"); } @Override public String toString() { return "Name: " + name + "\nWeight: " + weight; }} Add a method call to getNumDogs to the below starter code: public class DogTest {public static void main(String[] args) { Dog fluffy = new Dog("Fluffy", 10); int num = //call getNumDogs method here }} Then, add a method call…Using Jcreator, open, compile, and run java and observe its runtime. Write your observation regarding how encapsulation works for the program and the data it processed. Limit your paper to a single paragraph with at least 50 words or five (5) sentences. Source code: public class EncapTest { private String name; private String idNum; private int age; public int getAge() { return age; } public String getName() { return name; } public String getIdNum() { return idNum; } public void setAge( int newAge) { age = newAge; } public void setName(String newName) { name = newName; } public void setIdNum( String newId) { idNum = newId; }} public class RunEncap { public static void main(String args[]) { EncapTest encap = new EncapTest(); encap.setName("James"); encap.setAge(20); encap.setIdNum("12343ms"); System.out.print("Name : " + encap.getName() + " Age : " + encap.getAge()); }}what is the output of the following codes : code 1. class A { { System.out.print(1); } } class B extends A { { System.out.print(2); } } class C extends B { { System.out.print(3); } } public class MainClass { public static void main(String[] args) { C c = new C(); } } code 2 class M { int i; public M(int i) { this.i = i--; } } class N extends M { public N(int i) { super(++i); System.out.println(i); } } public class MainClass { public static void main(String[] args) { N n = new N(26); } } code 3 class M { int i; public M(int i) { this.i = i--; } } class N extends M { public N(int i) { super(++i); System.out.println(i); } } public class MainClass { public static void main(String[] args) { N n = new N(26); } }
- Write the Java program: Make sure to have proper code indentation. Code: class Main { public static void main(String[] args) { Tile t1, t2, t3, t4, t5; int totalValue; t1 = new Tile('H', 4); t2 = new Tile('E', 1); t3 = new Tile('L', 1); t4 = new Tile('L', 1); t5 = new Tile('O', 1); totalValue = t1.getValue() + t2.getValue() + t3.getValue() + t4.getValue() + t5.getValue(); System.out.print("The word "); System.out.print(t1.getLetter()); System.out.print(t2.getLetter()); System.out.print(t3.getLetter()); System.out.print(t4.getLetter()); System.out.print(t5.getLetter()); System.out.println(" is worth " + totalValue + " points"); if(t4.equals(t3)) { System.out.print("It has two of these: "); System.out.println(t4); } else { System.out.print("Error: " + t3.toString() + " and ");System.out.println(t4.toString() + " aren't equal."); } }} /* SAMPLE OUTPUT The word HELLO is worth 8 pointsIt…Show the output of the following programs. (Hint: Draw a table and list the variables in the columns to trace these programs.) (java language)(a)public class Test {public static void main(String[] args) {for (int i = 1; i < 5; i++) {int j = 0;while (j < i) {System.out.print(j + " ");j++;}}}} (b)public class Test {public static void main(String[] args) {int i = 0;while (i < 5) {for (int j = i; j > 1; j--)System.out.print(j + " ");System.out.println("****");i++;}}} (c)public class Test {public static void main(String[] args) {int i = 5;while (i >= 1) {int num = 1;for (int j = 1; j <= i; j++) {System.out.print(num + "xxx");num *= 2;} System.out.println();i--;}}} (d)public class Test {public static void main(String[] args) {int i = 1;do {int num = 1;for (int j = 1; j <= i; j++) {System.out.print(num + "G");num += 2;} System.out.println();i++;} while (i <= 5);}}WRITE A JAVA PROGRAM Methods can be used to define reusable code and organize and simplify code. Problem:- Suppose that you need to find the sum of integers from 5 to 15, from 16 to 30, and from 31 to 39, respectively. Define a public static sum method that take two int parameters -> (int start, int end) In the method, use for loop to add all the number from start to end. Later, invoke the sum inside the main method. Do the sum for each a) 5 to 15; b) 16 to 30; and c) 31 to 39 separately and later print the results. Output: Sum from 5 to 15 is 110 Sum from 16 to 30 is 345 Sum from 31 to 39 is 315
- Trace and document every step of execution of the following program: public class Trace { public static void main(String[] args) { int[] num = {1, 3, 6, 9, 12 }; for (int i = 4; i >= 0; i--) { num[i] +=1; } num[0] *=num[4]; } }here is my Java program.I don't know what's wrong, I can't run it. package four;public class Employee{ public String name;public int salary;public Employee(){ name ="Unknown";salary = 0;}public Employee(String n,int s){ name = n;salary = s;}void showEmployee(){System.out.print("name:"+name+" ");System.out.print("salary:"+salary+" ");}}class Manager extends Employee{ public String position;public Manager(){ position="unknown"; }public Manager(String n,int s,String p){ super(n,s);position=p; }void showManager(){System.out.println("position:"+position);}}class Demo7_2{public static void main(String args[]){Manager m1=new Manager();Manager m2=new Manager("Bob",4000,"Sales Manager"); m1.showEmployee();m1.showManager();m2.showEmployee();m2.showManager();}}1/ 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. 2/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 the constructor, and the initial fuel level is 0. Supply a method drive that simulates driving the car for a certain distance, reducing the amount of gasoline in the fuel tank. Also supply methods…
- Solve the question with python Design Foodcart class and Food class so that the following code provides the expected output.cart1 = Foodcart()food1 = Food('Burger','Chillox',180)food2 = Food.createFood('Cake','Mr. Baker',1000)print("===========================")print(food1)print("===========================")cart1.addFood(food1,food2)print("===========================")cart1.setCartName("Foodpanda")cart1.addFood(food1,food2)cart1.addFood(Food('Steak','Woodhouse Grill',2000))print("Total Price Available:",Foodcart.totalPrice)print("===========================")print("Total Foods created:",Food.totalFoods)print("===========================")cart1.printCartDetails()print("===========================")cart1.removeFood("French Fry")print("===========================")cart1.removeFood("Steak")print("===========================")cart1.printCartDetails()print("===========================")print("Total Price Available:",Foodcart.totalPrice)Java Questions - Based on each code, which answer out of the choices "A, B, C, D, E" is correct. Each question has one correct answer. Thank you. Part 1 - 6. Given the following code, the output is __. class Apple { int x = 15; }class Banana extends Apple { int x = 25; }public class Sample {public static void main(String[] args) {Apple a1 = new Banana();System.out.println(a1.x);}} A. Compiler errorB. 25C. 15D. 0E. None of the options Part 2 - 7. Which is possibly a composite class? class Seed { ... }class Fruit { Seed s1 = new Seed(); }class Apple extends Fruits { ... }class Orange extends Apple { ... }class ApplePie { ApplePie a1 = new ApplePie(); } A. FruitB. AppleC. ApplePieD. OrangeE. Seed Part 3 - 10. Given the following code, which statement is true? class Water() { ... }class Juice() extends Water { ... }class Apple() { ... }class ApplePie() { Apple a1 = new Apple(); }class AppleJuice() { Apple a1 = new Apple(); Water w1 = newWater(); } A. Juice is a superclass and Water is a…Manually trace the execution of the following Java code segment: (c) if the following method is declared: public static void drawLine(int num, char ch) { for (int i = 1; i <= num; i++) { System.out.print(ch); } } What does the statement drawLine(10, ‘$’) do?