Write My Paper Button

WhatsApp Widget

COMP2140 Java Programming: Java Basics

$20 Bonus + 25% OFF

Securing Higher Grades Costing Your Pocket?
Book Your Assignment at The Lowest Price
Now!

Students Who Viewed This Also Studied

COMP2140 Java Programming

Question:

rn

rn

Topic 1: Java Basics – Loops, Text I/O, Methods, and Arrays (15%)

rn

    rn

  1. (3%)Write a java program that uses a loop with selections to output the average of the numbers in the range of [5, 100] (with a step size of 5) that are multiples of 10 but not divisible by 3.
  2. rn

  3. (3%)Write a program that will count the number of characters, words, and lines in a file. Words are separated by whitespace characters. The file name should be passed as a command-line argument, as shown in the figure below. Feel free to make your own sensible text file for testing and choose your file name.
  4. rn

rn

rn

    rn

  1. (3%)Write the methods with the following headers:
  2. rn

rn

public static int reverse(int number) // Return the reversal of an integer, e.g., reverse(456) returns 654

rn

public static boolean isPalindrome(int number) // Return true if number is a palindrome

rn

Use the reverse method to implement isPalindrome. A number is a palindrome if its reversal is the same as itself. Write a test main program that prompts the user to enter an integer and reports whether the integer is a palindrome.

rn

    rn

  1. (3%)Write a program that prompts the user to enter two arrays of integers and displays the common elements that appear in both arrays. Note that the first number in the input indicates the number of the elements in the list. This number is not part of the list.
  2. rn

rn

Here is a sample run:

rn

Enter list1: 5 5 2 10 1 6

rn

Enter list2: 9 2 3 10 3 34 35 67 3 1 

rn

The common elements are 2 10 1

rn

    rn

  1. (3%)The inverse of a square matrix A is denoted A-1, such that A × A-1 = I, where I is the identity matrix with all 1s on the diagonal and 0 on all other cells. The inverse of a 2×2 matrix A can be obtained using the following formula:       
  2. rn

rn

rn

Implement the following method to obtain an inverse of 2×2 matrix:

rn

public static double[][] inverse(double[][] A)

rn

The method returns null if ad – bc is 0.

rn

Write a test program that prompts the user to enter a, b, c, d for a matrix, and displays its inverse matrix.

rn

Here are three sample runs:

rn

Enter a, b, c, d: 1 2 3 4

rn

-2.0 1.0

rn

1.5 -0.5

rn

Enter a, b, c, d: 0.5 2 1.5 4.5

rn

-6.0 2.6666666666666665

rn

2.0 -0.6666666666666666

rn

Enter a, b, c, d: 1 2 3 6 

rn

No inverse matrix

rn

Topic 2: Java OOP – Objects and Classes (10%)

rn

    rn

  1. (5%) Design a class named https://myassignmenthelp.com/au/anu/comp2140-java-programming/’Accounthttps://myassignmenthelp.com/au/anu/comp2140-java-programming/’ that contains:
  2. rn

rn

    rn

  • A private int data field named id for the account (default 0).
  • rn

  • A private double data field named balance for the account (default 0).
  • rn

  • A private double data field named annualInterestRate that stores the current interest rate (default 0). Assume that all accounts have the same interest rate.
  • rn

  • A private Date data field named dateCreated that stores the date when the account was created.
  • rn

  • A no-arg constructor that creates a default account.
  • rn

  • A constructor that creates an account with the specified id and initial balance.
  • rn

  • The accessor and mutator methods for id, balance, and annualInterestRate.
  • rn

  • The accessor method for dateCreated.
  • rn

  • A method named getMonthlyInterestRate() that returns the monthly interest rate.
  • rn

  • A method named getMonthlyInterest() that returns the monthly interest.
  • rn

  • A method named withdraw that withdraws a specified amount from the account.
  • rn

  • A method named deposit that deposits a specified amount to the account.
  • rn

rn

