Lab 3 - Selection Statements CSE 110 Principles of Programming with Java Spring 2021 Due February 14th 2021, 11:59PM Arizona Time 1 Lab Objectives The following objectives will be met at the end of...

1 answer below »
Please attached pdf instructions and java.file code template for solution guidance for Labs 3 (More on Selection Statements), Lab 9(Classes & Objects) and assignment 6 (Monsters with java, monsters and weapon file templates)



Lab 3 - Selection Statements CSE 110 Principles of Programming with Java Spring 2021 Due February 14th 2021, 11:59PM Arizona Time 1 Lab Objectives The following objectives will be met at the end of this lab - • Declare and define variables to store input given by the user • Accept user input using the Scanner class • Use switch and if statements to decide the flow of execution during runtime 1.1 User Input For this lab we will be focussing on practicing how to take user input, flow of execution management during runtime using the selection statement if and using both of the aforementioned concepts in our program successfully. Before we go on to the objectives, a quick reminder on user inputs and variables. Remember that user input or input values given by the user are data of different datatypes. In order to handle and store this incoming data we need some sort of storage containers. This is where variables come in (variables are storage containers of a particular datatype). Why do we need to store user inputs? This is simply so that we can manipulate the value or use them in some computation sometime later in our code. If we don’t store the user input in a variable then we won’t be to able recover and use that value later on. Thus it is important to always declare and define variables of the same datatype as the expected user input. For example, if we wanted to take two user inputs related to the divisor and dividend of a division operation, we would need two floating point variable or two integer variables - one to hold/store the divisor and the other to hold/store the dividend. It is good practice to understand the program requirements, figure out the number of inputs and outputs and then declare (and define) the same number of variables. In case you need more variables to hold intermediate values during computation, you can always add them to your code. To be able to accept user input in JAVA we need to use the Scanner class located in the java.util package. So we need to import this package into our source code file using the import keyword as shown below - import java.util.Scanner; Remember that all import statements need to be at the top of your source code file. Once you have imported the Scanner class into your source code file, you can create objects of it to take user input. Please refer to the Scanner class PDF on Canvas for details and examples. 1.2 Lab Objectives The source code file Lab3.java that you will create in this section, is what you will upload as your submission file to Canvas by the due date for this lab. Please ensure that the source code runs on your machine and produces the correct output as required. Overall Objective: For this lab, we will write a JAVA program to simulate the working of an arithmetic calculator that is capable of addition, subtraction, multiplication, division and modulus operations. You will prompt the user to enter two real operands and then ask them to input the sign of the operation they want to perform. The user will use the following signs to indicate the corresponding operation to be performed. • Addition : + • Subtraction : - • Multiplication : * • Division : \ • Modulus(Remainder) : % Based on the sign entered by the user, you will perform the appropriate operation using the switch state- ment. As a special check, for the division and modulus operation ensure that the divisor is not zero. In case the divisor is zero, inform the user that the division (or modulus) operation is not possible. For this section, you will create a new project in your IDE called Lab2 and create a source file called Lab2.java inside that project. The following requirements must be met to successfully complete this section - Obj.1 [3 points] Declare and define three variables of datatype double - one for each input and one to hold the result of the operation. You can define them with names of your choice (make sure they are relevant). Obj.2 [1 point] Declare and define one variable of datatype char - this will be used to hold the sign of the operation the user wants to perform. You can define it with a name of your choice (make sure they are relevant). Obj.3 [1 point] Declare and define an object of the Scanner class to enable your source code to take user input. Obj.4 [2 points] Accept two real numbers from the user using the Scanner class object and store them in the variables you created earlier. Obj.5 [1 point] Accept the sign of the operation to be performed (as a char) from the user using the Scanner class object and store it in the char variables you created earlier. 1 Obj.6 [(6+3) points] Use the selection statement switch to decide which operation to perform and based on the choice, compute the result and store it in the correct variable. In this step, while dealing with the division and modulus operation, ensure that the divisor is not zero. If the user enters the divisor as 0, then print a message informing them that the division operation is not possible by 0. [Hint: You will need to check if the divisor (one of the user inputs) is greater than 0 or not. Use the if statement in this case.] Obj.7 [1 point] Display the output of the operation selected by the user by printing the value stored in the result variable. Obj.8 [2 points] Close the Scanner class object as discussed in the lectures. Once you are done editing your source code, make sure to save it (save often to prevent loss of data and work) and then compile your source code. The next step is to follow the submission guidelines in Section 2 of this document and turn your lab in. 1.3 Comment Header Please include the following comment lines at the top of your Lab3.java file. Make sure you fill in the required fields as well. Listing 1: Comment Header 1 // ================================================ 2 // Lab3 . java 3 // Name : 4 // ASU ID : 5 // Time taken to complete t h i s lab : 6 // ================================================ 2 Submission Guidelines Please follow the guidelines listed below prior to submitting your source code file Lab3.java on Canvas - 1. Make sure that your source code file is named Lab3.java prior to submitting. 2. Make sure that you have completed all five objectives listed in section 1.2. 3. Include the completed comment header shown in section 1.3 at the top of your source code file 4. Submit your Lab3.java file only to the Canvas link for Lab 3 by February 14th 2021, 11:59PM Arizona Time. 3 Grading Rubric As noted in Section 1.2, each of the eight objectives have their own points. They are independent of each other and you will be scored for each objective that you complete successfully. Partial points will be awarded for partially completing objectives. 2 Lab Objectives User Input Lab Objectives Comment Header Submission Guidelines Grading Rubric   CSE 110 - Lab ​9 Lab Topics ● Variable Scopes ● Object Getters and Setters ● Classes and Objects in Java ● Class Methods and Attributes Lab Problem: Getters, Setters, and Scopes In this lab, we are going to learn how to create an abstract data type, or a class, in Java to help store some data. At the same time, we will practice and get used to the idea of variable scopes and how a Java program calls methods in the runtime. Part 1. Getters, Setters, and Variable Scopes Getters and setters are two important elements in object-oriented design. They are usually referred to with the concept “​encapsulation​”. Essentially, getters and setters are public methods serving as “accessors” and “mutators” respectively. As the names suggest, they are used to access or set information/states inside objects. As a result, the user would not accidentally access information of objects without a proper permission. Getters and setters are also helpful for program debugging tasks because they limit usage of information to some extent. In addition to getting/setting information, we also want to track how many times an object is updated and accessed by getters and setters. Specifically, the design of your Student class should follow this UML class diagram: When you submit your program, you must submit both your ​Student.java​, and​ Lab9.java​ from Canvas.   Grading Policy ● Code logic (up to 4pt): ○ -2 if the class Student is created in Lab9.java ○ -2 if the main method is duplicated in Student.java ○ -2 if there is any missing getters/setters ○ -2 if any permission modifiers (private and public) do not follow the spec ○ -2 if missing any class field (a.k.a. attribute, instance variable) ○ -2 if the types of class fields do not follow the spec ○ -2 if methods are declared as static accidentally Sample Output Below is an example of what your output should roughly look like when this lab is completed. The highlighted​ parts are the checkpoints and will be shown correctly when your Student.java is correct. student1's name is ​Foo Bar student1's ID is ​10291029 student1's grade is ​5.9 In student1, numUpdated = ​3 In student1, numAccessed = ​5 In main, numUpdated = 0 In main, numAccessed = 0 Assignment 6 - Monsters CSE 110 Principles of Programming with Java Spring 2021 Due April 24th 2021, 11:59PM Arizona Time 1 Assignment Objectives & Requirements 1.1 Assignment Objectives After completing this assignment the student should be able to: • Implement a class according to given specifications • Implement private instance variables • Implement constructor methods • Implement getter and setter methods 1.2 Assignment Requirements For this assignment you are given the following files - • Assignment6.java (make no changes to this file) • Monster.java (you must complete this file) • Weapon.java (you must complete this file) 2 Problem Description and Given Information You are going to complete a little program that simulates a battle between two Monsters. Each Monster will have a name and a healthScore. Each Monster will have a specific Weapon that they use to attack the other Monster. Each Weapon will have a name. Each Weapon will have a maxDamage that it can do. Each Monster will also be able to attack another Monster. You will write a pair of classes. One to define our Monster objects, and the other to define our Weapon objects. Remember that a class is like a blueprint that we can then use to instantiate objects of that type. So
Answered 16 days AfterApr 16, 2021

Answer To: Lab 3 - Selection Statements CSE 110 Principles of Programming with Java Spring 2021 Due February...

Arun Shankar answered on Apr 18 2021
153 Votes
Assignment_06/.DS_Store
__MACOSX/Assignment_06/._.DS_Store
Assignment_06/.classpath

    
        
    
        
        
    
    
    
Assignment_06/.project

     Assignment_06
    
    
    
    
        
             org.eclipse.jdt.core.javabuilder
            
            
        
    
    
        ...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here