Access over 20 million homework & study documents

3 Codes With Report

Content type
User Generated
Subject
Java
School
Southwestern Oklahoma State University
Type
Homework
Rating
Showing Page:
1/7
3 CODES WITH REPORT
I realized that I can analyze a code that is already written and update it as I did in question
4.10, I am able to write code that handles different situations as did in question 4.11, and I
understand that using prewritten methods in program makes your job easier as I did in 4.12.
Since all the programs works as expected, I believe that I understand all the points for this
assignment.
4.10)
Sentence:
In this question, it is asked to rewrite the given code to prompt the user to enter the
character Y for Yes, and N for No rather than entering 1 for Yes and 0 for No.
Outline:
1. Copy the previous code
2. Find out where input is used to get for “Yes” or “No”
3. Change these parts so that it a character is used to get input for “Yes” or “No”
4. Check the solution
Code:
import java.util.Scanner;
public class Lala {
public static void main(String[] args) {
System.out.println("Hello");
String set1 =
" 1 3 5 7\n" +
" 9 11 13 15\n" +
"17 19 21 23\n" +
"25 27 29 31";
String set2 =
" 2 3 6 7\n" +
"10 11 14 15\n" +
"18 19 22 23\n" +
"26 27 30 31";
String set3 =

Sign up to view the full document!

lock_open Sign Up
Showing Page:
2/7
" 4 5 6 7\n" +
"12 13 14 15\n" +
"20 21 22 23\n" +
"28 29 30 31";
String set4 =
" 8 9 10 11\n" +
"12 13 14 15\n" +
"24 25 26 27\n" +
"28 29 30 31";
String set5 =
"16 17 18 19\n" +
"20 21 22 23\n" +
"24 25 26 27\n" +
"28 29 30 31";
int day = 0;
// Create a Scanner
Scanner input = new Scanner(System.in);
// Prompt the user to answer questions
System.out.print("Is your birthday in Set1?\n");
System.out.print(set1);
System.out.print("\nEnter N for No and Y for Yes: ");
// Character input
String userAnswer = input.next();
if (userAnswer.equals("Y")) {
day += 1;
}
// Prompt the user to answer questions
System.out.print("\nIs your birthday in Set2?\n");
System.out.print(set2);
System.out.print("\nEnter N for No and Y for Yes: ");
char answer = input.next().charAt(0);
if (answer == 'Y')
day += 2;
// Prompt the user to answer questions
System.out.print("Is your birthday in Set3?\n");
System.out.print(set3);
System.out.print("\nEnter N for No and Y for Yes: ");
answer = input.next().charAt(0);
if (answer == 'Y')
day += 4;
// Prompt the user to answer questions
System.out.print("\nIs your birthday in Set4?\n");

Sign up to view the full document!

lock_open Sign Up
Showing Page:
3/7

Sign up to view the full document!

lock_open Sign Up
End of Preview - Want to read all 7 pages?
Access Now
Unformatted Attachment Preview
3 CODES WITH REPORT I realized that I can analyze a code that is already written and update it as I did in question 4.10, I am able to write code that handles different situations as did in question 4.11, and I understand that using prewritten methods in program makes your job easier as I did in 4.12. Since all the programs works as expected, I believe that I understand all the points for this assignment. 4.10) Sentence: In this question, it is asked to rewrite the given code to prompt the user to enter the character “Y” for “Yes”, and “N” for “No” rather than entering 1 for Yes and 0 for No. Outline: 1. 2. 3. 4. Copy the previous code Find out where input is used to get for “Yes” or “No” Change these parts so that it a character is used to get input for “Yes” or “No” Check the solution Code: import java.util.Scanner; public class Lala { public static void main(String[] args) { System.out.println("Hello"); String set1 = " 1 3 5 7\n" + " 9 11 13 15\n" + "17 19 21 23\n" + "25 27 29 31"; String set2 = " 2 3 6 7\n" + "10 11 14 15\n" + "18 19 22 23\n" + "26 27 30 31"; String set3 = " 4 5 6 7\n" + "12 13 14 15\n" + "20 21 22 23\n" + "28 29 30 31"; String set4 = " 8 9 10 11\n" + "12 13 14 15\n" + "24 25 26 27\n" + "28 29 30 31"; String set5 = "16 17 18 19\n" + "20 21 22 23\n" + "24 25 26 27\n" + "28 29 30 31"; int day = 0; // Create a Scanner Scanner input = new Scanner(System.in); // Prompt the user to answer questions System.out.print("Is your ...
Purchase document to see full attachment
User generated content is uploaded by users for the purposes of learning and should be used following Studypool's honor code & terms of service.

Anonymous
Really helpful material, saved me a great deal of time.

Studypool
4.7
Trustpilot
4.5
Sitejabber
4.4

Similar Documents