### and @@@ and ?

how do I calculate this java exam question, these examiners make it ha

  • (2 Pages)
  • +
  • 1
  • 2

20 Replies - 1178 Views - Last Post: 08 June 2009 - 08:08 PM Rate Topic: -----

#1 BrianNeedsJavaHelp  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 08-June 09

### and @@@ and ?

Post icon  Posted 08 June 2009 - 06:54 PM

Hi my name is Brian, I have some previous multiple choice questions from a java exam
I assume anyone who knows a thing or two about java could help me by ripping through them or even having an educated guess at them. . any help would be orsm

SECTION A — MULTIPLE CHOICE QUESTIONS
Attempt ALL questions from Section A. Each question is worth 1 mark.

Question 1

Consider a program with the following declarations and statements in the main()
method.

Scanner key;
int[] values;
Turtle t1;
sc = new Scanner(System.in);
String s="x";

Which of the following is true?

A There are 0 variables of a primitive type declared and 4 reference
variables declared.
B There is 1 variable of a primitive type declared and 3 reference
variables declared.
C There are 2 variables of primitive types declared and 2 reference
variables declared.
D There are 3 variables of primitive types declared and 1 reference
variable declared.
E There are 4 variables of primitive types declared and 0 reference
variables declared.



Question 2

Consider a Java program with the following code. The actual values assigned are
omitted — they are indicated by ???, ###, and @@@

int max = ###;
int current = 1;
for(int mult = ???; mult <= max; mult = mult + 1)
{
current+=@@@;
System.out.println(current);
}

What expressions will need to be assigned so that the output when the code is
executed will be:
2
4
8
16
32

A ??? = 0 ### = 3 @@@ = mult
B ??? = 0 ### = 4 @@@ = current
C ??? = 1 ### = 4 @@@ = current
D ??? = 1 ### = 5 @@@ = mult
E ??? = 2 ### = 6 @@@ = current



Question 3
Suppose that you have a program with the following declarations and initialisation:
int outer = 0;
int inner = 0;

What values will these variables have after the following code is executed? (You
may assume that it is included in an otherwise correct Java program.)

for (int oC = 0; oC <= 2; oC = oC + 1)
{
for (int iC = oC; iC >= 0; iC = iC - 1)
{
inner = inner + 1;
}
outer = inner - 1;
}
A inner 2
outer 1
B inner 3
outer 2
C inner 4
outer 3
D inner 5
outer 4
E inner 6
outer 5



Question 4
Consider a program with the following declarations and statements in the main()
method:

char[] chars;
char char1 = '1';
int char2 = 2;
chars = new char[char2];
chars[1] = char1;

Which of the following is true?

A chars refers to an array with 1 character element.
B char2 is illegally defined.
C chars.length() is equal to 2.
D The first element of the array chars contains the value '1'.
E The last element of the array chars contains the value '1'.



Question 5

Consider a Java application with the following declarations and code in the main()
method. What will appear on the screen when the code is executed? (You may
assume that it is included in an otherwise correct Java program.)

String s, t, u;
s = new String("low");
t = new String("bow");
u = new String("sew");
if (s.indexOf('o') == -1)
{
t = new String("woe");
}
else
{
t = new String("doe");
if (s == "low")
{
u = new String("mow");
}
else
{
u = new String("row");
}
}
System.out.println(t);
System.out.println(u);

A bow
sew
B woe
sew
C doe
mow
D doe
row
E None of the above.



Question 6
Suppose that a class had been defined that has the following instance data declared:
final String WORD = new String("Hidden");
char w='w';
String word;
and a method with the header:
public String delete(String s, char x)

Which of the following would be a valid call to this method (when included in the
code of another method within the class)?

A WORD = delete(WORD,'w');
B word = delete(word, "w");
C WORD = delete(WORD, w);
D word = delete(word, w);
E WORD = delete(word, 'w');

This post has been edited by BrianNeedsJavaHelp: 08 June 2009 - 06:57 PM


Is This A Good Question/Topic? 0
  • +

Replies To: ### and @@@ and ?

#2 BrianNeedsJavaHelp  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 08-June 09

Re: ### and @@@ and ?

Posted 08 June 2009 - 07:03 PM

Hi my name is Brian, can any 1 help me with some previous exam multiple chioce q's?
even just a guess and letting me know would be soooo orsm. cheers :^:

SECTION A — MULTIPLE CHOICE QUESTIONS
Attempt ALL questions from Section A. Each question is worth 1 mark.

Question 7
Consider a method with the following header:
public boolean character(double integer)

Which of the following is true?

A The method will not return a value.
B The method has a double parameter with the formal identifier
integer.
C The method has a double parameter with the actual identifier
integer.
D The method has a boolean parameter with the formal identifier
character.
E The method has a boolean parameter with the actual identifier
character.



