Create a program that tracks your progress as a student in this class. You will
ID: 3531451 • Letter: C
Question
Create a program that tracks your progress as a student in this class. You will need to store your name, student identification number, the sum of your quiz scores and the sum of your assignment scores.
Develop the following program in Java with two classes. One should be a class called Student. This is the class where you will store all of your information. This class should have four private instance variables. They are as follows:
private String name;
private String id;
private int quizScores;
private int assignmentScores;
The class will have one default constructor.
//Postcondition: creates a Student object which assigns these values to the instance variables
//set name = "";
//set id = "";
//set quizScores = 0;
//set assignmentScores = 0;
public Student()
The class should have the following public methods and only these methods:
//Postcondition: sets the student's name to newName
public void setName(String newName)
//Postcondition: returns the student's name
public String getName()
//Postcondition: sets the student's id to newId
public void setId(String newId)
//Postcondition: returns the the student's id number
public String getId()
//Precondition: newQuiz >= 0
//Postcondition: adds the value of newQuiz to the student's quiz scores
public void addQuiz(int newQuiz)
//Postcondition: returns the sum of the student's quiz scores
public int getQuizScores()
//Precondition: newAssignment >=0
//Postcondition adds the value of newAssignment to the student's assignment scores
public void addAssignment(int newAssignment)
//Postcondition: returns the sum of the student's assignment scores
public int getAssignmentScores()
and add the following overloaded methods:
//Precondition: newQuiz1 >= 0 and newQuiz2 >= 0
//Postcondition: adds the value of newQuiz1 and newQuiz2 to the student's quiz scores
public void addQuiz(int newQuiz1, int newQuiz2)
//Precondition: newAssignment1 >=0 and newAssignment2 >= 0
//Postcondition: adds the value of newAssignment1 and newAssignment2 to the student's assignment scores
public void addAssignment(int newAssignment1, int newAssignment2)
Create a demo class called StudentDemo. This class is like all of our previous assignments where it only has a main method. In this class create an object of type Student. Then change the name to your name. Then change the student id to your student id. Add of all of your quiz scores and then add all of your assignment scores. To add your quiz scores and assignment scores please make calls to both versions of the overloaded methods. Display your name, your student id, your quiz scores, and your assignment scores to the screen.
Explanation / Answer
Hey this is the complete answer to your que : Check it out..It 100% working
..I have also shown the sample output
STUDENT CLASS :
public class Student {
private String name;
private String id;
private int quizScores;
private int assignmentScores;
public Student() {
super();
}
public Student(String name, String id, int quizScores, int assignmentScores) {
super();
this.name = name;
this.id = id;
this.quizScores = quizScores;
this.assignmentScores = assignmentScores;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public int getQuizScores() {
return quizScores;
}
public void setQuizScores(int quizScores) {
this.quizScores = quizScores;
}
public int getAssignmentScores() {
return assignmentScores;
}
public void setAssignmentScores(int assignmentScores) {
this.assignmentScores = assignmentScores;
}
public void addQuiz(int newQuiz)
{
if(newQuiz >= 0)
{
quizScores += newQuiz;
}
}
public void addAssignment(int newAssignment)
{
if(newAssignment >= 0 )
{
this.assignmentScores += newAssignment;
}
}
public void addQuiz(int newQuiz1, int newQuiz2)
{
if(newQuiz1 >= 0 && newQuiz2 >=0 )
{
quizScores += (newQuiz1 + newQuiz2);
}
}
public void addAssignment(int newAssignment1, int newAssignment2)
{
if(newAssignment1 >=0 && newAssignment2 >=0)
{
assignmentScores += (newAssignment1+newAssignment2);
}
}
}
STUDENT DEMO CLASS
public class StudentDemo {
public static void main(String[] args)
{
Student s1=new Student();
s1.setName("Sumit");
s1.setId("2013");
s1.addQuiz(20);
s1.addQuiz(30, 40);
s1.addAssignment(50);
s1.addAssignment(20,70);
System.out.println("---------------------------******--------------------------");
System.out.println("The Student details are :");
System.out.println("Name :"+s1.getName());
System.out.println("ID :"+s1.getId());
System.out.println("Quiz Score :"+s1.getQuizScores());
System.out.println("Assignment Score :"+s1.getAssignmentScores());
System.out.println("-----------------------------******------------------------");
}
}
OUTPUT:
---------------------------******--------------------------
The Student details are :
Name :Sumit
ID :2013
Quiz Score :90
Assignment Score :140
-----------------------------******------------------------
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.