Advertisement
orxan007

Untitled

Oct 21st, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.41 KB | None | 0 0
  1. /*-------------------------------------------------------------------------
  2. // AUTHOR: Orkhan Taghizada.
  3. // FILENAME: Lab7.
  4. // SPECIFICATION: Making program for students.
  5. // FOR: CSE 110- Lab #7
  6. // TIME SPENT: 20 Minutes.
  7. //-----------------------------------------------------------*/
  8. public class Student {
  9. // declare some variables of different types:
  10.  
  11. // an int called studentID
  12. int studentId;
  13. // a string called studentMajor
  14. String studentMajor;
  15. // an int called studentCredits
  16. int studentCredits;
  17. // an int called studentPoints
  18. int studentPoints;
  19. // a string called firstName
  20. String firstName;
  21. // a string called lastName
  22. String lastName ;
  23.  
  24. public Student (int id, String major, int credits, int points, String fName, String lName)
  25. {
  26. studentId = id;
  27. studentMajor=major;
  28. studentCredits=credits;
  29. studentPoints =points;
  30. firstName =fName;
  31. lastName = lName;
  32. // write the segment of code
  33. //that assigns input data to the data members
  34.  
  35.  
  36. }
  37. public int getID()
  38. {
  39. // write a line of code
  40. //that returns the student ID
  41. return getID();
  42. }
  43. public String getMajor()
  44. {
  45. // write a line of code
  46. //that returns the student major
  47. return getMajor();
  48. }
  49. public int getGradePoints ()
  50. {
  51. // write a line of code
  52. //that returns the student grade points
  53. return getGradePoints ();
  54. }
  55. public int getCredits()
  56. {
  57. // write a line of code
  58. //that returns the student total credits
  59. return getCredits();
  60. }
  61. public String getFullName()
  62. {
  63. // write a line of code
  64. //that returns the full name.
  65. // for this functionality, you need to create a private method ‘createFullName’
  66. // you have to call this private method here and then return the fullName. Like
  67. return createFullName();
  68.  
  69. }
  70. private String createFullName()
  71. {
  72. // use the concatenation of firstName and lastName
  73. // to create full name and then return the full name.
  74. String FullName = firstName + lastName;
  75. return FullName;
  76. }
  77. public void changeMajor(String newMajor, int newPoints, int newCredits) {
  78. if (studentPoints<newPoints && studentCredits<newCredits){
  79. // Change the value of the Student object’s major
  80. // variable to the new input’s value.
  81. studentMajor = newMajor;
  82. studentCredits =newCredits;
  83. studentPoints=newPoints;
  84. System.out.println(getFullName() + "has changed majors to" + newMajor);
  85. }else {
  86. System.out.println("Invalid attempt to change major");
  87. }
  88. }}
  89.  
  90.  
  91. import java.util.Scanner;
  92. public class Lab7
  93. {
  94. public static void main(String[] args)
  95. {
  96. Scanner in = new Scanner(System.in);
  97. //declare variables where you will store
  98. //inputs from user
  99. int studentID;
  100. String studentMajor;
  101. int studentCredits;
  102. int studentGradePoints;
  103. String firstName;
  104. String lastName;
  105.  
  106. System.out.println("Enter first name :" );
  107. firstName=in.next();
  108. System.out.println("Enter lst name :");
  109. lastName=in.next();
  110. System.out.println("Enter student ID " );
  111. studentID=in.nextInt();
  112. System.out.println("Enter student major :");
  113. studentMajor=in.next();
  114. System.out.println("Enter the number of credits earned by the student");
  115. studentCredits =in.nextInt();
  116. System.out.println("Enter student's number of Points");
  117. studentGradePoints=in.nextInt();
  118. //Call the get methods(getID, getMajor...)
  119. //to display Student1
  120. //ID, major, grade points, and number of credits.
  121. // call the getFullName method to get the full name of the student.
  122. Student Student1 = new Student( studentID, studentMajor, studentCredits, studentGradePoints, firstName , lastName);
  123. System.out.println("STUDENT INFORMATIONS \n");
  124. System.out.println("The name of student is: "+
  125. Student1.getFullName()+"\n");
  126.  
  127. System.out.println("The student ID number is : "
  128. +Student1.getID()+ "\n");
  129. System.out.println("Major is: "
  130. + Student1.getMajor()+ ".\n");
  131. System.out.println("The student’s number of points is "
  132. + Student1.getGradePoints()+"\n");
  133. System.out.println("Number of earned credits is "
  134. +Student1.getCredits()+ ".\n");
  135. // Attempt to change the major to
  136. // “International Affairs” with 400 points and 500 (you can use other values as well)
  137. //by calling changeMajor(String newMajor, int newPoints, int newCredits)
  138. // credits. This should not succeed. It should print error.
  139. // Change just the student’s major to
  140. // “International Affairs” by calling changeMajor(String newMajor)
  141. // Print out the following:
  142. // <Student full name> has changed majors to <Student Major>
  143.  
  144.  
  145. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement