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

  Write a haskell program to calculates a balanced partition

Write a program in Haskell which calculates a balanced partition of N items where each item has a value between 0 and K such that the difference b/w the sum of the values of first partition,

  Create an application to run in the amazon ec2 service

In this project you will create an application to run in the Amazon EC2 service and you will also create a client that can run on local machine and access your application.

  Explain the process to develop a web page locally

Explain the process to develop a Web page locally

  Write functions

These 14 questions covers java class, Array, link list , generic class.

  Programming assignment

If the user wants to read the input from a file, then the output will also go into a different file . If the user wants to read the input interactively, then the output will go to the screen .

  Write a prolog program using swi proglog

Write a Prolog program using swi proglog

  Create a custom application using eclipse

Create a custom Application Using Eclipse Android Development

  Create a application using the mvc architecture

create a application using the MVC architecture. No scripting elements are allowed in JSP pages.

  Develops bespoke solutions for the rubber industry

Develops bespoke solutions for the rubber industry

  Design a program that models the worms behavior

Design a program that models the worm's behavior.

  Writing a class

Build a class for a type called Fraction

  Design a program that assigns seats on an airplane

Write a program that allows an instructor to keep a grade book and also design and implement a program that assigns seats on an airplane.

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