ITDR2104 Programming Assignment 1 The objective of this assignment is to impleme
ID: 3737092 • Letter: I
Question
ITDR2104 Programming Assignment 1 The objective of this assignment is to implement a Student class Create a new project in your IDE and add a class in the project with a suitable class name The class should be created using the following UML: Student -idno:int name:String -gender:char major:String +Studento +Student(id:int,name:String.gender char) +getldnoO:int +getName:String +getGender0:char +getMajorO:String +setMajor(major:String):void +toString:Strin The major or specialization for a student can be any one of Software, Network, Security or Database Management. In order to test your class, create another class that contains the main method (i.e. your main program). The code in the main method should crcatc n number of objects, where n' depends on how many students you want to have. [You should test the concepts of a dynamic array]. In each object, allow the user to select any one of the specialization and set it in the object. Also the program should print the contents of all objects using the toString method. You must submit the source code on or before 29-03-2018Explanation / Answer
import java.io.IOException;
import java.util.Scanner;
public class Test {
public static void main(String[] args) throws IOException {
{
// Using Scanner for Getting Input from User
@SuppressWarnings("resource")
Scanner in = new Scanner(System.in);
int a = in.nextInt();
System.out.println("Entered integer "+a);
Student[] studentArray = new Student[a];
for (int i = 0; i < a; i++){
char M='m';
studentArray[i] = new Student(i, null, M);
String[] strings= {"Software", "Network", "Security", "DatabaseManagement"};
System.out.println("Please Entered integer from 0 to 3"
+ "0-Software "+ "1- Network"+"2- Security"+"3- DatabaseManagement");
int a1 = in.nextInt();
System.out.println("Entered value"+a1);
String choice= strings[a1];
studentArray[i].setMajor(choice);
}
}
}
}
package project;
public class Student {
int idno;
String name;
char gender;
String major;
public Student(int idno, String name, char gender) {
super();
this.idno = idno;
this.name = name;
this.gender = gender;
}
public String getMajor() {
return major;
}
public void setMajor(String major) {
this.major = major;
}
public int getIdno() {
return idno;
}
public String getName() {
return name;
}
public char getGender() {
return gender;
}
@Override
public String toString() {
return "Student [idno=" + idno + ", name=" + name + ", gender=" + gender + ", major=" + major + "]";
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.