Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Java Expert


Home >> Java

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? _______

Java, Programming

  • Category:- Java
  • Reference No.:- M91610850
  • Price:- $20

Priced at Now at $20, Verified Solution

Have any Question?


Related Questions in Java

Assignment taskwrite a java console application that allows

Assignment task Write a java console application that allows the user to read, validate, store, display, sort and search data such as flight departure city (String), flight number (integer), flight distance (integer), fl ...

Assignment - method in our madnessthe emphasis for this

Assignment - "Method in our Madness" The emphasis for this assignment is methods with parameters. In preparation for this assignment, create a folder called Assign_3 for the DrJava projects for the assignment. A Cityscap ...

Overviewyou are required to use java se 80 and javafx to

Overview You are required to use Java SE 8.0 and JavaFX to develop a Graphical User Interface (GUI) for the FlexiRent rental property management program created in Assignment 1. This assignment is designed to help you: 1 ...

Assignment game prototypeoverviewfor this assessment task

Assignment: Game Prototype Overview For this assessment task you are expected to construct a prototype level/area as a "proof of concept" for the game that you have designed in Assignment 1. The prototype should function ...

Can someone please help me with the following java

can someone please help me with the following java question The input is an N by N matrix of nonnegative integers. Each individual row is a decreasing sequence from left to right. Each individual column is a decreasing s ...

Chatbotscreate a small networked chat application that is

Chatbots Create a small, networked chat application that is populated by bots. Introduction On an old server park, filled with applications from the early days of the internet, a few servers still run one of the earliest ...

In relation to javaa what is constructor the purpose of

(In relation to Java) A. What is constructor? the purpose of default constructor? B. How do you get a copy of the object but not the reference of the object? C. What are static variables and instance variables? D. Compar ...

Retail price calculatorwrite a java program that asks the

Retail Price Calculator Write a JAVA program that asks the user to enter an item's wholesale cost and its markup percentage. It should then display the item's retail price. For example: (If an item's wholesale cost is 5. ...

Assessment socket programmingtaskwrite a java gui program

Assessment: Socket Programming Task Write a JAVA GUI program that would facilitate text chatting/exchanging between two or multiple computers over the network/internet, using the concept of JAVA socket programming. If yo ...

Question slideshows or carousels are very popular in

Question : Slideshows (or carousels) are very popular in websites. They allow web developers to display news or images on the website in limited space. In this code challenge, you are required to complete the JavaScript ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As