Assignment 4 Java
You are required, but not limited, to turn in the following source files:
Assignment4.java
Club.java
President.java
New Skills to be Applied
In addition to what has been covered in previous assignments, the use of the following items, discussed in class, will probably be needed:
Classes
Instance Objects
Accessors/Mutators(Modifiers) methods
Visibility Modifiers (Access specifier) - public, private,
etc.
Encapsulation concept
Aggregation relationship between classes
Program Description
The following is the description of Assignment4 class.
The driver program will allow the user to interact with your other class modules. The purpose of this module is to handle all user input and screen output. The main method should start by displaying the following menu in this exact format:
Choice\t\tAction\n
------\t\t------\n
A\t\tAdd Club\n
D\t\tDisplay
Club\n
Q\t\tQuit\n
?\t\tDisplay
Help\n\n
Next, the following prompt should be displayed:
What action would you like to perform?\n
Read in the user input and execute the appropriate command. After the execution of each command, re-display the prompt. Commands should be accepted in both lowercase and uppercase.
Add Club
Your program should display the following prompt:
Please enter the Club
information::\n
Enter its name:\n
Read in the user input and set the club name on the club object. Then it will ask a user to enter its number of members, its university, its president's first name, last name, and academic level.
Read in the user input and set them on the club object.
Note that there is only one Club object in this assignment. Thus when "Add Club" option is selected more than once, the new one overwrites the old Club object information.
Display Club
Your program should display the club information in the following format:
\nClub
Name:\t\tSwimming
Club\n
Number Of Members:\t87\n
University:\t\tArizona State
University\n
President:\t\tWater,Bob(Senior)\n\n
Make use of the toString method of the Club class to display
this information. The toString method is used together with
System.out.print method.
(System.out should NOT to be used within the toString method.)
Quit
Your program should stop executing and output nothing.
Display Help
Your program should redisplay the "choice action" menu.
Invalid Command
If an invalid command is entered, display the following line:
Unknown action\n
President Class
The President class describes information of a president of a club. It has following attributes:
| Attribute Name | Attribute Type | Description |
| firstName | String | first name of the president |
| lastName | String | last name of the president |
| academicLevel | String | academic level of the president, such as senior, junior, etc. |
The following constructor should be provided to initialize each
attribute. This constructor initializes the value of string
attributes to "?".
public President( )
The following accessor methods should be provided to get the
attributes:
public String getFirstName()
public String getLastName()
public String getAcademicLevel()
The following modifier(mutator) methods should be provided to
set the attributes:
public void setFirstName(String someFirstName)
public void setLastName(String someLastName)
public void setAcademicLevel(String someLevel)
The following method must be defined:
public String toString()
toString method should return a string of the following
format:
Water,Bob(Senior)
where "Water" is the last name of a president, "Bob" is the first
name, and "Senior" is the academic level. So you need to insert ","
or parentheses between these variables.
Note that you can choose a meaningful parameter variable name for
each method.
Club Class
The Club class describes a club. It has the following attributes
| Attribute Name | Attribute Type | Description |
| clubName | String | name of the Club |
| numberOfMembers | int | Number of members of the Club |
| university | String | university of the Club |
| currentPresident | President | current president of the Club |
The following constructor should be provided to initialize each
attribute. This constructor initializes the value of string
attributes to "?" and the value of integer attribute to 0,
and an object of President using the constructor of the President
class.
public Club( )
The following accessor methods should be provided to get the
attributes:
public String getClubName()
public int getNumberOfMembers()
public String getUniversity()
public President getCurrentPresident()
The following modifier(mutator) methods should be provided to
change the attributes:
public void setClubName(String someName)
public void setNumberOfMembers(int someNumber)
public void setUniversity(String someUniversity)
public void setCurrentPresident(String firstName, String lastName,
String someLevel)
The following method must be defined:
public String toString()
The toString() method constructs a string of the following format:
\nClub
Name:\t\tSwimming
Club\n
Number Of Members:\t87\n
University:\t\tArizona State
University\n
President:\t\tWater,Bob(Senior)\n\n
Assignment4.java
import java.util.*;
public class Assignment4
{
public static void main (String[] args)
{
// local variables, can be accessed anywhere from the main method
char input1 = 'Z';
String inputInfo;
String clubName, university, firstName, lastName, academicLevel,
numOfMembersStr;
int numOfMembers;
String line = new String();
// instantiate a Club object
Club club1 = new Club();
printMenu();
//Create a Scanner object to read user input
Scanner scan = new Scanner(System.in);
do // will ask for user input
{
System.out.println("What action would you like to perform?");
line = scan.nextLine();
if (line.length() == 1)
{
input1 = line.charAt(0);
input1 = Character.toUpperCase(input1);
// matches one of the case statement
switch (input1)
{
case 'A': //Add Club
System.out.print("Please enter the Club information:\n");
System.out.print("Enter its name:\n");
clubName = scan.nextLine();
club1.setClubName(clubName);
System.out.print("Enter its number of members:\n");
numOfMembersStr = scan.nextLine();
numOfMembers = Integer.parseInt(numOfMembersStr);
club1.setNumberOfMembers(numOfMembers);
System.out.print("Enter its university:\n");
university = scan.nextLine();
club1.setUniversity(university);
System.out.print("Enter its president's first name:\n");
firstName = scan.nextLine();
System.out.print("Enter its president's last name:\n");
lastName = scan.nextLine();
System.out.print("Enter its president's academic level:\
n");
academicLevel = scan.nextLine();
club1.setCurrentPresident(firstName, lastName,
academicLevel);
break;
case 'D': //Display Club
System.out.print(club1);
break;
case 'Q': //Quit
break;
case '?': //Display Menu
printMenu();
break;
default:
System.out.print("Unknown action\n");
break;
}
}
else
{
System.out.print("Unknown action\n");
}
} while (input1 != 'Q' || line.length() != 1);
}
/** The method printMenu displays the menu to a user **/
public static void printMenu()
{
System.out.print("Choice\t\tAction\n" +
"------\t\t------\n" +
"A\t\tAdd Club\n" +
"D\t\tDisplay Club\n" +
"Q\t\tQuit\n" +
"?\t\tDisplay Help\n\n");
}
}
Test Cases
Use the following test cases to ensure that your program works for all of them:
Input #1:
A
Swimming Club
87
Arizona State University
Bob
Water
Senior
D
A
Hiking Club
43
University of Arizona
Meg
Walker
Graduate
D
Q
Output #1:
Choice Action
------ ------
A Add Club
D Display Club
Q Quit
? Display Help
What action would you like to perform?
Please enter the Club information:
Enter its name:
Enter its number of members:
Enter its university:
Enter its president's first name:
Enter its president's last name:
Enter its president's academic level:
What action would you like to perform?
Club Name: Swimming Club
Number Of Members: 87
University: Arizona State University
President: Water,Bob(Senior)
What action would you like to perform?
Please enter the Club information:
Enter its name:
Enter its number of members:
Enter its university:
Enter its president's first name:
Enter its president's last name:
Enter its president's academic level:
What action would you like to perform?
Club Name: Hiking Club
Number Of Members: 43
University: University of Arizona
President: Walker,Meg(Graduate)
What action would you like to perform?
Input #2:
A
Singing Club
41
Arizona State University
Sophie
Music
Junior
D
?
Q
Output #2:
Choice Action
------ ------
A Add Club
D Display Club
Q Quit
? Display Help
What action would you like to perform?
Please enter the Club information:
Enter its name:
Enter its number of members:
Enter its university:
Enter its president's first name:
Enter its president's last name:
Enter its president's academic level:
What action would you like to perform?
Club Name: Singing Club
Number Of Members: 41
University: Arizona State University
President: Music,Sophie(Junior)
What action would you like to perform?
Choice Action
------ ------
A Add Club
D Display Club
Q Quit
? Display Help
What action would you like to perform?
The Java code is given below:
********************************* Assignment4.java
******************************************
import java.util.*;
import java.lang.NullPointerException;
public class Assignment4
{
/* Main method */
public static void main (String[] args) throws NullPointerException
{
char input1 = 'Z';
String inputInfo;
String clubName, university, firstName, lastName, academicLevel,numOfMembersStr;
int numOfMembers;
String line = "";
/* intantiate object of Club class */
Club club1 = new Club();
printMenu();
Scanner scan = new Scanner(System.in);
do
{
System.out.println("What action would you like to perform?");
line = scan.nextLine();
if (line.length() == 1)
{
input1 = line.charAt(0);
input1 = Character.toUpperCase(input1);
switch (input1)
{
case 'A': //Add Club
System.out.print("Please enter the Club information:\n");
System.out.print("Enter its name:\n");
clubName = scan.nextLine();
club1.setClubName(clubName);
System.out.print("Enter its number of members:\n");
numOfMembersStr = scan.nextLine();
numOfMembers = Integer.parseInt(numOfMembersStr);
club1.setNumberOfMembers(numOfMembers);
System.out.print("Enter its university:\n");
university = scan.nextLine();
club1.setUniversity(university);
System.out.print("Enter its president's first name:\n");
firstName = scan.nextLine();
System.out.print("Enter its president's last name:\n");
lastName = scan.nextLine();
System.out.print("Enter its president's academic level:\n");
academicLevel = scan.nextLine();
club1.setCurrentPresident(firstName, lastName, academicLevel);
break;
case 'D': //Display Club
System.out.print(club1);
break;
case 'Q': //Quit
break;
case '?': //Display Menu
printMenu();
break;
default:
System.out.print("Unknown action\n");
break;
}
}
else
{
System.out.print("Unknown action\n");
}
} while (input1 != 'Q' || line.length() != 1);
}
/** The method printMenu displays the menu to a user **/
public static void printMenu()
{
System.out.print("Choice\t\tAction\n" +
"------\t\t------\n" +
"A\t\tAdd Club\n" +
"D\t\tDisplay Club\n" +
"Q\t\tQuit\n" +
"?\t\tDisplay Help\n\n");
}
}
******************************** President.java ***********************************************
public class President {
/* Data members of the class */
private String firstName;
private String lastName;
private String academicLevel;
/* Getter function of firstName */
public String getFirstName() {
return firstName;
}
/* Setter function for firstName */
public void setFirstName(String firstName) {
this.firstName = firstName;
}
/* Getter function for lastName */
public String getLastName() {
return lastName;
}
/* Setter function for lastName */
public void setLastName(String lastName) {
this.lastName = lastName;
}
/* Getter function for academicLevel */
public String getAcademicLevel() {
return academicLevel;
}
/* Setter function for academicLevel */
public void setAcademicLevel(String academicLevel) {
this.academicLevel = academicLevel;
}
/* toString method to concat the data members to one string */
public String toString() {
return this.getLastName() + "," + this.getFirstName()
+ "(" + this.getAcademicLevel() + ")";
}
}
********************************* Club.java ************************************************
public class Club {
/* Data members of the class */
private String clubName;
private int numberOfMembers;
private String university;
private President currentPresident;
/* Getter function of clubName */
public String getClubName() {
return clubName;
}
/* Setter function of clubName */
public void setClubName(String clubName) {
this.clubName = clubName;
}
/* Getter function of numberOfMembers */
public int getNumberOfMembers() {
return numberOfMembers;
}
/* Setter function of numberOfMembers */
public void setNumberOfMembers(int numberOfMembers) {
this.numberOfMembers = numberOfMembers;
}
/* Getter function of university */
public String getUniversity() {
return university;
}
/* Setter function of university */
public void setUniversity(String university) {
this.university = university;
}
/* Getter function of currentPresident */
public President getCurrentPresident() {
return currentPresident;
}
/* Setter function of currentPresident */
public void setCurrentPresident(String firstName, String lastName, String academicLevel) {
this.currentPresident = new President();
currentPresident.setFirstName(firstName);
currentPresident.setLastName(lastName);
currentPresident.setAcademicLevel(academicLevel);
}
/* toString method to concat the data members to one string */
public String toString() {
return "\nClub Name:\t\t" + getClubName() +
"\nNumber Of Members:\t" + getNumberOfMembers() +
"\nUniversity:\t\t" + getUniversity() +
"\nPresident:\t\t" + getCurrentPresident() + "\n\n";
}
}
Sample Input and Output:

