WRITE A PROGRAM IN JAVA
Write program which accepts five students id,name,age,department,courses, taken and its grade.
a. calculate its GPA
. display all student information in ascending order
View Answers
February 9, 2012 at 5:36 PM
import java.util.*;
class Student{
int id;
String name;
int age;
String department;
String course;
String grade;
double gpa;
Student(int id, String name,int age,String department,String course,String grade,double gpa){
this.id=id;
this.name=name;
this.age=age;
this.department=department;
this.course=course;
this.grade=grade;
this.gpa=gpa;
}
public int getId(){
return id;
}
public String getName(){
return name;
}
public int getAge(){
return age;
}
public String getDepartment(){
return department;
}
public String getCourse(){
return course;
}
public String getGrade(){
return grade;
}
public double getGpa(){
return gpa;
}
}
public class CalculateGPA{
public static void main(String[] args){
Scanner input=new Scanner(System.in);
ArrayList<Student> list=new ArrayList<Student>();
double gpa=0;
for(int i=0;i<5;i++){
System.out.print("Enter id: ");
int id=input.nextInt();
System.out.print("Enter Name: ");
String name=input.next();
System.out.print("Enter Age: ");
int age=input.nextInt();
System.out.print("Enter Department: ");
String department=input.next();
System.out.print("Enter course: ");
String course=input.next();
System.out.print("Enter grade: ");
String grade=input.next();
if(grade.equals("A")||grade.equals("a")){
gpa=4;
}
else if(grade.equals("B")||grade.equals("b")){
gpa=3;
}
else if(grade.equals("C")||grade.equals("c")){
gpa=2;
}
else if(grade.equals("D")||grade.equals("d")){
gpa=1;
}
else if(grade.equals("F")||grade.equals("f")){
gpa=0;
}
list.add(new Student(id,name,age,department,course,grade,gpa));
}
for(Student s: list){
System.out.println(s.getId()+"\t"+s.getName()+"\t"+s.getAge()+"\t"+s.getDepartment()+"\t"+s.getCourse()+"\t"+s.getGpa());
}
}
}
Ads
Related Tutorials/Questions & Answers:
Advertisements
Write a java application program........?
Write a
java application
program........? Welcome every One :
I have
Q in
Java?
Q :
Write a
java application
program that reads 20 integer numbers input by the user and prints how many numbers > 100 and how many numbers
Write a program in java...
Write a
program in
java... Hi, friends
Please, can you help me?
Q1:
Write a
program in
java to simulate a calculator. Your
program should take two... to enter an integer number.
Write a
program in
java to find the factorial
WRITE A PROGRAM IN JAVA
WRITE A
PROGRAM IN JAVA
Write program which accepts five students id,name,age,department,courses, taken and its grade.
a. calculate its GPA
. display all student information in ascending order
WRITE A PROGRAM IN JAVA
WRITE A
PROGRAM IN JAVA How do I
write a
program in
Java, have the
program display a message with your name in it and a number (Hello john Smith!1) The number must increment from zero to nine, or decrement fron nine to zero. You
write a program in java.
write a
program in
java. arrange the natural n umber in 5x5 matrix as
21 22 23 24 25
20 7 8 9 10
19 6 1 2 11
18 5 4 3 12
17 16 15 14 13
i at centerd position and remaining arrange in anticlockwise direction.
 
write a program
write a program
write a
program add 2 no.s without use arithmetic,unary operaters in
java
Help me to write this simple java frame program
Help me to
write this simple
java frame
program I want to
write a
Java program for....
To create a frame with 4 text fields;name,street,city and pin;with suitable labels.
Also add a button "OK". After enter values
how do i write a java program for this??
how do i
write a
java program for this?? â??Ask the user if they have a dog. If â??yesâ??, ask the user how old is and compute the dogâ??s age... in your
program
how to write this program
how to
write this program
Write a
program in
java which calculates... or numerical grade. You will be submitting TWO versions of this
program.
Write one...?˘s GPA. This
program should take a student�s First Name, Last Name a GPA
write a program to print
write a
program to print
write a
program to print following
1 2 3 4 5 4 3 2 1
1 2 3 4 4 3 2 1
1 2 3 3 2 1
1 2 2 1
1 1