Write a program that will prompt the user to enter hisher


Assignment 1

Answer all questions. Make sure you run the program on net bean and submit your programs via ethuto.

Question 1

Write a program that will prompt the user to enter his/her name and a number. Use a while loop that will display the user name times the entered number.

Hint: the following steps must be performed:
- Declare variable name of type String, number of type integer and a count of type integer set to 0. Count is a loop control variable.
- Create the Scanner object.
- Prompt the user to enter the name and store the input on variable name.
- Prompt the user to enter the number and store the input on variable number.
- Create a while loop statement that will loop while count is less than number.
- Inside the loop display the name and increment count.
- Outside the while loop, display name, number, and count.

Question2

Given the following table of the test scores, create the if else ifstructure that will model the inputted test score. Display the message "not within range" for any value not within the range.

Range

remarks

80-100

Excellent

70-79

Very good

50-69

Good

40-49

Poor

0-39

Very poor

Hint: the following steps must be performed:
- Declare a variable mark of type integer and variable remarks of type String.
- Create the Scanner object.
- Prompt the user to enter a mark and store an inputted value on the variable mark
- Use if else if to check the range of the mark. If the mark is within the expected range, then set a remark to a specific value.
- Lastly, display the mark and remarks.

Questions 3 and 4 help you understand arrays 1 and 2 dimensional arrays.

Question3

As a Nanabolela secondary school IT teacher, you are required to create and initialize an array called testmarks with the values provided below. Use a for loop to add 2 to each test mark.

67

45

26

28

83

Hint: Follow the following steps
- Create and initialize an array testmarks of type integer with the value provided above.
- Use afor loop to manipulate an array by adding 2 to each test mark.
- Use a second for loop that will calculate sum of test marks.

Question 4

45

47

25

45

14

17

36

4

1

3

8

9

14

17

011

47

47

63

02

0

11

- Given the following table create and initialize the two-dimensional array called tableNumbers of type integer.
- Use nested loops that will add 12 to each element in an array.
- Use nested loops that will get the average of the data. Hint get total and count

Questions 5 and 6 helps you better with methods.

Question 5

1. Create a method called Calculate() of type integer that will calculate and return back the total. This method has two parameters num1 and num2.
2. Call method Calculate() passing 9 and 10.
3. Create a parameterless method of type void called DisplayName(). This method will prompt the user to enter his or her name and display the message "your user name is" followed by the user name.
4. Call the method DisplayName()

Question 6

As a Leseding high school IT teacher, you are required to create a program that will subtract 5 from the learner's marks.

23

45

26

28

83

Inside The main Method
1. Create and initialize array called MarksArray that will hold 5 marks.
2. Call a void method subtractFive() passing MarksArray as an argument
3. Call a returning value method returnAverage() passing MarksArray

Method implementation
4. Create a method SubtractFive() that will receive MarksArrayas a parameter, and use a for loop to subtract 5 from each element.
5. Create a method returnTotal() that will receiveMarksArrrayas a parameter, it will use a while loop to sum all the marks

Questions 7 and 8 covers Classes and Objects

Question 7

Complete the following class.
Public class Student
{
1. Student has three fields name, age and student number
2. Provide an overloaded constructor that will initialize these 3 fields
3. provides the getters methods for each field
Public static void StudentApplication(String args[]) // Assume the following initialisation are done.
{ String name="john";
Intage =26;
IntstudentNumber= 209075937;
4. Create an object called myStudent passing the above data
5. Display information using getters methods.
}
}

Question 8

- Create a class called Lecturer.
- Lecturer has the following attributes, name, staffNumber, salary.
- Create a constructor that will initialize these fields, if a salary is less than 0 set it to0.
- Create getters methods for all the fields.
Here is the test Application named LecturerApplicationthat will demonstrates class Lecturer
Public static void LecturerApplication(String args[])
{ String name=John;
IntstaffNumber =17095;
doublesalary= -99.99;
- Create an object called employeeObject passing the above data.
- Display information using getters methods.

Solution Preview :

Prepared by a verified Expert
JAVA Programming: Write a program that will prompt the user to enter hisher
Reference No:- TGS01654237

Now Priced at $60 (50% Discount)

Recommended (95%)

Rated (4.7/5)