CSE 110 – Assignment #2  Solved

30.00 $

Category: Tags: , , , , ,
Click Category Button to View Your Next Assignment | Homework

You'll get a download link with a: zip solution files instantly, after Payment

Securely Powered by: Secure Checkout

Description

5/5 - (2 votes)

What this Assignment Is About:
• Using Classes and Objects (The String class) – Chapter 3 • Using conditional (if, if-else) statements – Chapter 4

Your programming assignments require individual work and effort to be of any benefit. Every student must work independently on his or her assignments. You must work alone on the assignments – no collaboration of any kind is permitted. You cannot use Google, StackOverflow, Chegg or any other on-line resources to look up for the solution. Sharing your assignments with others in any way is NOT permitted. Violations of the University Academic Integrity policy will not be ignored.

 

Violations of the University Academic Integrity policy will not be ignored.     The university academic integrity policy is found at https://provost.asu.edu/academic-integrity

Important Note: All submitted assignments must begin with the descriptive comment block.  To avoid losing trivial points, make sure this comment header is included in every assignment you submit.

/*————————————————————————-

// AUTHOR: your name

// FILENAME: title of the source file

// SPECIFICATION: description of the program

// YOUR Lab Letter and Name of the TA for your Closed lab

// FOR: CSE 110- homework #- days and time of your class

// TIME SPENT: how long it took you to complete the assignment

//———————————————————————-*/

Reasonably good amount of comments should be added in your program so that it is easy for other people to understand it. Please see the comment style in the textbook.

Part 1: Exercises (6 pts)

Note: The answers to the following questions should be typed in the block of comments in the Assignemnt2.java file.  Please make sure they’re commented out (green). Type them neatly and make them easy to read for the graders.

Given the String object called myString with the value “Practice makes perfect!” answer the following questions.

Question #1 (1pt): Write a statement that will output (System.out) the number of characters in the string.

Question #2  (1pt): Write a statement that output the index of the character ‘m’.

Question #3 (1 pt):  Write a statement that outputs the sentence in uppercase letters

Question #4 (1 pt): Write a statement that uses the original string to extract the new string “perfect” and prints it to the screen

Question # 5 (2 pts): What do the following expressions evaluate to in Java given int x = 3, y = 6;

  1. x == y / 2
  2. x % 2 == 0 || y % 2 != 0
  3. x – y < 0 && !(x >= y)
  4. x + 6 != y || x / y <= 0

 

Question # 6 (1 pt): What does the following statement sequence print? (page 63)

String str = “Harry”; int n = str.length();

String mystery = str.substring(0,1) + str.substring(n-1, n);

System.out.println(mystery);

 

Note : The API (Application Programming Interface) documentation lists the classes and methods of the Java library.  Go to  http://docs.oracle.com/javase/6/docs/api/ and find out the methods you may need to answer the questions.

Part 2:  Programming (14 points)

Remember the childhood game “Rock, Paper, Scissors”? It is a two-players game in which each person simultaneously chooses either rock, paper, or scissors. Rock beats scissors but loses to paper, paper beats rock but loses to scissors, and scissors beats paper but loses to rock. Your program must prompt the player 1 and player 2 to each enter a string for their choice: rock, paper, or scissors. Then appropriately reports if “Player 1 wins”, “Player 2 wins”, or “It is a tie.” Your program should work for both lower case and uppercase letters. If the user string is not rock, scissors or paper the program will print “Wrong choice”.

 

Sample Run: User input is in Bold.

 

Player 1: Choose rock, scissors, or paper:

rock

Player 2: Choose rock, scissors, or paper:

paper

Player 2 wins.

 

Player 1: Choose rock, scissors, or paper:

scissors

Player 2: Choose rock, scissors, or paper:

rock Player 2 wins.

 

Player 1: Choose rock, scissors, or paper:

PAPER

Player 2: Choose rock, scissors, or paper:

Rock

Player 1 wins.

 

Player 1: Choose rock, scissors, or paper:

rock

Player 2: Choose rock, scissors, or paper:

pen

Wrong choice!

 

 

Submit your homework by following the instructions below:

 

*********************************************************************************

 

  • Submit your java file on-line at the link provided on Canvas for assignment 2 under “Assignments” tab.
  • java should have the following, in order:
  • In comments, the assignment Header described in “Important Note”.
  • In comments, the answers to questions 1-5.
  • The working Java code requested in Part #2.
  • The Assignment2.java file must compile and run as you submit it. You can confirm this by viewing your submission results.

 

 

 

  • CSE110ASSGN2.zip