Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Programming Language Expert

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

Programming Language, Programming

  • Category:- Programming Language
  • Reference No.:- M91983557

Have any Question?


Related Questions in Programming Language

Assignment - haskell program for regular expression

Assignment - Haskell Program for Regular Expression Matching Your assignment is to modify the slowgrep.hs Haskell program presented in class and the online notes, according to the instructions below. You may carry out th ...

Extend the adworks applicationi add dialogs to allow the

Extend the AdWorks application I. Add Dialogs to allow the user to Add, Edit, Read and Delete a Customer and refresh the view accordingly. 1. The user should be able to select a specific customer from the DataGrid and cl ...

Structs and enumsoverviewin this task you will create a

Structs and Enums Overview In this task you will create a knight database to help Camelot keep track of all of their knights. Instructions Lets get started. 1. What the topic 5 videos, these will guide you through buildi ...

Question - create a microsoft word macro using vba visual

Question - Create a Microsoft Word macro using VBA (Visual Basic for Applications). Name the macro "highlight." The macro should highlight every third line of text in a document. (Imagine creating highlighting that will ...

Question 1 what is a computer program what is structured

Question: 1. What is a Computer program? What is structured programming? 2. What is modular programming? Why we use it? 3. Please evaluate Sin (x) by infinite series. Then write an algorithm to implement it with up to th ...

Background informationthis assignment tests your

Background Information This assignment tests your understanding of and ability to apply the programming concepts we have covered throughout the unit. The concepts covered in the second half of the unit build upon the fun ...

Assignment - proposal literature review research method1

Assignment - Proposal, Literature Review, Research Method 1. Abstract - Summary of the knowledge gap: problems of the existing research - Aim of the research, summary of what this project is to achieve - Summary of the a ...

Overviewthis tasks provides you an opportunity to get

Overview This tasks provides you an opportunity to get feedback on your Learning Summary Report. The Learning Summary Report outlines how the work you have completed demonstrates that you have met all of the unit's learn ...

Task - hand execution of arraysoverviewin this task you

Task - Hand Execution of Arrays Overview In this task you will demonstrate how arrays work by hand executing a number of small code snippets. Instructions Watch the Hand Execution with Arrays video, this shows how to ste ...

Task arrays and structsoverviewin this task you will

Task: Arrays and Structs Overview In this task you will continue to work on the knight database to help Camelot keep track of all of their knights. We can now add a kingdom struct to help work with and manage all of the ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As