Question

Hello, Can you please error check my javascript? It should do the following: Write a program...

Hello,

Can you please error check my javascript? It should do the following:

Write a program that uses a class for storing student data. Build the class using the given information.

The data should include the student’s ID number; grades on exams 1, 2, and 3; and average grade.

Use appropriate assessor and mutator methods for the grades (new grades should be passed as parameters).

Use a mutator method for changing the student ID.

Use another method to calculate the average grade.

Write a static method that will accept the two students as parameters and report which one has the highest average grade.

Test all constructors and methods using a separate driver class.

Here is my code so far:

public class Student

{

private int stuID;

private int grade1;

private int grade2;

private int grade3;

private int gradeAvg;

  

Student()

{

stuID=1;

grade1=90;

grade2=100;

grade3=98;

}

Student(int sID,int sgrade1,int sgrade2,int sgrade3)

{

stuID=sID;

grade1=sgrade1;

grade2=sgrade2;

grade3=sgrade3;

}

  

  

public int getStuID()

{

return stuID;

}

public void setStuID(int stuID)

{

this.stuID = stuID;

}

  

  

public int getGrade1()

{

return grade1;

}

public void setGrade1(int grade1)

{

this.grade1 = grade1;

}

  

  

public int getGrade2()

{

return grade2;

}

public void setGrade2(int grade2)

{

this.grade2 = grade2;

}

  

  

public int getGrade3()

{

return grade3;

}

public void setGrade3(int grade3)

{

this.grade3 = grade3;

}

  

  

int calculateAvgGrade()

{

gradeAvg=((grade1+grade2+grade3)/3);

return gradeAvg;

}

  

  

public static int HighGrade(Student s1, Student s2)

{

return(Math.max(s1.gradeAvg,s2.gradeAvg));

}

  

  

  

public static int HighGradeStudent(Student s1, Student s2)

{

  

if(s1.gradeAvg>s2.gradeAvg)

{

return(s1.stuID);

}

else

{

return(s2.stuID);

}

}

}

class StudentDemo

{

public static void main(String args[])

{

Student s1 = new Student();

System.out.println("Data of Student 1");

System.out.println("Student ID is: "+s1.getStuID());

System.out.println("Student grade1 is: "+s1.getGrade1());

System.out.println("Student grade2 is: "+s1.getGrade2());

System.out.println("Student grade3 is: "+s1.getGrade3());

System.out.println("Student1 Average grade is: "+s1.calculateAvgGrade());

  

Student s2 = new Student(2,80,90,100);

System.out.println("\nData of Student 2");

System.out.println("Student ID is: "+s2.getStuID());

System.out.println("Student grade1 is: "+s2.getGrade1());

System.out.println("Student grade2 is: "+s2.getGrade2());

System.out.println("Student grade3 is: "+s2.getGrade3());

System.out.println("Student2 Average grade is: "+s2.calculateAvgGrade());

  

Student s3 = new Student();

System.out.println("\nHighest average grade is: "+s3.HighGrade(s1,s2));

System.out.println("Student ID who has got Highest grade:"+s3.HighGradeStudent(s1,s2));

  

  

}

}

Error: Main method not found in class Student, please define the main method as:
public static void main(String[] args)
or a JavaFX application class must extend javafx.application.Application
Command exited with non-zero status 1

0 0
Add a comment Improve this question Transcribed image text
Answer #1