Question 8

Consider the following Java class declaration.
public class Q8
{
private int x = -8;
public Q8()
{
int x;
x = 8;
}
public void m8(int x)
{
x = 88;
}
}

After an object of class Q8 has been instantiated and the method m8() run with an
actual parameter value of 0, what is the value of that object’s instance variable x?

A 0
B 8
C -8
D 88
E The code has syntax errors and would not compile.



Question 9
Consider a program with the following declarations and initialisations in the
main() method.

int number = 10;
int divisor = 3;
double answer;

A programmer has been given the task of writing a statement that will correctly
determine the exact number of times the variable number is divisible by the variable
divisor assigning the answer to the variable answer. Which of the following will
do the job?

A answer = number / divisor;
B answer = number % divisor;
C answer = (double)(number / divisor);
D answer = (double)(number % divisor);
E answer = ((double)(number)) / divisor;



Question 10
Consider a program with the following code in the main() method:
(The program includes the import statement: import java.util.Scanner;)
Scanner sc = new Scanner(System.in);

int x = 0;
int num;
System.out.print("Enter an integer value: ");
try
{
num = Integer.parseInt(sc.nextLine());
x = num;
}
catch (NumberFormatException e)
{
x = 99;
}
System.out.println("x is: " + x + " num is: " + num);

What output will be seen on the console after the user enters 13 when prompted?

A x is: 0 num is: 0
B x is: 13 num is: 13
C x is: 99 num is: 99
D x is: 13 num is: 0
E x is: 99 num is: 13
Was This Post Helpful? 0
  • +
  • -

#3 jcmaster2  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 183
  • Joined: 27-April 09

Re: ### and @@@ and ?

Posted 08 June 2009 - 07:14 PM

Why don't you type the code into a Java compiler...run it and find the answer

Might actually be faster than waiting for us to post the solutions for you...

common sense?
Was This Post Helpful? 0
  • +
  • -

#4 BrianNeedsJavaHelp  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 08-June 09

Re: ### and @@@ and ?

Post icon  Posted 08 June 2009 - 07:14 PM

KXT101 Programming & Problem Solving
Page 11 of 17
continued…

CAN N E BODY HELP ME I DONT UNDERSTAND THIS/THESE PAST EXAM QUESTIONS
IF YOU COULD EVEN POST AN IDEA FOR ME IT WOULD BE ORSM. BRIAN

Question 14
An X-Ray machine sends x-rays in bursts 1 second long. Bursts commence when the
X-Ray machine operator presses a button on his computer screen’s GUI. After an xray
burst has been transmitted, staff should wait 5 seconds for the rays to dissipate
before entering the room. The operator’s computer screen displays the message
“STOP” when x-rays are being sent, “WAIT” when less than 5 seconds has elapsed
since x-rays have been sent, and “ENTER” at all other times. Outside the room
containing the X-Ray machine there is a monitor that displays the messages shown
on the X-Ray machine operator’s computer screen’s GUI.
You must provide a software implementation for the control of the X-Ray machine.
To help, there is a method System.sleep() which accepts a single double
parameter indicating the number of seconds the program should wait/sleep for.


a Write the class definition for the XRayController class including the class
header, any final variables and instance variables. The class should be a subclass
of PPSFrame and should implement the ActionListener interface.
[3 marks]

b Fully define a constructor method to allow a XRayController object to be
created.
[3 marks]

c Fully define the paintComponent() and actionPerformed() methods to
display the appropriate message, wait the relevant number of seconds, change
the mode and refresh the screen.
[6 marks]
Was This Post Helpful? 0
  • +
  • -

#5 KYA  Icon User is offline

  • g++ jameson.cpp -o beverage
  • member icon

Reputation: 3105
  • View blog
  • Posts: 19,144
  • Joined: 14-September 07

Re: ### and @@@ and ?

Posted 08 June 2009 - 07:16 PM

1. This is a java question.

2. Show us what you've tried so far, which specific questions as to where you are stuck and we'll be more then happy to assist.
Was This Post Helpful? 0
  • +
  • -

#6 BrianNeedsJavaHelp  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 08-June 09

Re: ### and @@@ and ?

Posted 08 June 2009 - 07:19 PM

BUT TO COMPILE ANY OF THOSE QUESTIONS REQUIRES OTHER CODE WHICH I CANNOT DO EITHOR!!!
IF YOU ARE ANY GOOD AT JAVA I ASSUME ALL IT WOULD TAKE IS TO READ THE QUESTION AND THE ANSWER OR POSSIBLE ANSWER WOULD BE OBVIOUS?
Was This Post Helpful? 0
  • +
  • -

#7 no2pencil  Icon User is online

  • Admiral Fancy Pants
  • member icon

Reputation: 5346
  • View blog
  • Posts: 27,296
  • Joined: 10-May 07

