Question: 1. Write a Java conditional statement that implements the following Table 1. where grade is an integer and school is a string. Both variables have


1. Write a Java conditional statement that implements the following Table 1. where grade is an integer and school is a string. Both variables have been declared and grade has been initialized to a value greater than or equal to 1: Table 1 Set School to: If grade is 1, 2, 3, 4, Sekolah Rendah 6,7,8 Sekolah Menengah 9, 10, 11, 12 Sekolah Berasrama >12 Sekolah Prestasi Tinggi [4 marks] 2. Write code to read string (without spaces), double, and integer from a file into variables you declare using a Scanner object called input that has been instantiated and initialized. [2 marks] 3. Write a Java statement to assign the sixth character of the string variable b to a previously declared character variable named c. [2 marks] 4. Given a variable x declared as a double and initialized, show the code to cast and store the value of x into a variable y which is defined as a short. Truncation will occur, which is fine. [2 marks] 5. Write a loop that computes the average of an array of integers called iArray that has been previously declared and initialized. Store the result in a variable of type integer called iAverage that has been previously declared and initialized to zero. (5 marks] 6. Show the declaration for a method called myMethod that 1) is visible outside the class, 2) can only access class (static) variables, 3) returns an array of integers, and 4) accepts two parameters which are a String and double, in that order. (5 marks] 7. You are working for an online retail store that sells clothing. Your manager has asked you to modify the Customer class so that it assigns a new unique customer ID number when a customer object is created. The current implementation constructs a new Customer object using the ID number supplied as a parameter. Modify the coding below to fulfill the manager's request. /** A class representing a Customer */ public class Customer { // instance variables private int idNumber; // customer ID number private String name; // customer name private ShoppingCart items; // customer's shopping cart of // to-be-purchased items private Address mailingAddress; // customer's mailing address /** Construct a new customer object with idNumber, name, and * mailing address */ public Customer(int idNumber, String name, address mailingAddress) { this.idNumber = idNumber; nextIDNumber; nextIDNumber++; // added this.name = name; this.mailingAddress = mailingAddress; this.items = new Shopping Cart(); } // other methods omitted to save space } (5 marks] 8. Write the specification and implementation of a method named update Hours to increase an employee object's working hours. The method should take the working hours as a parameter and update the hours for the employee. As a safeguard, if the working hours is less than 0.0, the method should return the Boolean value false and should not update the hours for the employee. If the working hours is greater than or equal to 0.0, the method should update the hours and return the Boolean value true. (5 marks]
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
