|
|
define a class name student.In clude the following members(at least these,possibly others):
Data members(all must be in PRIVATE)
name(string)
GPA(double)
rank(char)-possible values are
'f' (freshman), 's' (sophomore),'j' (junior),'r'(senior)
NOTE: Values for the 1st 3 data members for each student object are read in from the command line.
Method Members
a get and set methods (each one public) for each data member
eg:public void setName(String sName)
eg: public String getName()
public string toStanding(char x)-this method takes a char argument(eg.,'f' 's' 'j' or 'r') and returns the String corresponding to the char as follows:
if the arg is 'f' return the string "freshman"
so on
if the arg is anything else, return the string "unknown"
Define a public class names HW3 .In clude the following memebers(at least these,possibly others):
method members:
public static void main(String[] args)
first print out (using System.out.println) the following haeding: "STUDENT REPORT by Bhargavi Gedala"
then this method should create 2 instances of class Student to create 2 Sudent objects,using the built-in no-arg Student constructor.
It should read command-line arguments and use the 1st 2 command line args to set the values of name, GPA, and rank for the 1st student object, and use the next 3 command line args to set the values of name,GPA and rank for the second student object.
Then for each student object,print out the name, GPA and standing(eg "freshman) with at least one blank between the outputted values.to print the standing,you should include a call to method toStanding(-),passing in the rank and having the standing returned.there must be at least 2 blank lines between the haeding and this student information.
eg: if the stu1 is a reference to the first Student object, you might have a statement like this in the main:
System.out.println(stu1.getName()+" " +stu1.getGPA() + " "+ stu1.getStanding(stu1.getRank());
finally, in the main, print ou the GPA of the 2 student objects.
sample run of the app from DOS
>java HW3 Sally 3.58 f Bill 2.99 r
note that there r 3 command line args for each student created.If there r less than 6 command line args,print a message saying "Must have at least 6 args". if there r more than 6 command line args,simply ignore the unused args.
ive tried this but its not working...
import java.util.Scanner;
public class Hw3
{
public static void main(String[] args)
{
String name1, name2;
double gpa1, gpa2;
String rank1, rank2;
int a=0;
System.out.println("student report by Bhargavi Gedala");
Scanner input=new Scanner(System.in);
while(input.hasNext())
{
a++;
if(a<6)
{
System.out.println("must have 6 arguments");
}
name1=input.nextLine();
gpa1=input.nextDouble();
rank1=input.nextLine();
name2=input.nextLine();
gpa2=input.nextDouble();
rank2=input.nextLine();
Student stu1=new Student();
System.out.println(stu1.getName()+stu1.getGpa()+stu1.getRank()+stu1.getReturn());
}
}
public class Student
{
private String name;
private double gpa;
private char rank;
private char result;
public void setName(String sName)
{
name=sName;
}
public String getName()
{
return name;
}
public void setGpa(double sGpa)
{
gpa=sGpa;
}
public double getGpa()
{
return gpa;
}
public void setRank(char sRank)
{
rank=sRank;
}
public char getRank()
{
return rank;
}
result=toStanding(char x);
public String toStanding(char x)
{
String y;
if(x=='f')
{
y="freshman";
return y;
}
if(x=='s')
{
y="sophomore";
return y;
}
if(x=='j')
{
y="junior";
return y;
}
if(x=='r')
{
y="senior";
return y;
}
else
{
y="unknown";
return y;
}
}