this is the whole problem i did 1 to 3 im stuck at 4 Create a class called Student, with the following attributes/variables: a. studentName (String) b. studentNumber (int)s c. regYear(long) d. faculty(String) e. department(String) 2. Add the following methods in Student: a. accessors and mutators for all variables b. toString method i. Formulate your toString so that it only shows studentName, studentNumber and faculty 3. Create a class called MyFriends, with the following attributes variables: a. studentArray(Student[]) 4. Add the following methods in MyFriends: a. fillArray i. Using scanner ask how many students does the user want to input ii. Capture user input for all of his friends (Of course we are assuming all your friends would be similar UWC students, go ask around and meet new friends, also preferably not in the same Computer Science department … if possible … only if possible) b. main i. Call the fillArray method ii. Count how many Computer Science students iii. If half or more students are Computer Science students, then display “You … need more friends …” iv. Otherwise display “Nice, diversity is good” this is what i have so far for the problem im not really good at arrays import java.util.Scanner; public class Main { private String name; private int sm; private int y; private String fc; private String dept; public Main(String studentName, int studentNumber, int RegYear, String Faculty,String Department ) { name = studentName; sm = studentNumber; y = RegYear; fc = Faculty; dept=Department; } public void display() { System.out.println("StuName: " + name); System.out.println("StuNumber: " + sm); System.out.println("RegYear: " + y); System.out.println("FacultyName: " + fc); System.out.println("Department: " + dept); } public static void main(String args[]) { Scanner in = new Scanner(System.in); System.out.print("Enter studentName: "); String name = in.nextLine(); System.out.print("Enter studentNumber: "); int sm= in.nextInt(); System.out.print("Enter RegYear: "); int y = in.nextInt(); System.out.print("Enter Faculty: "); String fc = in.nextLine(); System.out.print("Enter Department: "); String dept = in.nextLine(); Main obj = new Main(name, sm, y,fc, dept); obj.display(); } }
this is the whole problem i did 1 to 3 im stuck at 4
Create a class called Student, with the following attributes/variables:
a. studentName (String)
b. studentNumber (int)s
c. regYear(long)
d. faculty(String)
e. department(String)
2. Add the following methods in Student:
a. accessors and mutators for all variables
b. toString method
i. Formulate your toString so that it only shows studentName,
studentNumber and faculty
3. Create a class called MyFriends, with the following attributes variables:
a. studentArray(Student[])
4. Add the following methods in MyFriends:
a. fillArray
i. Using scanner ask how many students does the user want to input
ii. Capture user input for all of his friends
(Of course we are assuming all your friends would be similar
UWC students, go ask around and meet new friends, also
preferably not in the same Computer Science department … if
possible … only if possible)
b. main
i. Call the fillArray method
ii. Count how many Computer Science students
iii. If half or more students are Computer Science students, then
display “You … need more friends …”
iv. Otherwise display “Nice, diversity is good”
this is what i have so far for the problem im not really good at arrays
import java.util.Scanner;
public class Main
{
private String name;
private int sm;
private int y;
private String fc;
private String dept;
public Main(String studentName, int studentNumber, int RegYear, String Faculty,String Department )
{
name = studentName;
sm = studentNumber;
y = RegYear;
fc = Faculty;
dept=Department;
}
public void display() {
System.out.println("StuName: " + name);
System.out.println("StuNumber: " + sm);
System.out.println("RegYear: " + y);
System.out.println("FacultyName: " + fc);
System.out.println("Department: " + dept);
}
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.print("Enter studentName: ");
String name = in.nextLine();
System.out.print("Enter studentNumber: ");
int sm= in.nextInt();
System.out.print("Enter RegYear: ");
int y = in.nextInt();
System.out.print("Enter Faculty: ");
String fc = in.nextLine();
System.out.print("Enter Department: ");
String dept = in.nextLine();
Main obj = new Main(name, sm, y,fc, dept);
obj.display();
}
}
Step by step
Solved in 3 steps with 4 images