Implement the class as defined above and before that draw a UML class diagram as your OOP design. Note that the method getMonthlyInterest() is to return monthly interest, not the interest rate. Monthly interest is balance * monthlyInterestRate; And monthlyInterestRate is annualInterestRate / 12.

rn

Then write a test program that creates an Account object with an account ID of 1001, a balance of $20,000, and an annual interest rate of 4.5%. Use the withdraw method to withdraw $2,500 and print the balance. Use the deposit method to deposit $3,000, and print the balance, the monthly interest, and the date when this account was created.

rn

    rn

  1. (5%) The Eight Queens problem is to find a solution to place a queen in each row on a chessboard such that no two queens can attack each other. You can use a two-dimensional array to represent a chessboard. However, since each row can have only one queen, it is sufficient to use a one-dimensional array to denote the position of the queen in the row. Thus, you can define the queensarray as:
  2. rn

rn

int[] queens = new int[8];

rn

Assign j to queens[i] to denote that a queen is placed in row i and column j.

rn

Define a class named EQ to represent eight queens in a chess board with the following members:

rn

    rn

  1. A private data field queens of the type int[].
  2. rn

  3. A no-arg constructor that constructs an object of EQ default queens values of -1s in the array.
  4. rn

  5. A constructor named EQ(int[] queens) that constructs an object of EQ with the specified queen placement.
  6. rn

  7. A method named get(int i) that returns queens[i].
  8. rn

  9. A method named set(int i, int j) that sets queens[i] with j.
  10. rn

  11. A method named isSolved() that returns true if all queens are placed in the board correctly.
  12. rn

  13. A method named printBoard() that displays the board with the queens like the following:
  14. rn

rn

|X| | | | | | | |

rn

| | | | |X| | | |

rn

| | | | | | | |X|

rn

| | | | | |X| | |

rn

| | |X| | | | | |

rn

| | | | | | |X| |

rn

| |X| | | | | | |

rn

| | | |X| | | | |

rn

Implement the class and use the following program to test your class.

