How many employee objects exist in the heap

Assignment Help JAVA Programming
Reference no: EM13939976

public class Syntax2
{
private int x, n;

public Syntax2(int a, int b)
{
x = a;
n = b;
}

public int sumofsquares(int x, int y)
{
return x * x + y * y;
}

public int nTimesProduct(int x, int y)
{
return n * x * y;
}

//test program
public static void main(String[] args)
{
Keyboard kbd = new Keyboard();
System.out.println("Enter two numbers ");
int m = kbd.readInt();
int n = kbd.readInt();
System.out.println("The result is: " + sumofsquares(m, n));
System.out.println("The other result is: " + nTimesProduct(m, n));
}

}

The above code has the following two errors:

Syntax2.java:39: non-static method sumofsquares(int,int) cannot be referenced from a static context: System.out.println("The result is: " + sumofsquares(m, n));

Syntax2.java:40: non-static method nTimesProduct(int,int) cannot be referenced from a static context: System.out.println("The other result is:" + nTimesProduct(m, n));

How do you rewrite this code so that it compiles and runs correctly, without making the sumofsquares and nTimesProduct methods static.

-----------------------------

Assume you have a class called Employee whose constructor takes two arguments: the employee's name and id number. Consider the following code fragment:

Employee [ ] ea = new Employee[20];
Employee emp1 = new Employee("Bob Jones", 34532);
Employee emp2 = emp1;
ea[0] = emp1;
ea[1] = emp2;

How many Employee objects exist in the heap in the above code? _______

What is the total number of all objects in the heap in the above code? _______

Reference no: EM13939976

Questions Cloud

Manufacture and retail own-branded barbecues and products : The first opportunity is to manufacture and retail own-branded barbecues and products. Manufacture would take place at a leased plant in India as BBQfun has no manufacturing capability. Also, manufacture in Australia would be too expensive.
Rewrittting codes in java : However, I am told the above code would not be written by an experienced Java programmer because the showMessageDialog method is static within the class. How would a pro would write it?
Application of revenue management in hospitality industry : In the past few years there has been a rapid development in the application of revenue management in the hospitality industry, and this can be supported by the volume of material published in this area.
Interactive natural cubic spline : My project depends on previous homework because of that I posted all the questions to be clear, but the main project that I need help with is the homework3
How many employee objects exist in the heap : Assume you have a class called Employee whose constructor takes two arguments: the employee's name and id number
Prepare a statement of cost of goods manufactured for april : Prepare a statement of cost of goods manufactured for April. Assume that the begin- ning balance in the raw materials account was $1,400 and that the beginning bal- ance in the work-in-process account was zero.
Write a payroll applicaion in java : The program should allow the user to enter information for any number of employees in this manner.
Discuss the critical points within service delivery process : Identify and discuss the critical points within the service delivery process that are likely to have a significant bearing on the customer's experience.
Using visual studio for pc,inside the visual c++ : Data and Code to be used for this assignment 3 are attached. Using Visual Studio for PC,Inside the Visual C++ option, we want to select a Win32 Console Application.

Reviews

Write a Review

JAVA Programming Questions & Answers

  Run both c++ and java versions of your program

In C++, create an Exception class, and a DivideByZero sub-class that takes a string for its constructor, and use this in the try-catch mechanism. In Java, use the division by zero exception object.

  Create a class named blooddata that includes fields

Create a class named BloodData that includes fields that hold a blood type (the four blood types are O, A, B, and AB) and an Rh factor (the factors are + and -). Create a default constructor that sets the fields to "O" and "+", and an overloaded c..

  Extend the vending machine

Your task for this assignment is to extend the "Vending Machine" you wrote for assignment seven to add the ability to hold the snacks

  Java program to print strings given at command line

Write down program Average.java to print strings which it is given at command line, one per line. If nothing is given at command line, then print "No arguments".

  Credit card expenses

You started recording every credit card transaction so that you can analyze your monthly expenses. You used an Excel worksheet to track dates, places, categories, and amounts. Because you are a consultant who travels periodically, you also have bu..

  Write a program that reads in a text file and then computes

Write a program that reads in a text file and then computes and prints a table of letter frequencies. For example, if the file is the text of "A Tale of Two Cities", found in the file at data/tales.txt , the program will print

  Create a complete java application that meets these

create a complete java application that meets these requirements1. the program has an opening comments section using

  Write a program that reads a set of floating-point

Write a program that reads a set of floating-point data values from the input.

  What could you do to kill more mutants

What are the implications related to suite of unit test cases when some mutants are not killed and What could you do to kill more mutants?

  Prepare a main method that tests all of your functions

A method that outputs the name and list of all patients - A method that resets the number of patients to 0 and the patientList to an empty list - Prepare a main method that tests (i.e, unit testing) all of your functions.

  Write java program to store employee id number

Use employee data file called employees.txt should comprise at least 5 employee records. Each record stores employee ID number (six digits) last name, first name, middle inital,gender(m or f).

  Eax contains the given contents before the instruction

For each add instruction in this problem, assume that EAX contains the given contents before the instruction is executed, and give the contents of EAX as well as the values of the CF, OF, SF, and ZF flags after the instruction is executed:

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd