Java programs

Question 1:  Switch (5 Points) 


Write a Java program to make a simple calculator using switch case statement which perform addition, subtraction, multiplication and division of two numbers. 

Either: Given two integers and an arithmetic operator, you have to perform the specific arithmetic operation on given integer operands using a switch case statement and print the result on screen.  OR: The program takes the value of both the numbers (entered by user) and then user is asked to enter the operation (+, -, * and /), based on the input program performs the selected operation on the entered numbers using switch case.  


Question 2: Nested Loops (5 Points) 

Write a program that use Nested Loop to collect data and calculate the average rainfall over a period of years. First the program should ask for the number of years. The outer loop will iterate once for each year. The inner loop will iterate 12 times, once for each month. Each iteration of the inner loop will ask the user for the inches of rainfall for that month. After all iterations, the program should display the number of months, the total inches of rainfall, the average rainfall per month for the entire period.  

Input Validation: Do not accept a number less than 1 for the number of years, do not accept negative numbers for the monthly rainfall.  


Question 3: Array List (5 Points) 

Create an ArrayList of Strings and write a program that places a string of four asterisks "****" in front of every string of length 4. For example, suppose that a variable called list contains the following values: {"this", "is", "lots", "of", "fun", "for", "every", "Java", "programmer"} And after running the program the list should store the following values after the call: {"****", "this", "is", "****", "lots", "of", "fun", "for", "every", "****", "Java", "programmer"} Notice that you leave the original strings in the list, "this", "lots", "Java", but include the four asterisk string in front of each to mark it.


Question 4: Files (5 Points) 

Write a program that reads a file (names as textfile) uploaded with assignment  and displays the words of that file as a list. Then display the words in reverse order. Then display them with all plurals (ending in "s") capitalized. Then display them with all plural words removed. 


Question 5: Array (5 Points) 

The local Driver’s License Office has asked you to write a program that grades the written portion of the driver’s license exam. The exam has 20 multiple questions. Here are the correct answers:   

1. B  6.  A  11.  B   16. C 2. D  7.  B  12.  C   17. C 3. A  8.  A  13.  D   18.  B 4. A  9.  C  14.  A   19.  D 5. C  10. D  15.  D   20.  A 


A student must correctly answer 15 of the 20 questions to pass the exam.  Correct answers should be saved in an array field. Program should have another array field to hold the student’s answers. The class should have following functionality: 

• If the student pass exam, save true in result variable otherwise false. Display a message showing the result on console.  

• totalCorrect: Display the total number of correctly answered questions. 

• totalIncorrect: Display the total number of incorrectly answered questions. 

• questionMissed: Display an int array containing the question numbers of the questions that the student missed. 

• Demonstrate the program that asks user to enter a student’s answers, and then displays the results in each four points listed above. 


Input Validation: Only accept the letters A, B,C, or D as answers. 

Exception Handling (5 Points) 

Each of your program should have proper exception handling, covered in week 9.

Need a custom answer at your budget?

This assignment has been answered 5 times in private sessions.

© 2024 Codify Tutor. All rights reserved