rn

  public static void main(String[] args) {

rn

    EQ board1 = new EQ();

rn

    board1.set(0, 2);

rn

    board1.set(1, 4);

rn

    board1.set(2, 7);

rn

    board1.set(3, 1);

rn

    board1.set(4, 0);

rn

    board1.set(5, 3);

rn

    board1.set(6, 6);

rn

    board1.set(7, 5);

rn

    System.out.println(https://myassignmenthelp.com/au/anu/comp2140-java-programming/”Is board 1 a correct eight queen placement? https://myassignmenthelp.com/au/anu/comp2140-java-programming/”

rn

        + board1.isSolved());

rn

rn

    EQ board2 = new EQ(new int[] { 0, 4, 7, 5, 2, 6, 1, 3 });

rn

    if (board2.isSolved()) {

rn

      System.out.println(https://myassignmenthelp.com/au/anu/comp2140-java-programming/”Eight queens are placed correctly https://myassignmenthelp.com/au/anu/comp2140-java-programming/”

rn

        + https://myassignmenthelp.com/au/anu/comp2140-java-programming/”in board 2https://myassignmenthelp.com/au/anu/comp2140-java-programming/”);

rn

      board2.printBoard();

rn

    }

rn

    else {

rn

      System.out.println(https://myassignmenthelp.com/au/anu/comp2140-java-programming/”Eight queens are placed incorrectly https://myassignmenthelp.com/au/anu/comp2140-java-programming/” 

rn

        + https://myassignmenthelp.com/au/anu/comp2140-java-programming/”in board 2https://myassignmenthelp.com/au/anu/comp2140-java-programming/”);

rn

    }

rn

  }

rn

Topic 3: Java OOP – Inheritance and Polymorphism (5%)

rn

    rn

  1. (5%)Following from the Topic 2 problem 6, the Account class was defined to model a bank account. An account has the properties account number, balance, annual interest rate, and date created, and methods to deposit and withdraw funds. Create two subclasses for checking and saving accounts. A checking account has an overdraft limit, but a savings account cannot be overdrawn. Draw the UML diagram for the classes and implement them. Write a sensible test program that creates objects of Account, SavingsAccount, and CheckingAccount, simulate their different transactions and invokes their toString() methods for printing the account status after each transaction.
  2. rn

rn

COMP2140 Java Programming

Answer in Detail


Solved by qualified expert

Get Access to This Answer

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Hac habitasse platea dictumst vestibulum rhoncus est pellentesque. Amet dictum sit amet justo donec enim diam vulputate ut. Neque convallis a cras semper auctor neque vitae. Elit at imperdiet dui accumsan. Nisl condimentum id venenatis a condimentum vitae sapien pellentesque. Imperdiet massa tincidunt nunc pulvinar sapien et ligula. Malesuada fames ac turpis egestas maecenas pharetra convallis posuere. Et ultrices neque ornare aenean euismod. Suscipit tellus mauris a diam maecenas sed enim. Potenti nullam ac tortor vitae purus faucibus ornare. Morbi tristique senectus et netus et malesuada. Morbi tristique senectus et netus et malesuada. Tellus pellentesque eu tincidunt tortor aliquam. Sit amet purus gravida quis blandit. Nec feugiat in fermentum posuere urna. Vel orci porta non pulvinar neque laoreet suspendisse interdum. Ultricies tristique nulla aliquet enim tortor at auctor urna. Orci sagittis eu volutpat odio facilisis mauris sit amet.

Tellus molestie nunc non blandit massa enim nec dui. Tellus molestie nunc non blandit massa enim nec dui. Ac tortor vitae purus faucibus ornare suspendisse sed nisi. Pharetra et ultrices neque ornare aenean euismod. Pretium viverra suspendisse potenti nullam ac tortor vitae. Morbi quis commodo odio aenean sed. At consectetur lorem donec massa sapien faucibus et. Nisi quis eleifend quam adipiscing vitae proin sagittis nisl rhoncus. Duis at tellus at urna condimentum mattis pellentesque. Vivamus at augue eget arcu dictum varius duis at. Justo donec enim diam vulputate ut. Blandit libero volutpat sed cras ornare arcu. Ac felis donec et odio pellentesque diam volutpat commodo. Convallis a cras semper auctor neque. Tempus iaculis urna id volutpat lacus. Tortor consequat id porta nibh.

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Hac habitasse platea dictumst vestibulum rhoncus est pellentesque. Amet dictum sit amet justo donec enim diam vulputate ut. Neque convallis a cras semper auctor neque vitae. Elit at imperdiet dui accumsan. Nisl condimentum id venenatis a condimentum vitae sapien pellentesque. Imperdiet massa tincidunt nunc pulvinar sapien et ligula. Malesuada fames ac turpis egestas maecenas pharetra convallis posuere. Et ultrices neque ornare aenean euismod. Suscipit tellus mauris a diam maecenas sed enim. Potenti nullam ac tortor vitae purus faucibus ornare. Morbi tristique senectus et netus et malesuada. Morbi tristique senectus et netus et malesuada. Tellus pellentesque eu tincidunt tortor aliquam. Sit amet purus gravida quis blandit. Nec feugiat in fermentum posuere urna. Vel orci porta non pulvinar neque laoreet suspendisse interdum. Ultricies tristique nulla aliquet enim tortor at auctor urna. Orci sagittis eu volutpat odio facilisis mauris sit amet.

Tellus molestie nunc non blandit massa enim nec dui. Tellus molestie nunc non blandit massa enim nec dui. Ac tortor vitae purus faucibus ornare suspendisse sed nisi. Pharetra et ultrices neque ornare aenean euismod. Pretium viverra suspendisse potenti nullam ac tortor vitae. Morbi quis commodo odio aenean sed. At consectetur lorem donec massa sapien faucibus et. Nisi quis eleifend quam adipiscing vitae proin sagittis nisl rhoncus. Duis at tellus at urna condimentum mattis pellentesque. Vivamus at augue eget arcu dictum varius duis at. Justo donec enim diam vulputate ut. Blandit libero volutpat sed cras ornare arcu. Ac felis donec et odio pellentesque diam volutpat commodo. Convallis a cras semper auctor neque. Tempus iaculis urna id volutpat lacus. Tortor consequat id porta nibh.

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Hac habitasse platea dictumst vestibulum rhoncus est pellentesque. Amet dictum sit amet justo donec enim diam vulputate ut. Neque convallis a cras semper auctor neque vitae. Elit at imperdiet dui accumsan. Nisl condimentum id venenatis a condimentum vitae sapien pellentesque. Imperdiet massa tincidunt nunc pulvinar sapien et ligula. Malesuada fames ac turpis egestas maecenas pharetra convallis posuere. Et ultrices neque ornare aenean euismod. Suscipit tellus mauris a diam maecenas sed enim. Potenti nullam ac tortor vitae purus faucibus ornare. Morbi tristique senectus et netus et malesuada. Morbi tristique senectus et netus et malesuada. Tellus pellentesque eu tincidunt tortor aliquam. Sit amet purus gravida quis blandit. Nec feugiat in fermentum posuere urna. Vel orci porta non pulvinar neque laoreet suspendisse interdum. Ultricies tristique nulla aliquet enim tortor at auctor urna. Orci sagittis eu volutpat odio facilisis mauris sit amet.

Tellus molestie nunc non blandit massa enim nec dui. Tellus molestie nunc non blandit massa enim nec dui. Ac tortor vitae purus faucibus ornare suspendisse sed nisi. Pharetra et ultrices neque ornare aenean euismod. Pretium viverra suspendisse potenti nullam ac tortor vitae. Morbi quis commodo odio aenean sed. At consectetur lorem donec massa sapien faucibus et. Nisi quis eleifend quam adipiscing vitae proin sagittis nisl rhoncus. Duis at tellus at urna condimentum mattis pellentesque. Vivamus at augue eget arcu dictum varius duis at. Justo donec enim diam vulputate ut. Blandit libero volutpat sed cras ornare arcu. Ac felis donec et odio pellentesque diam volutpat commodo. Convallis a cras semper auctor neque. Tempus iaculis urna id volutpat lacus. Tortor consequat id porta nibh.

46 More Pages to Come in This Document. Get access to the complete answer.

More COMP2140 COMP2140 Java Programming: Questions & Answers

COMP8038 Cloud Computing with Python

Task
Objective:
You will write python programs that allows you to automate and manage your AWS cloud services. This assignment will test your ability to use the Boto3 package and Ansible to interact with AWS cloud services, as well as your general Python scripting skills. Use free tier on AWS in a …

View Answer

Fundamental Principles and Methodologies

To describe the fundamental principles and methodologies for the analysis and design of typical business information systems. To capture stakeholder needs and transform these into a suitable set of system requirements. To transform requirements into a systems design. Table 1 presents the minimum, av …

View Answer

Management

Sliding Mode Control with a Lemniscate-Based Sliding Surface …

View Answer

Management

Critically evaluate software requirements as inputs toward testing of the final solution. Analyse and critically evaluate appropriate tools and techniques to support the testing process …

View Answer

Content Removal Request

If you are the original writer of this content and no longer wish to have your work published on Myassignmenthelp.com then please raise the
content removal request.

Choose Our Best Expert to Help You

Still in Two Minds? The Proof is in Numbers!

33845 Genuine Reviews With a Rating of 4.9/5.

HRM

Assignment: 6 Pages, Deadline:
22 days

I am really happy with the result, even though I had to make adjustments, and I got a good grade for it.

User ID: 5***20 France

Marketing

Home Work: 1 Page, Deadline:
3 days

Thank you so much! taking a time to do Thank you so much! taking a time to do my assignment my assignment

User ID: 6***98 United States

Assignment

Essay: 4.8 Pages, Deadline:
10 days

A very well presented assignment, all the ideas were very well explained, easy to understand. Definitely will recommend .

User ID: 8***07 Denmark

Business Law

Home Work: 0.9 Pages, Deadline:
1 day

Thank you, very much ????????????! I’m looking forward to working with you guys again.

User ID: 8***94 Canada

Medical

Essay: 1.6 Pages, Deadline:
3 days

This assignment was good I got a really good grade on this assignment so who complete this one great job.

User ID: 8***56 United States

Pharmacy

Assignment: 1 Page, Deadline:
3 days

This assignment was okay but I felt that it could have gotten a better grade but assignment was good.

User ID: 8***56 United States

Marketing

Home Work: 1 Page, Deadline:
11 days

Very reliable work. I liked the quality of assignment. They delivered two days before the day of commitment.

User ID: 8***50 Australia

Management

Assignment: 6 Pages, Deadline:
5 days

Good work and very fast turn around. Happy with the quality of assignment. Definitely would recommend.

User ID: 8***50 Australia

Assignment

Essay: 2 Pages, Deadline:
3 days

Very quick done and professional job. Helped me to gain good marks. Easy to read as answers given very clear.

User ID: 5***21 Blanchardstown, Ireland

Statistics

Home Work: 3 Pages, Deadline:
11 hours

Thank you very much… YOU ARE A GREAT WRITER ! You provide this answer and saved my life !

User ID: 8***32 Blanchardstown, Sri Lanka

Civil Law

Home Work: 3.6 Pages, Deadline:
4 hours

Thanks for the time response and helped me in successfully submitting the assignment. Thanks for this time

User ID: 8***31 United Kingdom, Great Britain

Economics

Home Work: 1.2 Pages, Deadline:
2 hours

Thanks for helping at short notice. Great quality, in the short time provided. All the best

User ID: 8***61 United Kingdom, Great Britain

Management

Assignment: 5 Pages, Deadline:
5 days

This report addresses the assignment brief very well, with much detail on Unilever online presence. The recommendation are good, and more detail/ less …

User ID: 8***01 England, Great Britain

Maths

Home Work: 1 Page, Deadline:
54 minutes

Super quick response time, great detail and construction of the solution. Many thanks for your help in this assignment. All the best

User ID: 8***61 United Kingdom, Great Britain

Maths

Home Work: 1 Page, Deadline:
1 hour

The new answer seems correct and is well explained in detail. Thank you for reviewing the work and for your help on this assignment. All the best.

User ID: 8***61 United Kingdom, Great Britain

Maths

Home Work: 1 Page, Deadline:
1 hour

Very good solution, well explained in detail. Thank you very much for your help on this assignment. All the best.

User ID: 8***61 United Kingdom, Great Britain

Finance

Essay: 4 Pages, Deadline:
7 days

Awesome work! I am fully satisfied with the quality of the content. The writers worked hard to deliver such a deep and wide content. Keep it up.

User ID: 8***46 Batu Caves, Malaysia

Nursing

Assignment: 1 Page, Deadline:
4 days

This powerpoint was neat and concise. The expert definitely followed through with what was asked.

User ID: 6***42 Batu Caves, United States

Nursing

Assignment: 12 Pages, Deadline:
5 days

well written assignment. good references and all done in a timely manner. pricing was good and support available when needed

User ID: 6***93 United Kingdom, Great Britain

Maths

Course Work: 0.4 Pages, Deadline:
2 hours

Great, very clear, thank you very much For your help on this assignment. All the best

User ID: 8***61 United Kingdom, Great Britain

HRM

Assignment: 6 Pages, Deadline:
22 days

I am really happy with the result, even though I had to make adjustments, and I got a good grade for it.

User ID: 5***20 France

Marketing

Home Work: 1 Page, Deadline:
3 days

Thank you so much! taking a time to do Thank you so much! taking a time to do my assignment my assignment

User ID: 6***98 United States

Assignment

Essay: 4.8 Pages, Deadline:
10 days

A very well presented assignment, all the ideas were very well explained, easy to understand. Definitely will recommend .

User ID: 8***07 Denmark

Business Law

Home Work: 0.9 Pages, Deadline:
1 day

Thank you, very much ????????????! I’m looking forward to working with you guys again.

User ID: 8***94 Canada

Medical

Essay: 1.6 Pages, Deadline:
3 days

This assignment was good I got a really good grade on this assignment so who complete this one great job.

User ID: 8***56 United States

Pharmacy

Assignment: 1 Page, Deadline:
3 days

This assignment was okay but I felt that it could have gotten a better grade but assignment was good.

User ID: 8***56 United States

Marketing

Home Work: 1 Page, Deadline:
11 days

Very reliable work. I liked the quality of assignment. They delivered two days before the day of commitment.

User ID: 8***50 Australia

Management

Assignment: 6 Pages, Deadline:
5 days

Good work and very fast turn around. Happy with the quality of assignment. Definitely would recommend.

User ID: 8***50 Australia

Assignment

Essay: 2 Pages, Deadline:
3 days

Very quick done and professional job. Helped me to gain good marks. Easy to read as answers given very clear.

User ID: 5***21 Blanchardstown, Ireland

Statistics

Home Work: 3 Pages, Deadline:
11 hours

Thank you very much… YOU ARE A GREAT WRITER ! You provide this answer and saved my life !

User ID: 8***32 Blanchardstown, Sri Lanka

Civil Law

Home Work: 3.6 Pages, Deadline:
4 hours

Thanks for the time response and helped me in successfully submitting the assignment. Thanks for this time

User ID: 8***31 United Kingdom, Great Britain

Economics

Home Work: 1.2 Pages, Deadline:
2 hours

Thanks for helping at short notice. Great quality, in the short time provided. All the best

User ID: 8***61 United Kingdom, Great Britain

Management

Assignment: 5 Pages, Deadline:
5 days

This report addresses the assignment brief very well, with much detail on Unilever online presence. The recommendation are good, and more detail/ less …

User ID: 8***01 England, Great Britain

Maths

Home Work: 1 Page, Deadline:
54 minutes

Super quick response time, great detail and construction of the solution. Many thanks for your help in this assignment. All the best

User ID: 8***61 United Kingdom, Great Britain

Maths

Home Work: 1 Page, Deadline:
1 hour

The new answer seems correct and is well explained in detail. Thank you for reviewing the work and for your help on this assignment. All the best.

User ID: 8***61 United Kingdom, Great Britain

Maths

Home Work: 1 Page, Deadline:
1 hour

Very good solution, well explained in detail. Thank you very much for your help on this assignment. All the best.

User ID: 8***61 United Kingdom, Great Britain

Finance

Essay: 4 Pages, Deadline:
7 days

Awesome work! I am fully satisfied with the quality of the content. The writers worked hard to deliver such a deep and wide content. Keep it up.

User ID: 8***46 Batu Caves, Malaysia

Nursing

Assignment: 1 Page, Deadline:
4 days

This powerpoint was neat and concise. The expert definitely followed through with what was asked.

User ID: 6***42 Batu Caves, United States

Nursing

Assignment: 12 Pages, Deadline:
5 days

well written assignment. good references and all done in a timely manner. pricing was good and support available when needed

User ID: 6***93 United Kingdom, Great Britain

Maths

Course Work: 0.4 Pages, Deadline:
2 hours

Great, very clear, thank you very much For your help on this assignment. All the best

User ID: 8***61 United Kingdom, Great Britain

Have any Query?

The post COMP2140 Java Programming: Java Basics appeared first on study tools.

Don`t copy text!
WeCreativez WhatsApp Support
Our customer support team is here to answer your questions. Ask us anything!
???? Hi, how can I help?