/**
*
* @author ....
*/
public class Student
{
    private int stuID;
    private int grade1;
    private int grade2;
    private int grade3;
    private int gradeAvg;

Student()
{
stuID=1;
grade1=90;
grade2=100;
grade3=98;
}
Student(int sID,int sgrade1,int sgrade2,int sgrade3)
{
stuID=sID;
grade1=sgrade1;
grade2=sgrade2;
grade3=sgrade3;
}


public int getStuID()
{
     return stuID;
}
public void setStuID(int stuID)
{
     this.stuID = stuID;
}
public int getGrade1()
{
     return grade1;
}
public void setGrade1(int grade1)
{
      this.grade1 = grade1;
}

public int getGrade2()
{
      return grade2;
}
public void setGrade2(int grade2)
{
      this.grade2 = grade2;
}


public int getGrade3()
{
      return grade3;
}
public void setGrade3(int grade3)
{
      this.grade3 = grade3;
}


int calculateAvgGrade()
{
       gradeAvg=((grade1+grade2+grade3)/3);
       return gradeAvg;
}

public static int HighGrade(Student s1, Student s2)
{
      return(Math.max(s1.gradeAvg,s2.gradeAvg));
}

public static int HighGradeStudent(Student s1, Student s2)
{
     if(s1.gradeAvg>s2.gradeAvg) {
      return(s1.stuID);
    }
    else {
        return(s2.stuID);
      }
   }

}

class StudentDemo {
  
public static void main(String args[]) {
Student s1 = new Student();
System.out.println("Data of Student 1");
System.out.println("Student ID is: "+s1.getStuID());
System.out.println("Student grade1 is: "+s1.getGrade1());
System.out.println("Student grade2 is: "+s1.getGrade2());
System.out.println("Student grade3 is: "+s1.getGrade3());
System.out.println("Student1 Average grade is: "+s1.calculateAvgGrade());

Student s2 = new Student(2,80,90,100);
System.out.println("\nData of Student 2");
System.out.println("Student ID is: "+s2.getStuID());
System.out.println("Student grade1 is: "+s2.getGrade1());
System.out.println("Student grade2 is: "+s2.getGrade2());
System.out.println("Student grade3 is: "+s2.getGrade3());
System.out.println("Student2 Average grade is: "+s2.calculateAvgGrade());
Student s3 = new Student();
System.out.println("\nHighest average grade is: "+s3.HighGrade(s1,s2));
System.out.println("Student ID who has got Highest grade:"+s3.HighGradeStudent(s1,s2));
}

    }

Output :

Student.java x plications.Student>grade1 javaapp Output -Student (run)x run: Data of Student 1 Student ID is: 1 Student gradel is: 90 Student grade2 is: 100 Student grade3 is: 98 Student1 Average grade is: 96 Data of Student 2 Student ID is: 2 Student gradel is: 80 Student grade2 is: 90 Student grade3 is: 100 Student2 Average grade is: 90 Highest average grade is: 96 Student ID who has got Highest grade :1 BUILD SUCCESSFUL (total time: 0 seconds)