Re: ### and @@@ and ?

Posted 08 June 2009 - 07:24 PM

** Moved to Java **

Brian, just throwing this out there for topic, it doesn't look like you even made any attempt at answering these.

If you just throw your homework out here for other to take a look at then how do you expect to be able to pass the exam?

Please make a valid attempt at doing them, & then ask when you run into a specific problem. Also, please don't type all in caps.

Best of luck.
Was This Post Helpful? 0
  • +
  • -

#8 no2pencil  Icon User is online

  • Admiral Fancy Pants
  • member icon

Reputation: 5346
  • View blog
  • Posts: 27,296
  • Joined: 10-May 07

Re: ### and @@@ and ?

Posted 08 June 2009 - 07:26 PM

This is the 2nd post that Brian has started under C/C++ that is a Java question.

I would go so far as to guess that Brian has a problem reading directions :)
Was This Post Helpful? 0
  • +
  • -

#9 BrianNeedsJavaHelp  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 08-June 09

Re: ### and @@@ and ?

Post icon  Posted 08 June 2009 - 07:29 PM

Question 2

Consider a Java program with the following code. The actual values assigned are
omitted — they are indicated by ???, ###, and @@@

int max = ###;
int current = 1;
for(int mult = ???; mult <= max; mult = mult + 1)
{
current+=@@@;
System.out.println(current);
}

What expressions will need to be assigned so that the output when the code is
executed will be:

2
4
8
16
32

A ??? = 0 ### = 3 @@@ = mult
B ??? = 0 ### = 4 @@@ = current
C ??? = 1 ### = 4 @@@ = current
D ??? = 1 ### = 5 @@@ = mult
E ??? = 2 ### = 6 @@@ = current
Was This Post Helpful? 0
  • +
  • -

#10 no2pencil  Icon User is online

  • Admiral Fancy Pants
  • member icon

Reputation: 5346
  • View blog
  • Posts: 27,296
  • Joined: 10-May 07

Re: ### and @@@ and ?

Posted 08 June 2009 - 07:30 PM

Dream.In.Code has a policy by which we prefer to see a good faith effort on your part before providing source code for homework assignments. Please post the code you have written in an effort to resolve the problem, and our members would be happy to provide some guidance. Be sure to include a description of any errors you are encountering as well.

Please post like this:

Thank you for helping us helping you.
Was This Post Helpful? 0
  • +
  • -

#11 jcmaster2  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 183
  • Joined: 27-April 09

Re: ### and @@@ and ?

Posted 08 June 2009 - 07:30 PM

View Postno2pencil, on 8 Jun, 2009 - 06:24 PM, said:

** Moved to Java **

Brian, just throwing this out there for topic, it doesn't look like you even made any attempt at answering these.

If you just throw your homework out here for other to take a look at then how do you expect to be able to pass the exam?

Please make a valid attempt at doing them, & then ask when you run into a specific problem. Also, please don't type all in caps.

Best of luck.



Lets be honest...sounds like he wants us to do it for us..since has as not shown any initiative...

Probably will blame us or his teacher for doing so poorly...not himself which he should take some responsibility for..
Was This Post Helpful? 0
  • +
  • -

#12 no2pencil  Icon User is online

  • Admiral Fancy Pants
  • member icon

Reputation: 5346
  • View blog
  • Posts: 27,296
  • Joined: 10-May 07

Re: ### and @@@ and ?

Posted 08 June 2009 - 07:32 PM

Have some faith. At least his 3rd homework post was posted under the correct forum. Soon enough he'll realize that no one is going to do it for him.
Was This Post Helpful? 0
  • +
  • -

#13 BrianNeedsJavaHelp  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 08-June 09

Re: ### and @@@ and ?

Posted 08 June 2009 - 07:35 PM

THEY RE TOO HARD THANKS FOR LAUGHING AT ME
Was This Post Helpful? 0
  • +
  • -

#14 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8334
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: ### and @@@ and ?

Posted 08 June 2009 - 07:35 PM

So you want us to do your homework ?
This is against this forum policy rule #1 that was showed to you when you post your topic

"We will not do your homework for you! Do not ask us to give you code! "

and rule #4 says:
:code:

2 rules not respected out of 7 you are not in a good position :)
Was This Post Helpful? 0
  • +
  • -

#15 no2pencil  Icon User is online

  • Admiral Fancy Pants
  • member icon

Reputation: 5346
  • View blog
  • Posts: 27,296
  • Joined: 10-May 07

Re: ### and @@@ and ?

Posted 08 June 2009 - 07:37 PM

View PostBrianNeedsJavaHelp, on 8 Jun, 2009 - 08:35 PM, said:

THEY RE TOO HARD

What do you expect to learn if you don't try?

It isn't that the questions are too hard, it's that you have already given up before you tried.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2