CSE110 Lab 3 Solved

35.00 $

Category:

Description

Rate this product

CSE 110 – Lab 3 What is this Lab about ?

This program is for practicing if-else expressions and reviewing some prior topics.

Getting Started

  1. Create a class called Lab3. Use the same setup for setting up your class and main method as you did for the previous assignments. Be sure to name your file Lab3.java.
  2. Remove the comments and insert correct expression according to the instructions.
  3. Write comments about what you are thinking and explain yourselves.
  4. Do check your submission output on the portal.

Assignments Documentation

At the beginning of each programming assignment you must have a comment block with the following information :

/*————————————————-
//AUTHOR : (Put Your Name Here)
//FILENAME : Lab3.java
//SPECIFICATION: This program is for practicing the use of if-else conditional expressions

  • //  It also reviews some previous topics. It also finds the dictionary order
  • //                of two strings.
    

    //LAB LETTER: (Put your LAB section here). //START TIME:
    //END TIME:

    Now lets begin with the assignment. You will find the instructions inline.

    // Import the Scanner class from the java.util package

    import java.util.Scanner;
    // Declare the class name as (Lab4) //–> Class Name Here !!
    {

    //Declare the main method //–> Main Method Here !! {

    // Declare double variables with names n1,n2,n3,n4, ans and max // Declare a String type variable s1.
    // Invoke a Scanner object “in/scan”.

    //Print the following statement.

    System.out.println(“Input four integers on which we want to perform Mathematical Operations!”);

    //Using the scanner object “in/scan”, assign values to n1,n2, n3, n4
    //Find the maximum and the minimum of all the 4 numbers n1,n2,n3,n4 using only //If and Else statements.

    //Print the following statements

    System.out.println(“Please Input one of the following operations:”); System.out.println(“Type a to Add the numbers.”);

System.out.println(“Type b to Mul the numbers.”); System.out.println(“Type c to find Avg.”); System.out.println(“Type d to find Max.”); System.out.println(“Type e to find Min.”);

//Using Scanner “in/scan” object, assign a value to String variable s1.

//Use if and
//For ex: if
// variable.
//if ‘b’ was
//and so forth.
//Print the ans variable only if the input s1 is a/b/c/d/e. System.out.println(“Answer is : “+ ans);

else control statements to find which option was entered. ‘a’ was entered, find the sum of the numbers and set the ans

entered, multiply the numbers, if ‘c’ find the average so on

//Else if any other value is entered other than a/b/c/d/e , print the following

System.out.println(“Please input the correct option.”)

//Declare 2 String variables , str1 and str2.

//Print the following statement

System.out.println(“We are now comparing 2 strings and finding which one will come first in a dictionary!!”);

System.out.println(“Please enter 2 strings of length 4.”); System.out.println(“Enter string 1:”);
//Using Scanner object in/scan take input str1. System.out.println(“Enter string 2:”);

//Using Scanner object in/scan take input str2.

//Now compare using if/else to find which string comes first.
//Remember to use nested conditional statements to find the alphabetical order. //Assign the first string to a String variable firstString.
//Assign the second string to a String variable secondString.

//Finally print the first string and the second String.

System.out.println(“First String is: ” + firstString); System.out.println(“Second String is: ” + secondString);

//Close the Scanner object:

//in.close() or scan.close().

} }

Do remember to close your braces for both the main method and the class.

Sample Output 1:

Input four integers on which we want to perform Mathematical Operations! 1
2
3

4
Please Input one of the following operations:
Type a to Add the numbers.
Type b to Mul the numbers.
Type c to find Avg.
Type d to find Max.
Type e to find Min.
a
Answer is : 10.0
We are now comparing 2 strings and finding which one will come first in a dictionary!! Please enter 2 strings of length 4.
Enter string 1:
abcd
Enter string 2:
defg
First String is: abcd
Second String is: defg

Sample Output 2:

Input four integers on which we want to perform Mathematical Operations! 1
2
3

4
Please Input one of the following operations: Type a to Add the numbers.
Type b to Mul the numbers.
Type c to find Avg.
Type d to find Max.
Type e to find Min.
d
Answer is : 4.0
We are now comparing 2
Please enter 2 strings
Enter string 1:
pqrs
Enter string 2:
abcd
First String is: abcd
Second String is: pqrs

Sample Output 3:

Input four integers on
1
2
3

4
Please Input one of the following operations: Type a to Add the numbers.
Type b to Mul the numbers.
Type c to find Avg.
Type d to find Max.
Type e to find Min.
e
Answer is : 1.0
We are now comparing 2
Please enter 2 strings
Enter string 1:
aadd
Enter string 2:
aacc
First String is: aacc
Second String is: aadd

Sample Output 4:

Input four integers on
1
2
3

which we want to perform Mathematical Operations!

strings and finding which one will come first in a dictionary!! of length 4.

which we want to perform Mathematical Operations!

strings and finding which one will come first in a dictionary!! of length 4.

4
Please Input one of the following operations:
Type a to Add the numbers.
Type b to Mul the numbers.
Type c to find Avg.
Type d to find Max.
Type e to find Min.
k
Please input the correct option.
We are now comparing 2 strings and finding which one will come first in a dictionary!! Please enter 2 strings of length 4.
Enter string 1:
aaa2
Enter string 2:
aaa1
First String is: aaa2
Second String is: aaa1

  • 3-9w3fxc.zip