当前位置:天才代写 > JAVA代写 > Java编程考试代写 EBU4201代写

Java编程考试代写 EBU4201代写

2022-07-22 15:37 星期五 所属: JAVA代写 浏览:116

EBU4201 Introductory Java Programming  

Java编程考试代写 Time allowed 2 hours Answer ALL questions Complete the information below about yourself very carefully. NOT allowed: electronic calculators and

Time allowed 2 hours  

Answer ALL questions  

Complete the information below about yourself very carefully.     

NOT allowed: electronic calculators and electronic dictionaries.  

 

Question 1

a)

Suppose you are writing a Java program for an art gallery. [15 marks]

i) Write a class called ArtWorkwhich has two attributes: name(which is a String), and creation_year (which is an integer) indicating when the artwork was created. Add accessor (getter) and mutator (setter) methods for each attribute. Use these appropriately in a constructor for ArtWork; the constructor takes two variables as input, which correspond to the name and creation year of an artwork, and sets the name and creation_year attributes accordingly.

ii) Add a method called ageto the ArtWorkclass in part i), which returns the age of an artwork object by subtracting its creation_year value from 2019. Briefly describe a problem with this method’s specification, and a solution for the problem.

b)  Java编程考试代写

This question uses some of the code you wrote for class ArtWorkin part a). Write the code for a tester class called ArtTesterwith a main method. In this class, an ArtWork object called “The Queen” from the year 1817 is constructed. The main method should also print out the age of the artwork. [4 marks]

c)

Answer the following questions about the Java programming language: [6 marks]

i) What is the difference between x++and ++x, in terms of their code behaviour?

ii) Why would someone use a breakstatement inside a switch?

iii) Briefly describe the reason for using the extends keyword.

 

Question 2  Java编程考试代写

a)

Answer the following questions about arrays and ArrayLists: [7 marks]

i) Indicate TWO differences between arrays and ArrayList

ii) Write Java code to place the following set of Strings into both an array called someArrayand an ArrayListcalled someAList: {twenty, ten, one}.

Note: Your code must include a declaration of all the relevant variables.

b)

This question is about access modifiers: [6 marks]

i) privateand publicare two of the access modifiers that can be used in Java. Explain the meaning of access modification in Java, by comparing the private and public access modifiers, including any advantages or disadvantages.

ii) How can you access an instance variable (attribute) if it is private?

iii) Often we may store a fixed variable (i.e. a constant value) marked as public final static. For example, a constant such as the absolute zero value of temperature (i.e. -273.14 Kelvin) would be written as shown in Figure 1. Will making this public cause any problem?

public final static double ABSOLUTE_ZERO = -273.14;

Figure 1

c)  Java编程考试代写

Assume the class Flowerhas already been implemented with the correct constructors and methods (e.g. public String getName()and public String toString()). What does the code fragment (in Figure 2) output to the screen? [3 marks]

Flower[] flowers = new Flower[3];
flowers[1] = new Flower("Rose");
System.out.println(flowers[1]);
System.out.println(flowers[2]);
System.out.println(flowers[3].getName());

Figure 2

d)

Given an array of intvalues, write a method that computes the maximum value. Hint: You should pay attention to the method header, return type, and the calculation itself. [6 marks]

e)

This section of the question is about Javadocs. [3 marks]

i) Write the command used to generate Javadoc comments, assuming that they are being generated for the file java.

ii) Give ONE example of a Javadoc tag, along with its description.

iii) Explain what a Javadoc is, and what is its purpose.

 

 

Question 3  Java编程考试代写

a)

State whether each of the following statements about Java interfaces is TRUE or [5 marks]

i) An interface is a collection of abstract methods.

ii) The functionality of an interface is fully specified.

iii) It is possible for an interface to extend another interface.

iv) An interface cannot be instantiated.

v) A class can only implement a single interface.

b)

This question is about Java memory management: [10 marks]

i) What are the TWO main areas of memory in Java? Give an example of what might be stored in each area.

ii) Assuming Car is a concrete class, consider the code fragment in Figure 3(with lines numbered 15) and answer the following sub-questions:

1.  Car c1 = new Car();
2.  Car c2 = new Car();
3.  Car c3 = c1;
4.  c1 = null;
5.  c2 = c3;

Figure 3

1) Indicate whether there are any objects eligible for garbage collection after executing the code in line 4 of Figure 3. Justify your answer.

2) Now assume that the code in line 5 of Figure 3 has also been executed. Are there any objects eligible for garbage collection? Explain.

c)  Java编程考试代写

The questions below are about Graphical User Interfaces (GUIs) in Java: [8 marks]

i) What are the THREE main concepts when doing GUI programming in Java? Your answer must also include a brief description of each concept.

ii) Briefly describe how the THREE concepts indicated in part i)are used together when designing a GUI.

d)

Consider the Java method in Figure 4(with lines numbered 1–4) and describe how recursive algorithmsare implemented in Java, using the code in Figure 4 as a reference example. Hint: You may want to refer to specific lines of code in your answer. [2 marks]

1.  public int recurse(int x) {
2.    if (x == 0) { return x; }
3.    else { return x + recurse(x-1); }
4.  }

Figure 4

 

Question 4  Java编程考试代写

a)

Answer the following questions about 2-dimensional arrays in Java. [4 marks]

i) Write the code to declare a 2-dimensional array named myStrings. This array should be capable of storing 10×10 String

ii) Imagine you wish to concatenate the Stringobjects in each element of the myStringsarray in part i). Write the Java code to concatenate all String objects into a single String object, and then print out the final results.

Note: You are not required to write a complete Java program.

b)

Answer the following questions about File Input/Output in Java: [10 marks]

i) Whenever performing I/O in Java, it is necessary to use tryand catch Explain why this is.

ii) Write a Java class called CountWriter. The class must generate a series of five sequential numbers (1, 2, 3, 4, 5) and write them to a file called txt. The class must first create a new file, and then write the numbers into the file. Each number should be placed on a separate line. Figure 5presents the data that the file count.txtshould contain, after your code has executed.

1
2
3
4
5

Figure 5

Note: You must use a for loop to generate the numbers. The file should be created in the same directory as the program. If the file already exists, then the program must display the message “File already exists” and then terminate the program.

c)  Java编程考试代写

Write the Java code for a simple GUI. This should include a JButtonthat is placed inside of a JFrame. The JButtonshould contain the text “Hello!“. You must also add event handling capabilities to your code: when a user clicks the button, the text in the button should change to “Bye Bye!“.

Note: You are not required to write a complete Java program. [5 marks]

d)

The questions below refer to exceptions and assertions in Java: [6 marks]

i) What is the output of the program inFigure 6(with lines numbered 1-13) when assertions are disabled and when assertions are enabled? Justify your answers.

1   public class AssertionTest {
2     public static void main(String[] args) {
3       try {
4         assert(false);
5       }
6       catch (Exception ex) {
7         System.out.println("Caught an exception!");
8       }
9       catch (Error err) {
10        System.out.println("Caught an error!");
11      }
12     }
13   }

Figure 6

ii) Write a new Exceptionclass called LargeDataException. This must be defined in a class file. You must also state the name of the file that you would write the code into.

Note: You only need to write the class declaration.

 

Java编程考试代写
Java编程考试代写

 

 

更多代写:美国MATLAB代上网课  gmat作弊  英国金融代考   英文论文写作代写  研究生英文演讲稿代写  留学Python程序代写

合作平台:essay代写 论文代写 写手招聘 英国留学生代写

 

天才代写-代写联系方式