Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Make sure it can be ran in Netbeans Program 1: Create the following two files: PersonalInfo (no main) and PersonalInfoDemo.java (with main). Create a Java

Make sure it can be ran in Netbeans

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 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: 1

Enter First Name: John

Enter Last Name: Smith

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: Acourse, 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 "Acourse" 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;

Acourse[] courses=new Acourse[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 an Acourse object and adds it to the array of courses. (Hint, include index++ to increment the value of index.)

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

public int getSemesterCredits() {

int totalCredits = 0;

for (Acourse 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.getSemesterCredits();

}

}

return totalCredits;

}

Create a program JaneDoeTranscipt as given below:

import java.util.Scanner;

public class JaneDoeTranscript {

import java.util.Scanner;

public class JaneDoeTranscript {

public static void main(String[] args) {

String name="Jane Doe";

int semester=0;

//Semester 1

semester++;

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

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

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

Schedule schedule1 = new Schedule(semester, name);

schedule1.addCourse(math);

schedule1.addCourse(eng);

schedule1.addCourse(cs);

//Semester 2

semester++;

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

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

Acourse cs2 = new Acourse("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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Microsoft Visual Basic 2008 Comprehensive Concepts And Techniques

Authors: Gary B. Shelly, Corinne Hoisington

1st Edition

1423927168, 978-1423927167

More Books

Students also viewed these Databases questions

Question

b. Does senior management trust the team?

Answered: 1 week ago

Question

c. How is trust demonstrated?

Answered: 1 week ago

Question

Have issues been prioritized?

Answered: 1 week ago