Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Need help with a lot of code in java import java.util.Scanner; public class Homework3 { public static void main(String[] args) { //declare & initialize input

Need help with a lot of code in java

import java.util.Scanner;

public class Homework3 { public static void main(String[] args) { //declare & initialize input from keyboard Scanner keyboard = new Scanner(System.in);

//declare & initialize variable double gpa = 3.42; //problem 1 //List, in multiline comment form, all the relational operators and define their functionality. //problem 2 //List, in multiline comment form, all the logical operators and their functionality. //problem 3 //Using two IF statements, display the words "With honors." when the gpa is greater than or equal 3.5 and //"Without honors." when gpa is less than 3.5 //problem 4 //Rewrite problem 3 using one IF...ELSE statement. //problem 5 //Rewrite problem 3 using one IF..ELSE statement and the appropriate logical operator with a compound condition //problem 6 //Using the following variable and two IF statements determine if it's value is odd or even and display an appropriate message. int number = 5; //problem 7 //Rewrite problem 6 using a single IF...else statement. //problem 8 //Using the two following variables and two separate nested IF statements, write "Both are odd." to the screen, if true. Nothing if not true. int number1 = 5; int number2 = 2; //problem 9 //Rewrite problem 8 using one IF statement and a compound condition and logical operator. //problem 10 //Rewrite problem 8 using an IF...ELSE statement. //problem 11 //Using the following variable and using one IF...ELSE statement and logical operator, pring "Yes" to the screen if the numbers value //is between 5 and 9 int number3 = 6; //problem 12 //Using the following variables write the decision statements using only IF statements to answer the following scenario: A person qualifies for insurance //when they are a non-smoker, veteran and over the age of 40. Print to the screen the appropriate output. double age = 44; boolean smoker = false; boolean veteran = true; //problem 13 //Rewrite problem 12 using logical operators and compound conditions. //problem 14 //Use the following variables, write a SWITCH that assigns the months string name to strMonth and print it out based on the month variables //numeric value. You must only use one print statement. int month = 3; String strMonth; //problem 15 //Using the following variable, write a SWITCH statement that prints out "You answered Yes." when the variable answer is equal to a y or Y. //And prints "Not valid" when any other character is found in answer. char answer = 'y'; //problem 16 //Rewrite problem 15 using an IF..else statement. //problem 17 //Using the following variable, using two IF statements write "Married" or "Not married" based on the value of the variable. boolean married = false; //problem 18 //Rewrite problem 17 using an IF...ELSE statement and the NOT logical operator to print "Not married." or "Married" to the screen. //problem 19 //Rewrite problem 17 using a SWITCH. //problem 20 //Using the following variable and decision statements of your choice solve the following problem: //To determine whether a year is a leap year, follow these steps:

//Step 1. If the year is evenly divisible by 4, go to step 2. Otherwise, go to step 5. //Step 2. If the year is evenly divisible by 100, go to step 3. Otherwise, go to step 4. //Step 3. If the year is evenly divisible by 400, go to step 4. Otherwise, go to step 5. //Step 4. The year is a leap year (it has 366 days). //Step 5. The year is not a leap year (it has 365 days). //Use the following test years - 1700, 1800 and 1600. //Print out "Year is a leap year." or "Year is not a leap year." int year = 1800;

//problem 21 //Using the following variables and the problem 20 solution determine and print out the number of days //within a month. Combine an IF statement for solving problem 20 when the month is February, within a SWITCH. //Months with 31 days: 1, 3, 5, 7, 8, 10, 12 //Months with 30 days: 4, 6, 9, 11 //logic pseudocode // case 2: // if leapyear // days = 29 // else // days = 28 // case 3: // int days = 0; month = 2; year = 2000; int numberOne = 0; int numberTwo = 0; //problem 22 //Write the code necessary to determine the largest number when a user is asked to enter two numbers. System.out.print("Enter an integer number: "); numberOne = keyboard.nextInt(); System.out.print("Enter another integer number: "); numberTwo = keyboard.nextInt(); //put code here //problem 23 //Have the user input three integer numbers and output the smallest of the three. int numberThree = 0; System.out.print("Enter an integer number: "); numberOne = keyboard.nextInt(); System.out.print("Enter a second integer number: "); numberTwo = keyboard.nextInt(); System.out.print("Enter a third integer number: "); numberThree = keyboard.nextInt(); //problem 24 //Using Math random, output a random integer value between 1 and 42.

//problem 25 //given the code below, have the user input an integer number between 1 and 7 and display the appropriate day of the week. Monday is // 1 and Tuesday 2. If the user inputs another value, output "Invalid input." Build the code using only individual IF statements. numberOne = 0;

//problem 26 //Given the user input of an integer number and using a SWITCH display the day of the week or invalid number if not between //1 and 7. Monday is 1 numberOne = 0; //problem 27 //given the code below, have the user input an integer number between 1 and 7 and display the appropriate day of the week. //Monday is 1 and Tuesday 2. If the user inputs another value, output "Invalid input." Build the code using only one IF..ELSEIF statement. numberOne = 0;

//problem 28 //Given the variable below, using Decision statements determine if the character is a vowel or consonant. char chrInput = 'a'; //problem 29 //Given the code and variables below, output "Valid password." if the strInput is at least 10 characters in length and "Invalid password." //if not. String strInput; //problem 30 //Using the logical NOT operator, output true when the following variable is false and false when true. boolean why = true; System.exit(0); }//end of main }//end of class

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Fundamentals Of Database Systems

Authors: Ramez Elmasri, Sham Navathe

4th Edition

0321122267, 978-0321122261

More Books

Students also viewed these Databases questions

Question

explain the concept of strategy formulation

Answered: 1 week ago