- What is wrong with the following variable declarations? (1 Mark). int Km*h = 90; String double = student1; int int1 = "50";
What is wrong with the following variable declarations? (1 Mark). int Km*h = 90; String double = student1; int int1 = "50";
Q1. What is wrong with the following variable declarations? (1 Mark).
int Km*h = 90;
String double = student1;
int int1 = "50";
String newCourse = "CS-140"
int y = x;
String 1_Car = "BMW";
Q2. What does this sequence of statements print? (1 Mark).
String msg = "The number of characters in the title of this course is: ";
String newCourse = "Computer Programming I";
int numberOfCharacters = newCourse.length();
String courseUpperCase = newCourse.toUpperCase();
System.out.print("Welcome to : ");
System.out.print("Good luck ");
//System.out.println(“to all students”);
System.out.print("for the course ");
System.out.println(newCourse); Ministry of Higher Education
Saudi Electronic University
College of Computing and Informatics Q3. Given the following Java code segment, answer the three questions below:
public class BankAccount
private double balance;
balance = 0;
} } public BankAccount(double initialBalance)
balance = initialBalance;
System.out.print("Balance is: ");
System.out.println(balance + 10);
1- Is “public BankAccount()” considered as a constructor? Why?
2- What is the output of "new BankAccount(10.5) ";
3- Write a method that may be used to withdraw an amount? (1 Mark).
Q4. Implement a class Employee. An employee has a name (string) and a salary
1- Write a default constructor.
2- Write a constructor with two parameters (name and salary).
3- Write methods to return the name and salary.
(1 Mark). Q5. In the 2- dimensional plane, a point is described by its two coordinates x and y.
It supports these operations:
- A constructor allowing initialization of coordinates
- 4 methods to set and get the values of the coordinates x and y
- Translation of a point
1- Write a class, called MyPoint that corresponds to an abstraction of points in
the dimensional plane.
2- Provide a tester class that creates one point, then translate and display the