Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please Use JAVA for this and make your code as simple as possible. assigned prob

ID: 3847671 • Letter: P

Question

Please Use JAVA for this and make your code as simple as possible.

assigned problem:

A class object of your choice (Full points ONLY if invariants are checked properly everywhere. "Checked properly" includes throwing an exception when necessary)

(2 Points) A constructor

(2 Points) An overloaded constructor

(2 Points) At least two properties (and the corresponding getters/setters)

(2 Points) having at least one array type property

(2 Points) having at least one non-array reference type property

(2 Points) A method that takes in a parameter and returns a value (other than getters/setters)

(2 Points) A method that takes in at least two parameters and doesn't return a value (modifies the class properties)

(2 Points) A method that loops through an array to manipulate or gather data from the array

(2 Points) a toString() method

(2 Points) an equals() method

A driver for your class object

(2 Points) for testing creating valid and invalid instances of the class object

(4 Points) for testing every public method (including getters and setters) with valid and invalid values (i.e. test the invariants)

(4 Points) for testing the boundary conditions (lower and upper boundaries) for every public methods in the class (including getters and setters)

Explanation / Answer

Code:-

/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Prog1
{
public int x;
public int y;
int arr[];
public String message;
  
Prog1(){
x=0;
y=0;
}
Prog1(int x,int y){
this.x=x;
this.y=y;
}
void set_x(int x){
this.x=x;
}
  
void set_y(int y){
this.y=y;
}
void set_arr(int arr[]){
this.arr=arr;
}
int get_x(){
return x;
}
void change_prop(int x,int y){
this.x=x;
this.y=y;
}
void change_x(int x){
this.x=x;
}
void change_y(int y){
this.y=y;
}
public String toString()
{
return message;
}
  
int get_y(){
return y;
}
int sum_of_array(){
int sum=0;
for(int i=0;i<arr.length;i++){
sum=sum+arr[i];
}
}
@Override
public boolean equals(Object o) {

// If the object is compared with itself then return true
if (o == this) {
return true;
}
return false;
}
   public static void main (String[] args) throws java.lang.Exception
   {
       Prog1 p=new Prog1();
   System.out.println(p.get_x());
   }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote