1.Write EBNF descriptions for the following:
A) Java class definition statement
B) Java method call statement
C) Java method header
D) C switch statement
E) C++ class declaration statement
F) C# Constructor declaration statement
A) Java class definition
public class A extends B implements C,D
where
public is modifier
A,B,C,D are identifiers
Assume non-terminal id as <id>
The definition becomes
[public] [(final|abstract)] class <id> [extends <id>] [implements <id> {, <id>}]
2) Java method call statement
<for> -> for ‘(‘ [[<type>] <id> = <expr> {, [<type>] <id> = <expr>}] ; [<expr>] ; [<expr>{, <expr>}] ‘)’ ‘{‘ <stmt_list> ‘}’
3)
The following is an example switch statement:
switch (a+b)
{
case 1 : x = 7; break;
case 2 : x = 8; break;
default : x = 9;
}
where “a+b” is an expression,
“1” and “2” are literals,
and “x=7;break;”, “x=8;break;” and “x=9;” are statement lists.
Assume non-terminals are <expr>, <literal>, and <stmt_list>
<switch> -> switch ‘(‘ <expr> ‘)’ ‘{‘ {case <literal> : <stmt_list>} [default : <stmt_list>] ‘}’
1.Write EBNF descriptions for the following: A) Java class definition statement B) Java method call statement...
In JAVA Algorithm Workbench 1. Write the first line of the definition for a Poodle class. The class should extend the Dog class. 2. Look at the following code, which is the first line of a class definition: public class Tiger extends Felis In what order will the class constructors execute? 3. Write the statement that calls a superclass constructor and passes the arguments x, y, and z. 4. A superclass has the following method: public void setValue(int v) value...
Assume that you have a String "name" attribute in a Java class definition. Write a public method to return this "name" attribute. public String getName() { return name; } 1.) Write a statement that throws an IllegalArgumentException with the error message “Argument cannot be negative”. 2.) The method getValueFromFile is public and returns an int. It accepts no arguments. The method is capable of throwing an IOException and a FileNotFoundException. Write the header for this method.
5. Given the following class definition, write Java code that implements the addFirst method public class MyLinkedList<E> { private Node<E> head, tail; private int size 0; // Number of elements in the list /** Add an element to the beginning of the list */ public void addFirst (E e) { private static class Node<E> { E element; Node<E> next; public Node (E element) { = element; this.element
Consider the Rectangle2 java class definition below. Write the definition of an equals) method that checks if two Rectangle objects have the same dimensions Write a Java program to test the equals method public class Rectangle2 K private int width, length; public Rectangle2(int w, int 1) { setWidth(w); setLength(1); System.out.println("Inside parameterized!!!"); } public void setWidth(int w) { width = w;} public void setLength(int i) { length = 1;} int getWidth() { return width; } int getLength() { return length; }...
Q 4(b) 6 Marks] Write the code for a single Java class of your own choice that demonstrates the use of the following features in the Java language: Method overloadingg The use of super and this Identify clearly where in your code each of these points is being demonstrated Q 4(c) [6 Marks] Write an abstract Student class in Java which has a name, id_number, year and programme_code as member variables. Add a constructor to your class and a display()...
JAVA 1. Given the following class definition, what are the contents of the fields x and y of the object p ? class MyPoint { int x; int y; public MyPoint (int x, int y){ x = x; y = y; } --------------------------------------- MyPoint p = new MyPoint( 100, 88 ); 2. static and non-static members What would happen if you tried to compile and run the following code ? public class Driver {...
Working in java programming. I have a class (call it manage) that takes in an arraylist (list) and a boolean (switch), which is created/preset in the parent main function above this class. The arraylist is modified and returned to the main function however, hence it's name 'manage.' I need help declaring the arraylist in the constructor? public class manage{ public manage(){ //Constructor // What is arraylist construction? this.switch = false; } public manage(ArrayList<Integer> list, boolean switch) { this.list = list;...
QUESTION 1 In Java, all variables declared using a class are ____. a. reference variables b. constants c. primitive variables d. operators 1 points QUESTION 2 An expression such as str.length(); is an example of a(n) ____. a. system call b. method call c. object call d. class 1 points QUESTION 3 Consider the following statements. double x; String y; y = String.format( "%.2f", x); If x = 285.679, what is the value of y? a. "285.00" b....
QUESTION 21 In the Java programming language method overriding occurs when (a) and precedes the call with an @Override annotation a method in a child class calls the method of the same name in one of its ancestor classes (b) when a class defines an abstract method and precedes the declaration with an @Override annotation two or more methods of a class have the same name but different signatures and both of (c) them are marked with an @Override annotation...
1) Consider the following Java program: 1 public class HelloWorld { 2 // My first program! 3 public static void main(String[] args) { 4 System.out.println("Hello, World!"); 5 } 6 } What is on line 1? a. a variable declaration b. a statement c. a method (subroutine) definition d. a comment e. a class definition 2) Which one of the following does NOT describe an array? a. It can be used in a for-each loop. b. It has a numbered sequence...