1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
lidiya [134]
3 years ago
7

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.java--------------------------------------------------------------------------------

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
*/
}
}
Computers and Technology
1 answer:
Ostrovityanka [42]3 years ago
8 0

Answer:

Hi, I'm going to put the code answer here and you put in the corresponding line to not copy all the code in the answer.

replace the following line or adjust to the following code

/*

* CODE HERE

while(personSelect <= 0 || personSelect  > 5) {

System.out.println("Wrong number, try to input the number in range 1 to 5" );

personSelect = scan.nextInt();

}

if(personSelect == 1){

person1.setGpa(newGPA);

printInfo()

}

else if(personSelect == 2){

person2.setGpa(newGPA);

printInfo()

}

else if(personSelect == 3){

person3.setGpa(newGPA);

printInfo()

}

else if(personSelect == 4){

person4.setGpa(newGPA);

printInfo()

}

else {

person5.setGpa(newGPA);

printInfo()

}

*/

Explanation:

According to the description of code, we have to add some lines to resolve the questions.

a):

In base on the input, we have to modify the <em>attribute GPA</em> with the method <em>setGpa</em> depending on the person chosing. We call the person chosen before and also call the method setGpa( ) and pass  as <em>parameter</em> the GPA value obtained in tha last input

b)

In this case we have to <em>create a loop</em> for iterate the times that is necesary to get a value of person that is permit in <em>range 1 to 5</em>, and hence that we create and individual if condition to assign the GPA to the person chosen.

I hope it's help you.

You might be interested in
An online game is played with two dice. In this context, explain what is meant by decomposition.
Vlad [161]

Answer:

The answer to this question is given below in the explanation section.

Explanation:

This question is about desinging a game that is played with two dice and gets or shows their value to the player.

The dice value is random, and it can be between one and six. So, you need to generate two numbers between 1 and 6. You may also need to display the numbers

The main part of this program is that you need to know the numbers to limit or restrict what the user may do next while playing.

That's most of the first level of decomposition for solving a problem. In decomposition, you need to keep decomposing (breaking) the problem into smaller pieces, thinking outline of the program and deciding what objects, functions, variables, and logic you're going to implement in the coding.

4 0
3 years ago
Match each vocabulary word to its definition.
viktelen [127]

Answer:

can you show the picture??

5 0
3 years ago
Technicans A says the engine camshaft converts reciprocating motion of the piston into rotary montion for power output. Technici
garri49 [273]

It doesn't say what Technician B thinks, but I can tell you what the camshaft does and then you can decide who is right on your own. The camshaft is little metal rounded triangles above the piston that times when the intake and exhaust valve open and close.

Technician A is very wrong, the camshaft doesn't do that.

6 0
3 years ago
In Word, a red wavy underline indicates a/an
insens350 [35]
It's B. grammar errors are blue and autocorrect suggestions produce a small dialog box. I'm unsure what D is, but it's not an underline.
6 0
2 years ago
Which strategy would most likely improve a student's reading comprehension?
Fynjy0 [20]

Answer:

I think asking questions is the best.

Explanation:

I believe asking questions are the best because you get to understand the text which is really good. Some 7th grade reading teachers can help you a lot and you can use iLit to help a bunch.

8 0
3 years ago
Read 2 more answers
Other questions:
  • A four year old laptop will not boot and presents error messages on the screen
    8·1 answer
  • The computer stores a program while the program is running, as well as the data thatthe program is working with, in _____.
    10·1 answer
  • Given that String[] str has been initialized, to get a copy of str[0] with all characters converted to upper case, use the follo
    5·1 answer
  • A user complains that his computer automatically reboots after a short period of time. Which of the following computer component
    13·1 answer
  • Participants in open _________ community projects get experience and make connections with other professionals that can be valua
    6·1 answer
  • One of the most common uses of spreadsheet are
    12·1 answer
  • Why should we be careful about opening email attachments?
    8·2 answers
  • A _____ network is where all computers are equal and each one is both data requester and data provider.
    13·1 answer
  • Declare an ArrayList of Strings. Add eight names to the collection. Output the Strings onto the console using the enhanced for l
    9·1 answer
  • Northern Trail Outfitters uses a custom object Invoice to collect customer payment information from an external billing system.
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!