Complete the implementation of calculator

Assignment Help Programming Languages
Reference no: EM131227643

Problem 1: Complete the implementation of Calculator.scala

Problem 2: Elbonia has a simple sliding scale income tax scheme. Your tax rate is determined by your income according to the following table:

Income

Rate

< $20000

0%

< $30000

5%

< $40000

11%

< $60000

23%

< $100000

32%

>= $100000

50%

Implement a tax calculator for the Elbonians: TaxCalculator.scala

Your calculator should throw an "Income can't be negative" exception if the input is negative.

Problem 3: Complete ShapeMaker.scala. Here's a sample output:

Enter a positive integer: 10

**********

**********

**********

**********

**********

**********

**********

**********

**********

**********

 

*

**

***

****

*****

******

*******

********

*********

**********

 

     *    

    ***   

   *****  

  ******* 

 *********

***********

 

***********

 *********

  ******* 

   *****  

    ***   

     *   

Problem 4: Complete VectorCalculator.scala. Additional information about arrays in Scala can be found on the web. Here, for example

Problem 5: Complete the implementation of MatrixCalculator.scala.

Here's a sample output:

Enter a positive integer: 5

 39 58 28 57 1

 77 68 99 57 85

 26 83 51 40 64

 0 55 67 57 6

 21 96 22 64 13

trace = 228

Problem 6: Rewrite the following Java method in Mystery.scala

import java.util.*;

public class Mystery {

   public static void main(String args[]) {

      Scanner kbd = new Scanner(System.in);

      System.out.print("enter a positive integer: ");

      Random r = new Random();

      int k = kbd.nextInt();

      for(inti = 0; i< 10; i++) {

         System.out.println("trial " + i);

         for(int j = 0; j < 100; j++) {

            //int k = r.nextInt(100);

            k = (k * k) % 100;

            if (k < j/3) continue;

            if (k < j/2) break;

            System.out.println("k = " + k);

         }

      }

   }

}

Hint: Use Scala's break blocks.

Problem 7: Assume the following declarations have been made:

var x = 10

lazy val y = 1 / 0

Without using Scala, what are the values (with their types) of the following expressions, if the expressions contain errors, write "error":

1. if (false) 3

2. if (false) if (true) 3 else 4     // dangling else

3. if (x = 10) true else false     

4. if (true) 1 else 1/0              // conditional eval

5. if (if (true) false else true) true else false

6. y + 10

7. println("100") // tricky!

8. true || 3 == 1/0                  // short circuit eval

9. false && (1 / 0 > 0)             // short circuit eval

Now check your answers using the Scala interpreter.

Problem 8: Assume the following declarations have been made:

var x = 10

Without using Scala, what are the values (with their types) of the following expressions, if the expressions contain errors, write "error".

1. {1; 2; 3} + {4; 5; 6}

2. {1; 2; {3; 4; {5; 6} } }

3. if (false) {2; 3} else {4; {5; 6}} + {10; 20}

4. {10; 20} + if (false) {2; 3} else {4; {5; 6}}

5. {var x = 20; var y = x + 1; x + y}

6. // { var y = x + 1; var x = 5; var z = x + 1; x + y + z}

7. {var x = 3; var y = {var x = 9; x + 1}; x + y} // shadowning

8. {def tri(n: Int): Int = if (n == 0) 0 else n + tri(n - 1); tri(5) }

// recursive blocks

Now check your answers using the Scala interpreter. Ignore the warning messages, but not the error messages.

Attachment:- Assignment.rar

Reference no: EM131227643

Questions Cloud

Would rational expectations help or hinder their efforts : (Long-Run Phillips Curve) Suppose the economy is at point d on the long-run Phillips curve shown in Exhibit 6. If that inflation rate is unacceptably high, how can policy makers get the inflation rate down? Would rational expectations help or hind..
What specific policy views does that person advocate : Choose a Fed governor or a regional Reserve Bank president and try to determine whether that person leans more toward an active or a passive policy view. What specific policy views does that person advocate?
How relevant were the predictions of this article : If you are the top person in your company managing the overall supply chain what are the top 3-4 features/functionality that are "must haves" for managing efficiently and effectively? Why? Support your answers with pertinent details.
Impact of the internet on online criminal activities : Provide the URL of at least one site that discusses the impact of the Internet on online criminal activities and provide a brief review of the information contained there. Did you learn anything new? Were you surprised by any of the information pr..
Complete the implementation of calculator : Problem 1: Complete the implementation of Calculator.scala. Elbonia has a simple sliding scale income tax scheme. Your tax rate is determined by your income according to the following table:
What is wasta : Using wasta is an accepted business practice in the Arab world. What is wasta? What are the advantages of using it as seen through the eyes of Arab managers? Describe some similarities and differences in negotiation styles between Arab-style negot..
New conversation within the it world : The Internet of Things (IoT) has become a new conversation within the IT world, describing how more smart devices can communicate with each other and interface with humans. Naturally, this would mean networking challenges become increasingly sophi..
Er model and supporting documentation : Discuss how the technique of normalization can be used to check the structure of the tables created from the ER model and supporting documentation.
Determining the fact-finding technique : The five most commonly used techniques are examining documentation, interviewing, observing the business in operation, conducting research, and using questionnaires. Describe each fact-finding technique and identify the advantages and disadvantage..

Reviews

len1227643

10/1/2016 3:46:11 AM

The first six problems use Code Check (http://horstmann.com/codecheck/). Click the link, paste Scala code into the windows where indicated, then click the "Submit Query" button. A report will be generated indicating if your code passed a series of tests. If you have errors, you may try again. When you are satisfied with the report, click the "Download" link at the bottom of the report. This will create a signed zip file. This should be submitted as an attachment to Canvas. Unsigned attachments will not be accepted.

Write a Review

Programming Languages Questions & Answers

  What is a data flow diagram

Define what is meant by a process in a process model. How should a process be named? What information about a process should be stored in the CASE repository?

  Program to print a business travel expenses

Write a program to print a business travel expenses attachment for an income tax return.

  Modify the pseudocode and optimize it.

Provide valid reasons why the pseudocode is now more efficient.

  Creating form which analyzes poker hand entered by user

To observe behavior of Sub Procedures, draw a Form which analyzes a poker hand entered by user and displays the type of hand.

  Characteristics used for biometric user authentication

You have just been promoted to manager of computer security for large enterprise (XYZ Corporation). Your first project as security manager is to estimate principal physical characteristics used for biometric user authentication.

  Write a script to create a new product category

Write a script to create a new Product Category called ‘Shoes'. This category belongs under the category Clothing. Only ParentProductCategoryID and Name are required.

  What will the permissions string contain

If you execute ls -ld on the project38" directory, what will the permissions string contain? If you execute ls -l on the iapp_v_8 file contained in project38 , what will the permissions string contain

  Calculate display the area of a rectangle (length * width)

Use the input.txt file. Have it read in the number of records to work on. Then for each record read in a character. If it is a C then read in a value and calculate and display the area of a circle (pi*r 2 ), a R then read in two values and calculate ..

  Distinguishing web pages or web servers for task

Distinguish between any Web pages or Web servers you would use for this task.

  Design a gui class that should be hand-coded

The program should consist of three classes. The first class should define the GUI and should be hand-coded and not generated by a GUI generator.

  Write prolog clauses to express the relationships

Write prolog clauses to express the relationships, given the parent relationship: grand-parent, sibling, cousin.

  Explain some ways tables can be used on web page

Tables are one of the most useful page layout tools available to web designers. Explain some ways tables can be used on a web page. Elaborate on other ways to achieve the same look.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd