Create a Java Program to complete the following: Note: Follow the requirements b
ID: 3827848 • Letter: C
Question
Create a Java Program to complete the following:
Note: Follow the requirements below to complete the project.
You have to complete this home work before you come to next class as you need this for next class Lab
Your application should find GPA of of a student.
1.Create StudentDetail.java class. Do not need to include main method while creating this class
Create variables following variables in this class
studentName, studentId , scoreMath,scoreScience,scoreHistory,scoreEnglish,stuTotal , stuAverage,stuGPA
Add getters and setters for these variables
2.Create Student class. Include main method while creating this class
3.Create StudentHelper class. Do not need to include main method while creating this class.
This class should have calculateGPA() method.
This method should be able to receive StudentDetail object and return StudentDetail object
4.From Student class's main method, using JOptionPane, ask user to enter Student's name, Students's Id, scores in 4 subjects one by one and save them all in StudentDetail object (using the set methods)
Create an object for StudentHelper class.
Using this object, call calculateGPA() method of StudentHelper an send StudentDetail object.
5.In calculateGPA(), get the scores of 4 subjects one by one from StudentDetail object,calculate total ,average and GPA, save them in the StudentDetail object.
6.In main method of Student class, after receiving StudentDetail object from calculateGPA() method, using JOptionPane, display, student name,id and GPA using this StudentDetail object.
Also do the following:
1.With example, explain the difference between reference and primitive variable.
2.________________ operator is used to create a class object
3.In a Java project, ClassA has methodA() .
Write the 2 lines of Java code that you would need in ClassB to create an object for ClassA to access its method methodA()
4. Write about any 2 methods that belong to String class
5. What does the following code do?
String str = "12345";
int n = Integer.ParseInt(str);
6.The class JOptionPane is contained in the package -------------------
7. The class Scanner is contained in the package -----------------------
8 In Java , we can have else statement without if (True/false)
9. When will the following expression be true
!(x>0)
10. What is the output of the following code
if(5<=5)
System.out.print("true");
else
System.out.print("false");
Explanation / Answer
[1] (a) primitive and reference type is that primitive type always has a value, it can never be null. reference type can be null, which denotes the absence of value.
(b) Primitive variables contains fundamental values, like int, float, boolean etc. reference type contains/refers the handle of the Object that has been created using the "new <ObjectName()>" syntex
Example :
primitive variable,
int i=10;
object reference variable
ClassA object = new ClassA();
[2] new() Operator used to create object of an class
[3] ClassB {
ClassA ob = new ClassA();
ob.methodA();
}
[4] string length() method returns length of the string.
string charAt() method returns a character at specified index
[5] This returns an integer .
But Error in this : int n = Integer.parseInt(str);
PaserInt --> parseInt
[6] javax.swing.JOptionPane
[7] java.util.Scanner
[8] False
[9] When x<=0
[10]True