Wednesday, September 2, 2020

#151 Create class Student that has the following data

Create class Student that has the following data - Computer Science

ChemistryExplain daily providing Q&A content “#151 Create class Student that has the following data" in Computer science, Ba computer science, Berkeley computer science, Computer science associate degree jobs
ChemistryExplain “#151 Create class Student that has the following data in Computer science, Ba computer science, Berkeley computer science, Computer science
Get the Free Online Chemistry Q&A Questions And Answers with explain. To crack any examinations and Interview tests these Chemistry Questions And Answers are very useful. Here we have uploaded the Free Online Chemistry Questions. Here we are also given the all chemistry topic.
 ChemistryExplain team has covered all Topics related to inorganic, organic, physical chemistry, and others So, Prepare these Chemistry Questions and Answers with Explanation Pdf.
For More Chegg Questions

Free Chegg Question

1- Create class Student that has the following data: id(int), name(string), gpa (double), generate constructor, setter/getter and toString methods.
2- Create class Car that has the following data: plateNo(int), brand(String), generate constructor, setter/getter and toString methods.
3- Create a new class, call it GM_Test, in the class create
a- generic method called swapFirstLast, it receives a generic type array, and swaps the last element in the array with the first one.
b- generic method called reverse, it receives a generic type array, and reverse the order of the elements in the array.
C- Generic method shift that receives an a generic type array and shifts its element one position to the left as depicted by the following figure
So after calling the method, the above array will be as follows
d- Generic method print that receives a generic type array and prints its elements.
e- Create main method, and in the method create the following arrays and fill them with elements: Array of students (3 elements) Array of accounts (4 elements)
f- In the main method, call the methods in a,b,c on the array of students and accounts. Each time, print the array before you call the method, then print it after calling the method to see its effects.
g- Create the following arrays:
int intArray[]={4,1,7,9);
char chArray[]={'a','b','c','d'};
call the methods in a,b,c on the array of intArray and chArray. Each time, print the array before you call the method, then print it after calling the method to see its effects.
 For More Chemistry Notes and Helpful Content Subscribe Our YouTube Chanel - Chemistry Explain  

Free Chegg Answer

Code
Exercise 1
1)
Student class
public class Student {
private int id;
private String name;
private double gpa;
public Student(int id, String name, double gpa) {
this.id = id;
this.name = name;
this.gpa = gpa;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getGpa() {
return gpa;
}
public void setGpa(double gpa) {
this.gpa = gpa;
}

@Override
public String toString() {
return "Student{" + "Id=" + id + ", Name=" + name + ", GPA=" + gpa + '}';
}


}
2)
Car class

public class Car {
private int palteNo;
private String brand;
public Car(int palteNo, String brand) {
this.palteNo = palteNo;
this.brand = brand;
}
public int getPalteNo() {
return palteNo;
}
public void setPalteNo(int palteNo) {
this.palteNo = palteNo;
}
public String getBrand() {
return brand;
}
public void setBrand(String brand) {
this.brand = brand;
}
@Override
public String toString() {
return "Car{" + "Palte Number=" + palteNo + ", Brand=" + brand + '}';
}
}
3)

public class GM_Test {

public static void main(String[] args) {
System.out.println("Student array:");
Student students[]={new Student(1001, "Jack", 3.4),new Student(1002, "Bob", 3.9),new Student(1003, "Jill", 4.4)};
print(students);
System.out.println("\n\nCar array:");
Car cars[]={new Car(985,"Foard"),new Car(758,"MG"),new Car(147,"Honda"),new Car(478,"Maruti")};
print(cars);

Integer intArray[]={4,1,7,9};
Character chArray[]={'a','b','c','d'};

System.out.println("\n\nOriginal integer array:");
print(intArray);
swapFirstLast(intArray);
System.out.println("After swaping first and last element array is: ");
print(intArray);
shift(intArray);
System.out.println("After shifting array is: ");
print(intArray);
reverse(intArray);
System.out.println("After reverseing array is: ");
print(intArray);

System.out.println("\n\nOriginal Character array:");
print(chArray);
swapFirstLast(chArray);
System.out.println("After swaping first and last element array is: ");
print(chArray);
shift(chArray);
System.out.println("After shifting array is: ");
print(chArray);
reverse(chArray);
System.out.println("After reverseing array is: ");
print(chArray);
}
public static < E > void swapFirstLast( E[] inputArray ) {
E temp;
temp =inputArray[0];
inputArray[0]=inputArray[inputArray.length-1];
inputArray[inputArray.length-1]=temp;
}
public static < E > void reverse( E[] inputArray ) {
E temp;
int i, k;
int size=inputArray.length;
for (i = 0; i < size / 2; i++) {
temp = inputArray[i];
inputArray[i] = inputArray[size - i - 1];
inputArray[size - i - 1] = temp;
}
}
public static < E > void shift( E[] inputArray ) {
E temp=inputArray[0];
for(int i=0;i<inputArray.length-1;i++)
inputArray[i]=inputArray[i+1];
inputArray[inputArray.length-1]=temp;
}

public static < E > void print( E[] inputArray ) {
for(int i=0;i<inputArray.length;i++)
System.out.println(inputArray[i]);
}
}

Labels: , ,

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home