Question: Program 1: Create the following two files: PersonalInfo (no main) and PersonalInfoDemo.java (with main). Create a Java class called PersonalInfo that represents a person with

Program 1:

Create the following two files: PersonalInfo (no main) and PersonalInfoDemo.java (with main).

Create a Java class called PersonalInfo that represents a person with the following private properties:

String first;

String last;

String ssNumber;

int age;

The class should have the following four constructors:

Note: Use the following default values: first=, last=, ssNumber=N/A, age=0.

A no-arg constructor that sets all properties to default values.

A constructor that takes in a first name and a last name. Set the other two to default values.

A constructor that takes in a first name a last name, and age. Set the ssNumber to the default value.

A constructor that takes in all properties as arguments and sets them accordingly.

The class should also have at least getters for all the properties.

Create a program called PersonalInfoDemo that has the following parameters:

String first;

String last;

int age=0;

String ssNumber="";

PersonalInfo person=new PersonalInfo();

int legal=0;

The programs does the following:

Asks the following:

If it illegal to ask for age or social security number enter 1, if it legal to ask for age but not or social security number enter 2, if it legal to ask for age and social security number enter 3:

(Call this parameter legal).

If they entered 1, 2, or 3:

Ask for the persons first name and last name.

If they entered 2 or 3:

Ask for the persons age

If they entered 3:

Ask for the persons social security number

Note: To avoid switching from reading in numbers to Strings use keyboard.next() to read in the Strings and everything should be fine.

Define your instance of the PersonalInfo class as follows:

if (legal==1)

person = new PersonalInfo(first, last);

if (legal==2)

person = new PersonalInfo(first, last, age);

if (legal==3)

person = new PersonalInfo(first, last, age,ssNumber);

Print out the persons first and last name, their age, and their social security number.

Examples:

If it legal to ask for age but not or social security number enter 2.

If it legal to ask for age and social security number enter 3: 1

Enter First Name: John Smith

Enter Last Name:

Personal Information:

Name: John Smith

Age: 0

SSN: N/A

If it illegal to ask for age or social security number enter 1.

If it legal to ask for age but not or social security number enter 2.

If it legal to ask for age and social security number enter 3: 2

Enter First Name: John

Enter Last Name: Smith

Enter Age: 25

Personal Information:

Name: John Smith

Age: 25

SSN: N/A

If it illegal to ask for age or social security number enter 1.

If it legal to ask for age but not or social security number enter 2.

If it legal to ask for age and social security number enter 3: 3

Enter First Name: John

Enter Last Name: Smith

Enter Age: 25

Enter SSN: 123-45-6789

Personal Information:

Name: John Smith

Age: 25

SSN: 123-45-6789

Program 2:

Create four pages:

Three Classes: Course1, Schedule, Transcript.

A program JaneDoeTranscript which supplies course information and prints out the total number of credits Jane has earned so far:

Pass in all four .java files.

Create a class called "Course1" with the following private properties:

String dept;

String name;

int credits;

Create a constructor that accepts and sets a courses department, name, and number of credits.

Create getters for these three variables.

Create a class called "Schedule" with the following private properties:

int semester;

String studentName;

Course1[] courses=new Course1[10];

int index=0;

Create a constructor that accepts and sets the semester (an integer), and students name.

Create getters for semester, the studentName, and courses.

Create a method called "addCourse" that accepts a Course1 object and adds it to the array of courses. (Hint, include index++ to increment the value of index.)

In the Course class, create a method called "getSemesterCredits" as follows:

public int getSemesterCredits() {

int totalCredits = 0;

for (Course1 course : courses) {

if (course != null) {

totalCredits += course.getCredits();

}

}

return totalCredits;

}

Create a class called "Transcript" with the following private properties:

String name;

Schedule[] schedules=new Schedule[12];

int index=0;

Create a constructor that accepts a (students) name.

Create getters for the name and schedules variables.

Create a method called "addSchedule" that accepts a semester object and adds it to the array of schedules. (Hint, include index++ to increment the value of index++.)

In the Transcript class, create a method called "getTotalCredits" as follows:

public int getTotalCredits() {

int totalCredits = 0;

for (Schedule schedule : schedules) {

if (schedule!= null) {

totalCredits += schedule. schedule.getSemesterCredits();

}

}

return totalCredits;

}

Create a program JaneDoeTranscipt as given below:

import java.util.Scanner;

public class JaneDoeTranscript {

public static void main(String[] args) {

String name="Jane Doe";

int semester=0;

//Semester 1

semester++;

Course1 math = new Course1("Math", "Calculus I", 4);

Course1 eng = new Course1("English", "Composition I", 3);

Course1 cs = new Course1("Computer Science", "Programming I", 4);

Schedule schedule1 = new Schedule(semester, name);

schedule1.addCourse(math);

schedule1.addCourse(eng);

schedule1.addCourse(cs);

//Semester 2

semester++;

Course1 math2 = new Course1("Math", "Calculus II", 4);

Course1 psy = new Course1("Psychology", "Intro to Psychology", 3);

Course1 cs2 = new Course1("Computer Science", "Programming II", 3);

Schedule schedule2 = new Schedule(semester, name);

schedule2.addCourse(math2);

schedule2.addCourse(psy);

schedule2.addCourse(cs2);

Transcript transcript = new Transcript(name);

transcript.addSchedule(schedule1);

transcript.addSchedule(schedule2);

System.out.println("Student Name: " + transcript.getname());

System.out.println("Total credits: " + transcript.getTotalCredits());

}

}

Example

Student Name: Jane Doe

Total credits: 21

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!