What this Lab Is About: Given a UML diagram, learn to design a class Learn how t
ID: 3862304 • Letter: W
Question
What this Lab Is About: Given a UML diagram, learn to design a class Learn how to define constructor, accessor, mutator and toStringOmethods, etc Learn how to create an object and call an instance method. Coding Guidelines for All ments You will be graded on this Give identifiers semantic meaning and make them easy to read (examples numStudents, grossPay, etc) Keep identifiers to a reasonably short length. Use upper case for constants. Use title case (first letter is u case) for classes. Use lower case with uppercase word separators for all other identifiers ivariables methods, objects) Use tabs or spaces to indent code within blocks (code surrounded by braces). This includes classes, methods, and code associated with ifs, switches and loops. Be consistent with the number of spaces or tabs that you use to indent. Use white space to make your program more readable r Use comments properly before or after the ending brace of classes, methods, and blocks to identify to which block it belongs 1. Lab Description For this Lab you have to implement a class called Student. Student class should have instance variables studentID, firstName, lastName, major, gradePoints, and totalCredits. For Student class, supply a constructor and the following methods: getld0, getFullName0, getMajoro, getGradepoints0, getCredits0, etc. See the following UML diagram for Student class Student student ID int first Name String lastName: String -major String grade Points int total Credits int +Student (int, String, String String int, int) +get Id int get Full String Name +getMajor String +get Grade points nt +get Credits int +changeMajor (String void +change Major (String, int, int): void String +toStringExplanation / Answer
I have Pasted 2 java Files below
1 is Student.java
2nd is Lab7.java
Student.java
package com.program.chegg;
/*---------------------------------------------------------
// AUTHOR: your name
// ASU ID: your 10 digits ASU ID
// FILENAME: title of the source file
// SPECIFICATION: description of the program
// TIME SPENT: how long it took you to complete the lab
//-------------------------------------------------------*/
public class Student {
private int studentID;
private String firstName;
private String lastName;
private String major;
private int gradePoints;
private int totalCredits;
public Student(int studentID, String firstName, String lastName, String major, int gradePoints, int totalCredits) {
this.studentID = studentID;
this.firstName = firstName;
this.lastName = lastName;
this.major = major;
this.gradePoints = gradePoints;
this.totalCredits = totalCredits;
}
public int getID() {
return studentID;
}
public String getFullName() {
return firstName + " " + lastName;
}
public String getMajor() {
return major;
}
public int getGradepoints() {
return gradePoints;
}
public int getCredits() {
return totalCredits;
}
public void changeMajor(String major) {
this.major = major;
}
public void changemajor(String newMajor, int newPoints, int newCredits) {
if ((newPoints <= this.gradePoints) && (newCredits <= this.totalCredits)) {
this.major = newMajor;
} else {
System.out.println("Invalid attempt");
}
}
@Override
public String toString() {
System.out.println("================================================");
return String.format("%s %s %s %s %s ", "Student ID : " + String.valueOf(getID()), "Student Name: " + getFullName(), "Major : " + getMajor(), "Num of Points: " + String.valueOf(getGradepoints()), "Total Credits: " + String.valueOf(getCredits()));
}
}
Lab7.java
package com.program.chegg;
import java.util.Scanner;
/*---------------------------------------------------------
// AUTHOR: your name
// ASU ID: your 10 digits ASU ID
// FILENAME: title of the source file
// SPECIFICATION: description of the program
// TIME SPENT: how long it took you to complete the lab
//-------------------------------------------------------*/
public class Lab7 {
public static void main(String[] args) {
String firstName;
String lastName;
String fullName;
String major;
String oldMajor;
int studentId;
int points;
final int totalCredits = 100;
Scanner scan = new Scanner(System.in);
System.out.println("Enter first Name: ");
firstName = scan.next();
System.out.println("Enter last Name: ");
lastName = scan.next();
System.out.println("Enter student major: ");
major = scan.next();
System.out.println("Enter student ID: ");
studentId = scan.nextInt();
System.out.println("Enter # of points: ");
points = scan.nextInt();
Student student1 = new Student(studentId, firstName, lastName, major, points, totalCredits);
fullName = student1.getFullName();
System.out.println("Student Name: " + fullName);
System.out.println("Student ID: " + student1.getID());
System.out.println();
System.out.println(student1.toString());
oldMajor = student1.getMajor();
System.out.println("Do you want to Change the major - Yes/No");
String yes_no = scan.next();
if (!oldMajor.equals(major) || yes_no.equals("yes".toLowerCase())) {
student1.changemajor(major, points, totalCredits);
student1.changeMajor(major);
System.out.println("Student has changed major from " + oldMajor + " to " + major);
student1.toString();
}
}
}
This code is tested and Change the author name and other names accordingly.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.