Question: After creating the alumni class the next step should be to create an object of the alumni class in a tester/client class to make sure
After creating the alumni class the next step should be to create an object of the alumni class in a tester/client class to make sure that the object can be created and displayed. Then create an arraylist with 20-25 instances of the alumni class. College and collegeArraylist. THis is done in JGrasp: This is the examples of what I'm supposed to do. The first part is the CollegeArray.Java and the second part is the Collge.Java. The below is what she gave us an example, so my question is do I need to add to what she gave us.
Provide a list of alumni - name, address with city, state, zip, email, graduation year, degree, major, job title, company, industry
//This file is an example of how to create an arraylist of the college class
import java.util.ArrayList; import java.util.Scanner;
public class CollegeArrayList { public static void main (String [] args) { //declare variables String cName; int tuition; int num; int age; Scanner input = new Scanner (System.in); //declare an arraylist of colleges ArrayList colleges = new ArrayList (); //input number of colleges System.out.println("Please enter the number of colleges "); num=input.nextInt(); input.nextLine(); for (int index =0; index { System.out.println("Please enter the name of the college"); cName=input.nextLine(); System.out.println("Please enter the tuition"); tuition=input.nextInt(); input.nextLine(); colleges.add(new College(cName,tuition)); } for (College c : colleges) System.out.println(c.toString()); int total=0; int avg; //determine average tuition for (int index =0; index { total+=colleges.get(index).getCost(); } //System.out.println("total: " + total); avg=total/colleges.size(); System.out.println("average: " + avg); //find colleges with tuition less than the average for (int index =0; index { if(colleges.get(index).getCost() System.out.println("index: " + index + colleges.get(index).toString()); } } }
------------------------------------
public class College { //instance variables private String name; private double cost; public College (String n, double c){ name=n; cost=c; } //accessor public double getCost (){ return cost; } //mutator public String toString() { String s=" " + name + " has a tuition cost of " + cost; return s; } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
