asp.net c# Student 辅导讲解、代编程c# asp.net
解析Haskell程序|讲解留学生Prolog
PROGRAMMING FUNDAMENTALS – SAMPLE PRACTICAL TEST 1
ALL ANSWERS ARE TO BE WRITTEN ON THIS PAPER
PART A
Below is some code for the classes Student and Tutorial. You are required to add your own code to these classes and answer the following questions:
Q1. In the class Student, declare the class attributes id, name, numSubjects. Select the most appropriate data types for these attributes.
Q2. Create an alternate constructor for class Student that has 3 input parameters, one for each of the class attributes listed above. Initialise the class attributes to these input parameter values in the constructor of class Student.
Q3. In the class Student, create a procedure called displayName() that will display the name of the Student.
Q4. In the class Student, create a procedure called displayDetails() that will display the id and name of the Student. Both are to be displayed on one line.
Q5. In the class Student, create a function called updateSubjects() that will ask the user of the program to enter the number of subjects the Student is studying (use Scanner). The value must be entered as integer and returned by the function.
WRITE THE CODE FOR CLASS STUDENT ON THE NEXT PAGE?
class Student
{
}// End of class Student?
Q6. In the main method of class Tutorial, declare and create two Student objects (so two Student programs are loaded and running), call them anything you like. You must use the alternate constructor for Student to do this.
Q7. In the main method of class Tutorial, after creating the two student objects, call the procedure displayName() for each student object.
Q8. Now add extra code in the main method that calls the updateSubjects() function for each student object. The values returned from the function calls must be stored in two local variables. Use these variables to determine which student is studying the most subjects, then call displayDetails() for this student only.
WRITE THE CODE FOR CLASS TUTORIAL ON THE NEXT PAGE ?
class Tutorial
{
public static void main(String args[])
{
}
}// End of class Tutorial
?
PART B
Q1. Write down the correct way to declare and create an object using the following Constructor method headers:
Laptop(String model, double version, double cost)
Keyboard(int id, String type)
Account(int number, boolean current, double balance)
Phone(String name, double price, String code)
Car(String registration, double mileage, double cost)
Q2. What is wrong with this code? Correct all errors so the code will compile. More than one solution is possible.
Double amount = “3.75”;
if(amount = 100 || amunt => 50);
{
System.out.println("Amount is: " + amount);
}
else (amount == 3.75)
{
amount = 5.2;
System.out.println("Amount is: " + amount);
}