Write a main()routine that uses the subroutine that you wrote for part (a) to output 10 lines of stars with 1 star in the first line, 2 stars in the second line, and so on, as shown below. ( 6 marks)
*_*_*_*_*_*_*_*_*_*
*_*_*_*_*_*_*_*_*
*_*_*_*_*_*_*_*
*_*_*_*_*_*_*
*_*_*_*_*_*
*_*_*_*_*
*_*_*_*
*_*_*
*_*
*
Write a subroutine named "stars" that will output a line of stars to standard output. (A star is the character "*".) The number of stars should be given as a parameter to the subroutine. Use for loop. For example, the command "stars(10)" would output (6 marks) *_*_*_*_*_*_*_*_*_*
Write pseudo code that print the largest value among a list of numbers.
7. Please complete the following codes (4 marks)
public class TestArray {
public static void main(String[] args) {
// create and initialize an array ‘myList’ with 4 elements. The values are the 4 elements are into 1.9,2.9,3.4 and 3.5
_______________________________
// Print all the array elements
for (double element: myList) {
System.out.println(element);
}
}
}
What is printed on execution of these methods?
Consider the following program written in Java to answer this
Question:
1. import java.util.*;
2. class Arraylist
3. {
4. public static void main(String args[])
5. {
6. ArrayList obj = new ArrayList();
7. obj.add("A");
8. obj.add("B");
9. obj.add("C");
10. obj.add("D");
11. System.out.println(obj);
12. }
13. } What would be the output of the statement when the program is executed?
What is the result of the following program?
Consider the following code fragment
Rectangle r1 = new Rectangle();
r1.setColor(Color.red);
Rectangle r2 = r1;
r2.setColor(Color.blue);
After the above piece of code is executed, what are the colors of r1 and r2 (in this order)?
Which of these access specifiers can be used for a class so that its members can be accessed by a different class in the different package?
A. Public
B. Protected
C. Private
D. No Modifier
Try to refactor below codes for computing score (underlined part) with extract methods
public class Customer
{
void foo()
{
int a, b, c, xfactor;
int score; Scanner myInput = new Scanner(System.in);
a = myInput.nextInt();
b = myInput.nextInt();
c = myInput.nextInt();
xfactor = myInput.nextInt();
System.out.println(“Computer score:”);
// Compute score score = a*b+c;
score *= xfactor;
}
}
3. The Car class (subclass) inherits the attributes and methods from the Vehicle class (superclass). And every car has model. Please also add toString method to the Car class to print out the brand, and model of the car.
Class Vehicle {
protected String brand; // Vehicle attribute
Vehicle() // Vehicle constructor
{
Brand = “Ford”;
}
public void honk() { // Vehicle method
System.out.println("Tuut, tuut!");
}
}
Please help write the Car class. (10 marks)
Write a subroutine named "printDayofWeek" that will output the day of the week for a given number. Use Swtich-case. For example, the command "1” would output “Sunday”. (10 marks)