Question & Answer: Give the output from the program. public class ArrayTester public static void main String args) Numbers nums…..

Need these simple coding and give output of these 2 simple questions IN JAVA

Give the output from the program. public class ArrayTester public static void main String args) Numbers nums new Numbers 4) nums: rint dai rint Class Numbers private int list ublic Numbers (int size list, new int size] for (int index 0 index K size: index list index] index 3; public void print or (int num lis System. out print (num print with space System, out rintln. public void update for int index 1: index list. length index list Lindex] list index 11 1; list 0] list. length;

.

1)Give the output from the program. public class ArrayTester public static void main String args) Numbers nums new Numbers 4) nums: rint dai rint Class Numbers private int list ublic Numbers (int size list, new int size] for (int index 0 index K size: index list index] index 3; public void print or (int num lis System. out print (num print with space System, out rintln. public void update for int index 1: index list. length index list Lindex] list index 11 1; list 0] list. length;

2) 

Expert Answer

 1)

public class ArrayTester {

public static void main(String[] args) {
Numbers nums=new Numbers(4);//it initialize the list with index+3
nums.print();//print the values of list
nums.update();//update the nums according to update method
nums.print();
}

}

class Numbers{
private int [] list;
public Numbers (int size){//initialize the list
list =new int [size];
for (int index =0;index<size;index++)
list[index]=index*3;// each element of list is index*3

}
public void print(){
for (int num:list)
System.out.println(num +””);
System.out.println();
}
public void update(){
for (int index=1;index<list.length;index++)
list[index]=list[index-1]+1;//current element will become the previous element+1
list[0]=list.length;//first element is equal to length of list
}
}

2)

Name class:

public class Name {

String first;
String last;

public Name(String first,String last) {
this.first=first;
this.last=last;//initialize the value

}
public String toString()
{
return first+” “+last;
}
}

Student class:

public class Student {
Name name;
double gpa;
public Student(String first,String last,double gpa) {
this.name=new Name(first, last);//initialize the value
this.gpa=gpa;

}
public String toString()
{
return name.toString()+” “+gpa;
}
public void updateGPA(double gpa)
{
this.gpa=gpa;//update the gpa depends upon value
}

Still stressed from student homework?
Get quality assistance from academic writers!