Add a comment
Know the answer?
Add Answer to:
Hello, Can you please error check my javascript? It should do the following: Write a program...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Modify the objectstudent JAVA program to add a private variable zipcode, you must also add setters...

    Modify the objectstudent JAVA program to add a private variable zipcode, you must also add setters and getter methods for the new variable and modify the toString method. The objectstudent program is in this weeks module, you can give it a default value of 19090. class Student { private int id; private String name; public Student() { id = 8; name = "John"; } public int getid() { return id; } public String getname() { return name; } public void...

  • import java.util.Scanner; public class StudentClient {       public static void main(String[] args)    {   ...

    import java.util.Scanner; public class StudentClient {       public static void main(String[] args)    {        Student s1 = new Student();         Student s2 = new Student("Smith", "123-45-6789", 3.2);         Student s3 = new Student("Jones", "987-65-4321", 3.7);         System.out.println("The name of student #1 is ");         System.out.println("The social security number of student #1 is " + s1.toString());         System.out.println("Student #2 is " + s2);         System.out.println("the name of student #3 is " + s3.getName());         System.out.println("The social security number...

  • I have this program that works but not for the correct input file. I need the...

    I have this program that works but not for the correct input file. I need the program to detect the commas Input looks like: first_name,last_name,grade1,grade2,grade3,grade4,grade5 Dylan,Kelly,97,99,95,88,94 Tom,Brady,100,90,54,91,77 Adam,Sandler,90,87,78,66,55 Michael,Jordan,80,95,100,89,79 Elon,Musk,80,58,76,100,95 output needs to look like: Tom Brady -------------------------- Assignment 1: A Assignment 2: A Assignment 3: E Assignment 4: A Assignment 5: C Final Grade: 82.4 = B The current program: import java.io.File; import java.io.FileNotFoundException; import java.io.FileWriter; import java.io.IOException; import java.util.Scanner; public class main {    public static void main(String[]...

  • need basic default constructor , and shoed an example too s0. write the class Battery and...

    need basic default constructor , and shoed an example too s0. write the class Battery and it has s1. a data for the battery capacity (that is similar to myBalance of the BankAccount class.) s2. a parameterized constructor: public Battery(double amount) s3. a drain mutator s4. a change mutator s5. a getRemainingCapacity accessor Need to run this tester - public class BatteryTester{ public static void main(String[] args) { Battery autoBattery = new Battery(2000); //call default constructor System.out.println("1. battery capacity is...

  • I need to add a method high school student, I couldn't connect high school student to...

    I need to add a method high school student, I couldn't connect high school student to student please help!!! package chapter.pkg9; import java.util.ArrayList; import java.util.Scanner; public class Main { public static Student student; public static ArrayList<Student> students; public static HighSchoolStudent highStudent; public static void main(String[] args) { int choice; Scanner scanner = new Scanner(System.in); students = new ArrayList<>(); while (true) { displayMenu(); choice = scanner.nextInt(); switch (choice) { case 1: addCollegeStudent(); break; case 2: addHighSchoolStudent(); case 3: deleteStudent(); break; case...

  • java This lab is intended to give you practice creating a class with a constructor method,...

    java This lab is intended to give you practice creating a class with a constructor method, accessor methods, mutator methods, equals method , toString method and a equals method. In this lab you need to create two separate classes, one Student class and other Lab10 class. You need to define your instance variables, accessor methods, mutator methods, constructor, toString method and equals method in Student class. You need to create objects in Lab10 class which will have your main method...

  • A. Create a CollegeCourse class. The class contains fields for the course ID (for example, CIS 21...

    A. Create a CollegeCourse class. The class contains fields for the course ID (for example, CIS 210), credit hours (for example, 3), and a letter grade (for example, A). Include get and set methods for each field. Create a Student class containing an ID number and an array of five CollegeCourse objects. Create a get and set method for the Student ID number. Also create a get method that returns one of the Student’s CollegeCourses; the method takes an integer...

  • A. Create a CollegeCourse class. The class contains fields for the course ID (for example, CIS...

    A. Create a CollegeCourse class. The class contains fields for the course ID (for example, CIS 210), credit hours (for example, 3), and a letter grade (for example, A). Include get and set methods for each field. Create a Student class containing an ID number and an array of five CollegeCourse objects. Create a get and set method for the Student ID number. Also create a get method that returns one of the Student’s CollegeCourses; the method takes an integer...

  • A. Create a CollegeCourse class. The class contains fields for the course ID (for example, CIS...

    A. Create a CollegeCourse class. The class contains fields for the course ID (for example, CIS 210), credit hours (for example, 3), and a letter grade (for example, A). Include get and set methods for each field. Create a Student class containing an ID number and an array of five CollegeCourse objects. Create a get and set method for the Student ID number. Also create a get method that returns one of the Student’s CollegeCourses; the method takes an integer...

  • Below, you can find the description of your labwork for today. You can also find the...

    Below, you can find the description of your labwork for today. You can also find the expected output of this code in the Application Walkthrough section. You are going to improve your existing Money & Stock Trading Platform on previous week’s labwork by incorporating Collections. In previous labworks, you have used arrays for holding Customer and Item objects. For this labwork you need to use ArrayList for holding these objects. So, rather than defining Customer[] array, you need to define...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT