Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I already have the code for this assignment but there's something of the code that I want to fix, please help me Here's the assignment:

I already have the code for this assignment but there's something of the code that I want to fix, please help me

Here's the assignment:

Consider the following class:

public class Sequence

{

private int[] values;

public Sequence(int size) { values = new int[size]; }

public void set(int i, int n) { values[i] = n; }

public int get(int i) { return values[i]; }

public int size() { return values.length; }

}

Add a method

public boolean equals(Sequence other)

that checks whether two sequences have the same values in the same order.

The code of the resource class:

public class U6E11R { private int[] values; public U6E11R(int size) { values = new int[size]; } public void set(int i, int n) { values[i] = n; } public int get(int i) { return values[i]; } public int size() { return values.length; }

public boolean equals(U6E11R other) { // Check if size of both sequence is same or not if(size() != other.size()) return false; for(int i = 0; i < size(); i++){ if(get(i) != other.get(i)) return false; } return true; } }

The code of the driver class:

// Main class to test both the methods class U6E11D

{ public static void main(String[] args)

{ U6E11R s1 = new U6E11R(9); U6E11R s2 = new U6E11R(7); // Populate s1 s1.set(0, 1); s1.set(1, 4); s1.set(2, 9); s1.set(3, 16); s1.set(4, 9); s1.set(5, 7); s1.set(6, 4); s1.set(7, 9); s1.set(8, 11); // Populate s2 s2.set(0, 11); s2.set(1, 11); s2.set(2, 7); s2.set(3, 9); s2.set(4, 16); s2.set(5, 4); s2.set(6, 1); System.out.println(s1.equals(s2)); } }

I want the lines

U6E11R s1 = new U6E11R(9); U6E11R s2 = new U6E11R(7); // Populate s1 s1.set(0, 1); s1.set(1, 4); s1.set(2, 9); s1.set(3, 16); s1.set(4, 9); s1.set(5, 7); s1.set(6, 4); s1.set(7, 9); s1.set(8, 11); // Populate s2 s2.set(0, 11); s2.set(1, 11); s2.set(2, 7); s2.set(3, 9); s2.set(4, 16); s2.set(5, 4); s2.set(6, 1); System.out.println(s1.equals(s2)); } }

that are currently in the driver class to be in the resource class as a method or something that the driver class can just call

Step by Step Solution

There are 3 Steps involved in it

Step: 1

Prompt You have code for an assignment that includes a Sequence class and a U6E11R class The U6E11R class already has an equals method but you want to ... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Income Tax Fundamentals 2013

Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill

31st Edition

1111972516, 978-1285586618, 1285586611, 978-1285613109, 978-1111972516

More Books

Students also viewed these Programming questions

Question

Do the calculations to determine the missing amounts in the table.

Answered: 1 week ago