Screenshot of the codes is given
below:
********************************* Assignment4.java
******************************************


******************************** President.java
***********************************************
********************************* Club.java
************************************************

If the answer helped please upvote, it means a lot and for any query please comment.
Assignment 4 Java You are required, but not limited, to turn in the following source files:...
You will write a single java program called MadLibs. java. This file will hold and allow access to the values needed to handle the details for a "MadLibs" game. This class will not contain a maino method. It will not ask the user for any input, nor will it display (via System.out.print/In()) information to the user. The job of this class is to manage information, not to interact with the user.I am providing a MadLibsDriver.java e^{*} program that you can...
in JAVA -- need to use an arraystack for this and can only
manipulate smartstring.java aka the one that says :
public class SmartString implements SmartStringADT at the
beginning
//for SmartStringTest.java:
import static org.junit.Assert.*;
import org.junit.Test;
public class SmartStringTest {
//Test insert method
@Test
public void testinsert1() {
SmartString evaluator = new
SmartString();
evaluator.insert(0, "Hello");
evaluator.insert(4, ", how are
you?");
assertEquals("Hello, how are you?",
evaluator.toString());
}
...
Java need help with searching for a contact Question:Write a program that uses an ArrayList of parameter type Contact to store a database of contacts. The Contact class should store the contact’s first and last name, phone number, and email address. Add appropriate accessor and mutator methods. Your database program should present a menu that allows the user to add a contact, display all contacts, search for a specific contact and display it, or search for a specific contact and...
Deliverable
A zipped NetBeans project with 2 classes
app
ZipCode
Address
Classes
Suggestion:
Use Netbeans to copy your last lab (Lab 03) to a new
project called Lab04.
Close Lab03.
Work on the new Lab04 project then.
The Address Class
Attributes
int number
String name
String type
ZipCode zip
String state
Constructors
one constructor with no input parameters
since it doesn't receive any input values, you need to use the
default values below:
number - 0
name - "N/A"
type...
JAVA help Create a class Individual, which has: Instance variables for name and phone number of individual. Add required constructors, accessor, mutator, toString() , and equals method. Use array to implement a simple phone book , by making an array of objects that stores the name and corresponding phone number. The program should allow searching in phone book for a record based on name, and displaying the record if the record is found. An appropriate message should be displayed if...
This is the question:
These are in Java format.
Comments are required on these two Classes (Student.java
and StudentDemo.java) all over the coding:
Provide proper comments all over the
codings.
---------------------------------------------------------------------------------------------------------------
import java.io.*;
import java.util.*;
class Student {
private String name;
private double gradePointAverage;
public Student(String n , double a){
name = n;
gradePointAverage = a;
}
public String getName(){
return name;
}
public double getGradePointAverage(){
return gradePointAverage;
}
...
Code in JAVA
UML
//TEST HARNESS
//DO NOT CHANGE CODE FOR TEST HARNESS
import java.util.Scanner; // Scanner class to support user input
public class TestPetHierarchy
{
/*
* All the 'work' of the process takes place in the main method. This is actually poor design/structure,
* but we will use this (very simple) form to begin the semester...
*/
public static void main( String[] args )
{
/*
* Variables required for processing
*/
Scanner input = new Scanner( System.in...
Files given in this assignment (right-click on the file to download) Assignment7.cpp (need to complete) Student.h (Given. Just use it, don't change it!) Student.cpp (Partially filled, need to complete) 1. Assignment description In this assignment, you will write a simple class roster management system for ASU CSE100. Step #1: First, you will need to finish the design of class Student. See the following UML diagram for Student class, the relevant header file (class declaration) is given to you as Student.h,...
Use inheritance to create a new class AudioRecording based on Recording class that: it will retain all the members of the Recording class, it will have an additional field bitrate (non-integer numerical; it cannot be modified once set), its constructors (non-parametrized and parametrized) will set all the attributes / fields of this class (reuse code by utilizing superclass / parent class constructors): Non-parametrized constructor should set bitrate to zero, If arguments for the parametrized constructor are illegal or null, it...
Java Homework Problems: 4. • Examine AddImport.java. – Perform the following: – Replace the fully qualified name to access the Jlabel component with an import statement. – To import classes from the util package, replace multiple import statements with a single import statement. /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ import java.util.Calendar; import java.util.Date; public...