subject

You have the templates of 2 classes, person and program. the person class has 4 attributes, name, age, major and gpa. there is a constructor for the class that is used to make person objects. there are setter/mutator methods and getter/accessor methods for those attributes. there is also a printinfo() method that prints out information about the person. the program class has a main method that has 5 person objects person1 to person5 declared and initialized. the main method within the class also has a scanner object that is used to take input for a person number and a newgpa. your task is as follows:
a. based on the input of personselect select the appropriate person and change their gpa to the newgpa input and then print out their information. for instance if the user types in 1 then select person 1 and print out their information using the printinfo method. do it for all possible inputs from 1 to 5.
b. if however the input is not 1 to 5 then inform the user they have to have to type in an appropriate person number
person. java
public class person {
string name;
int age;
double gpa;
string major;
public person(string aname, int aage, string amajor, double agpa)
{
name = aname;
age = aage;
gpa = agpa;
major = amajor;
}
/**
* @return the name
*/
public string getname() {
return name;
}
/**
* @param name the name to set
*/
public void setname(string pname) {
name = pname;
}
/**
* @return the age
*/
public int getage() {
return age;
}
/**
* @param age the age to set
*/
public void setage(int page) {
age = page;
}
/**
* @return the gpa
*/
public double getgpa() {
return gpa;
}
/**
* @param gpa the gpa to set
*/
public void setgpa(double pgpa) {
gpa = pgpa;
}
/**
* @return the major
*/
public string getmajor() {
return major;
}
/**
* @param major the major to set
*/
public void setmajor(string pmajor) {
major = pmajor;
}
public void printinfo()
{
system. out. println("");
system. out. println("business college ");
system. out. println("name: " + name);
system. out. println("major: " + major);
system. out. println("gpa: " + gpa);
system. out. println("");
}
}
program.
import java. util. scanner;
public class program {
public static void main(string[] args) {
//declare person objects here
person person1 = new person("dewars",40 , "mis", 3.9);
person person2 = new person("budweiser",23 , "mis", 3.2);
person person3 = new person("appletons",25 , "mis", 3.0);
person person4 = new person("beam",20 , "finance", 3.7);
person person5 = new person("daniels",19 , "accounting", 2.9);
scanner scan = new scanner(system. in);
system. out. println("type in a person number whose gpa you would like to change > ");
int personselect = scan. nextint();
system. out. println("type in the gpa you would like the person's to be > ");
double newgpa = scan. nextdouble();
/*
* code here
*/
}
}

ansver
Answers: 1

Another question on Computers and Technology

question
Computers and Technology, 23.06.2019 18:30
This program should be a short piece of code that prints all of the positive integers from 1 to 100 as described more fully below. the program may contain multiple methods, and if using an oo language, should be contained within a single class or object. the program should be designed so that it begins execution when invoked through whichever mechanism is most common for the implementation language. â–ş print out all positive integers from 1 to 100, inclusive and in order. â–ş print messages to standard output, matching the sample output below. â–ş in the output, state whether the each integer is 'odd' or 'even' in the output. â–ş if the number is divisible by three, instead of stating that the number is odd or even, state that the number is 'divisible by three'. â–ş if the number is divisible by both two and three, instead of saying that the number is odd, even or divisible by three; state that the number is 'divisible by two and three'. â–ş design the logic of the loop to be as efficient as possible, using the minimal number of operations to perform the required logic. sample output the number '1' is odd. the number '2' is even. the number '3' is divisible by three. the number '6' is divisible by two and three.
Answers: 1
question
Computers and Technology, 24.06.2019 00:20
The guy wire bd exerts on the telephone pole ac a force p directed along bd. knowing the p must have a 720-n component perpendicular to the pole ac, determine the magnitude of force p and its component along line ac.
Answers: 2
question
Computers and Technology, 24.06.2019 13:00
Which one of the following functions is not available on the autosum tool? sum average if max
Answers: 3
question
Computers and Technology, 24.06.2019 13:30
Does anybody know how to hack into a google account? i had important information on it and it is gone now and i need getting it back.
Answers: 1
You know the right answer?
You have the templates of 2 classes, person and program. the person class has 4 attributes, name, ag...
Questions
question
History, 19.09.2019 05:30
question
Mathematics, 19.09.2019 05:30
Questions on the website: 13722367