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
// Name of the TA for your weekly 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
Part 1: Written Exercises: (4 pts)
- Rewrite the following set of if statements using a nested if-else structure.
if (score >= 90) grade = A;
if (score >= 80 && score < 90) grade = B; if (score >= 70 && score < 80) grade = C; if (score >= 60 && score < 70) grade = D; if (score < 60) grade = F;
- Rewrite the following nested if-else statement as an equivalent switch s if (letter == A | | letter == a) System.out.println(Excellent); else if (letter == B | | letter == b) System.out.println(You can do better);
else if (letter == C | | letter == c)
System.out.println(Try harder); else if (letter == D | | letter == d)
System.out.println(Try much harder);
else
System.out.println(Try another major! );
Part 2: Programming: (16 points)
Write a program called Assignment3 (saved in a file Assignment3 .java) that asks a user to enter two strings.
First, the program prompts:
Please enter a string.
The program should read in the string, and prompts:
Please enter another string.
The program reads in two strings and it prints a menu to the user. The program asks for user to enter an option and performs one of the following:
Here are the options on the menu:
Option a: checks if the length of the two strings are the same.
Option b: checks if two strings are same or different.
Option c: checks which string is lexically larger, or if they are same
Option d: prints out the first character (index 0) of each string
Option e: prints out a new string consisting of the first string concatenated (appended) with the second string.
Option f: prints out two strings using upper case letters.
Option q: quit the program.
Here is the sample output your program should produce when the user enters the strings shown in bold:
Sample Output : (the user enters the string shown in bold)
Please enter a string.
apple
Please enter another string.
orange
Command Options
a: find if the lengths of the strings are equal b: find if the two strings are the same
c: find which string is lexically larger d: print the first character of each string e: concatenate the two strings f: print both strings in uppercase
q: quit this program
Please enter an option or type?
a
The lengths are not the same.
Please enter an option or type?
b
The two strings are different.
Please enter an option or type?
c
The second string is lexically larger.
Please enter an option or type?
d
The first character of the first string is a
The first character of the second string is o
Please enter an option or type?
e
The concatenation of two strings is appleorange
Please enter an option or type?
f
The first string using upper case letters: APPLE
The second string using upper case letters: ORANGE
Please enter an option or type?
b
The two strings are different.
Please enter an option or type?
q
Press any key to continue . . .
Requirements: make sure you are using a switch statement for the menu. In addition, your program should keep asking for input until user chooses to quit.
Helpful hints for doing this assignment:
- work on it in steps
- always make sure your code compiles before you add more code
- the options are called in any order
Reviews
There are no reviews yet.