Question

departmentstore: package departmentstorepkg; import java.util.ArrayList; public class DepartmentStore {    private static final int DEFAULT_SIZE =...

departmentstore:

package departmentstorepkg;

import java.util.ArrayList;

public class DepartmentStore {

  

private static final int DEFAULT_SIZE = 10;

private StaffMember [] myEmployees;

private int myNumberEmployees;

private String myFileName;

private StaffMember[] employee;

public DepartmentStore (String filename){

myFileName = filename;

myEmployees = employee;

  

}

public String toString(){

return this.getClass().toString() + ": " + myFileName;

}

public void addEmployee(Employee emp){

}

/**

* prints out all the employees in the array list held in this class

*/

public void print(){

for(int i = 0; i<myNumberEmployees;i++){

System.out.println(this.myEmployees[i]);

System.out.println("");

}

}

/**

*

* prints only instances of Employee objects

*

*/

public void printEmployees(){

//instanceof (think of it as an operator) comparing what kind of obj you are

//finish the work on your own!!

for (int i = 0; i < myNumberEmployees; i ++){

StaffMember sm = myEmployees[i];

if(sm instanceof Hourly ){

}

else if (sm instanceof Executive){

}

else{

System.out.println(sm.toString());

}

}

}

/**

* prints only instances of Executive objects

*

*/

public void printExecutives(){

//instanceof (think of it as an operator) comparing what kind of obj you are

//finish the work on your own!!

for(int i = 0; i< myNumberEmployees;i++){

StaffMember sm = myEmployees[i];

if(sm instanceof Executive ){

System.out.println(sm.toString());

}

}

}

/**

*

* prints only instances of Hourly objects

*/

public void printHourly(){

//instanceof (think of it as an operator) comparing what kind of obj you are

//finish the work on your own!!

for (int i = 0; i < myNumberEmployees; i ++){

StaffMember sm = myEmployees[i];

if(sm instanceof Hourly){

System.out.println(sm.toString());

}

}

}

public Employee findEmployee(String ssn){

for (int i = 0; i < myNumberEmployees; i ++){

StaffMember sm = (Employee)myEmployees[i];

if(sm.getSocialSecurityNumber().equals(ssn)){

return (Employee) sm ;

}

}

return null;

}

public void removeEmployee(String ssn){

for(int i = 0; i< myNumberEmployees;i++){

Employee sm = (Employee) myEmployees[i];

if(sm.socialSecurityNumber.compareTo(ssn) == 0){

}

}

}

public void removeEmployee(Employee emp){

for(int i = 0; i< myNumberEmployees;i++){

Employee sm = (Employee) myEmployees[i];

if(sm.compareTo(emp) == 0){

  

}

}

}

public boolean updateHours(String ssn, int hours){

boolean r = false;

if(findEmployee(ssn) instanceof Hourly)

{

((Hourly)findEmployee(ssn) ).addHours(hours);

r = true;

}

if (r){

return true;

}

else{

return false;

}

}

}

departmenstoretest:

package departmentstorepkg;

public class DepartmentStoreTest {

public static void main(String[] args) {

// StaffMemberIO empIn = new StaffMemberIO ("./employees.txt");

// StaffMember sm = empIn.getNext();

// while (sm!=null) {

//

// System.out.println(sm);

//

// if(sm instanceof Executive)

// {

// System.out.println(" Executive");

// System.out.println(sm);

// }

// else if(sm instanceof Hourly)

// {

// System.out.println(" Hourly");

// System.out.println(sm);

// }

// else if(sm instanceof Employee)

// {

// System.out.println(" Employee");

// System.out.println(sm);

// }

// System.out.println();

// sm = empIn.getNext();

//

// }

{

System.out.println();

DepartmentStore store = new DepartmentStore("Allied Service Department Store");

System.out.println();

StaffMemberIO empIn = new StaffMemberIO ("employees.txt");

//while another employee to read

while(empIn.hasNext()){

store.addEmployee(empIn.next());

}

System.out.println("My store: " + store.toString());

System.out.println("Here are the people in the store: ");

System.out.println("Testing print method in department store class");

store.print();

System.out.println();

System.out.println("Testing printEmployees method in departmentStore class");

store.printEmployees();

System.out.println();

System.out.println("Testing printExecutives method in departmentStore class");

store.printExecutives();

System.out.println();

System.out.println("Testing printHourly method in departmentStore class");

store.printHourly();

System.out.println();

System.out.println("Testing findEmployee method in departmentStore class");

System.out.println(store.findEmployee("222-22-2222"));

System.out.println(store.findEmployee("123-45-6789"));

System.out.println();

System.out.println("Testing removeEmployee method in departmentStore class");

System.out.println("using both removeEmployee(String ssn) and removeEmployee(Employee emp)");

Employee temp1 = store.findEmployee("123-45-6789");

store.removeEmployee("123-45-6789");

System.out.println(store.findEmployee("123-45-6789"));

// using removeEmployee(Employee emp)

Employee temp2 = store.findEmployee("323-23-5666");

store.removeEmployee(store.findEmployee("323-23-5666"));

System.out.println(store.findEmployee("323-23-5666"));

System.out.println("adding employees back in");

store.addEmployee(temp1);

store.addEmployee(temp2);

System.out.println(store.findEmployee("123-45-6789"));

System.out.println(store.findEmployee("323-23-5666"));

System.out.println();

System.out.println("Testing return output for updateHours method in departmentStore class");

System.out.println(store.updateHours("212-33-6978", 0));

System.out.println(store.updateHours("222-22-2222", 20));

System.out.println();

System.out.println("Testing hourly hours update for updateHours method in departmentStore class");

System.out.println(store.updateHours("212-33-6978", 20));

System.out.println(store.updateHours("658-45-9234", 40));

store.printHourly();

System.out.println();

System.out.println("Testing awardBonus method in Executive class");

((Executive)store.findEmployee("123-45-6789")).awardBonus(1000.50);

((Executive)store.findEmployee("623-34-2399")).awardBonus(1240.50);

((Executive)store.findEmployee("345-67-8934")).awardBonus(1220.50);

store.printExecutives();

}

}

}

employee:

package departmentstorepkg;

public class DepartmentStoreTest {

public static void main(String[] args) {

// StaffMemberIO empIn = new StaffMemberIO ("./employees.txt");

// StaffMember sm = empIn.getNext();

// while (sm!=null) {

//

// System.out.println(sm);

//

// if(sm instanceof Executive)

// {

// System.out.println(" Executive");

// System.out.println(sm);

// }

// else if(sm instanceof Hourly)

// {

// System.out.println(" Hourly");

// System.out.println(sm);

// }

// else if(sm instanceof Employee)

// {

// System.out.println(" Employee");

// System.out.println(sm);

// }

// System.out.println();

// sm = empIn.getNext();

//

// }

{

System.out.println();

DepartmentStore store = new DepartmentStore("Allied Service Department Store");

System.out.println();

StaffMemberIO empIn = new StaffMemberIO ("employees.txt");

//while another employee to read

while(empIn.hasNext()){

store.addEmployee(empIn.next());

}

System.out.println("My store: " + store.toString());

System.out.println("Here are the people in the store: ");

System.out.println("Testing print method in department store class");

store.print();

System.out.println();

System.out.println("Testing printEmployees method in departmentStore class");

store.printEmployees();

System.out.println();

System.out.println("Testing printExecutives method in departmentStore class");

store.printExecutives();

System.out.println();

System.out.println("Testing printHourly method in departmentStore class");

store.printHourly();

System.out.println();

System.out.println("Testing findEmployee method in departmentStore class");

System.out.println(store.findEmployee("222-22-2222"));

System.out.println(store.findEmployee("123-45-6789"));

System.out.println();

System.out.println("Testing removeEmployee method in departmentStore class");

System.out.println("using both removeEmployee(String ssn) and removeEmployee(Employee emp)");

Employee temp1 = store.findEmployee("123-45-6789");

store.removeEmployee("123-45-6789");

System.out.println(store.findEmployee("123-45-6789"));

// using removeEmployee(Employee emp)

Employee temp2 = store.findEmployee("323-23-5666");

store.removeEmployee(store.findEmployee("323-23-5666"));

System.out.println(store.findEmployee("323-23-5666"));

System.out.println("adding employees back in");

store.addEmployee(temp1);

store.addEmployee(temp2);

System.out.println(store.findEmployee("123-45-6789"));

System.out.println(store.findEmployee("323-23-5666"));

System.out.println();

System.out.println("Testing return output for updateHours method in departmentStore class");

System.out.println(store.updateHours("212-33-6978", 0));

System.out.println(store.updateHours("222-22-2222", 20));

System.out.println();

System.out.println("Testing hourly hours update for updateHours method in departmentStore class");

System.out.println(store.updateHours("212-33-6978", 20));

System.out.println(store.updateHours("658-45-9234", 40));

store.printHourly();

System.out.println();

System.out.println("Testing awardBonus method in Executive class");

((Executive)store.findEmployee("123-45-6789")).awardBonus(1000.50);

((Executive)store.findEmployee("623-34-2399")).awardBonus(1240.50);

((Executive)store.findEmployee("345-67-8934")).awardBonus(1220.50);

store.printExecutives();

}

}

}

executive:

package departmentstorepkg;
//********************************************************************
// Executive.java Author: Lewis and Loftus
//
// Represents an executive staff member, who can earn a bonus.
//********************************************************************

class Executive extends Employee{
private double bonus;

// Sets up an executive with the specified information.
public Executive(String name, String address, String phone,
String socialSecurityNumber, double payRate) {
super(name, address, phone, socialSecurityNumber, payRate);
bonus = 0; // bonus has yet to be awarded
}

// Awards the specified bonus to this executive.
public void awardBonus(double execBonus) {
bonus = execBonus;
}

// Computes and returns the pay for an executive, which is the
// regular employee payment plus a one-time bonus.
public double pay() {
double payment = super.pay() + bonus;
bonus = 0;
return payment;
}

public String toString() {
String result = super.toString();
result += "\nBonus: " + bonus;
return result;
}
}

staffmember:

package departmentstorepkg;

//********************************************************************

// StaffMember.java Author: Lewis and Loftus

//

// Represents a generic staff member.

//********************************************************************

abstract class StaffMember

{

/**

* staff member name

*/

protected String name;

/**

* staff member address

*/

protected String address;

/**

* staff member telephone number

*/

protected String phone;

/**

* initializes a newly-created StaffMember object

*/

public StaffMember(String name, String address, String phone) {

this.name = name;

this.address = address;

this.phone = phone;

}

/**

* returns a String representation of this object

*/

public String toString() {

String result = getClass().getName()+ "\nName: " + name + "\n";

result += "Address: " + address + "\n";

result += "Phone: " + phone;

return result;

}

/**

* abstract method representing the rate of pay for this staff member

*/

public abstract double pay();

public Object getSocialSecurityNumber() {

// TODO Auto-generated method stub

return null;

}

}

hourly:

package departmentstorepkg;

//********************************************************************

// Hourly.java Author: Lewis and Loftus

//

// Represents an employee that gets paid by the hour.

//********************************************************************

class Hourly extends Employee

{

private int hoursWorked;

// Sets up this hourly employee using the specified information.

public Hourly(String name, String address, String phone,

String socialSecurityNumber, double payRate) {

super(name, address, phone, socialSecurityNumber, payRate);

hoursWorked = 0;

}

// Adds the specified number of hours to this employee's

// accumulated hours.

public void addHours(int moreHours) {

hoursWorked += moreHours;

}

// Computes and returns the pay for this hourly employee.

public double pay() {

double payment = payRate * hoursWorked;

hoursWorked = 0;

return payment;

}

// Returns information about this hourly employee as a string.

public String toString() {

String result = super.toString();

result += "\nCurrent hours: " + hoursWorked;

return result;

}

}

staffmemberIO:

package departmentstorepkg;

import java.io.*;

import java.util.*;

public class StaffMemberIO

{

private String fileName;

private BufferedReader infile;

private Employee nextOne;

public StaffMemberIO(String filename) {

fileName = filename;

openFile();

nextOne = getNext();

}

/**

* returns true if there is another employee to be read from the file

*/

public boolean hasNext() {

return nextOne != null;

}

/**

* returns an Employee (or one of its subclasses) constructed from the

* information about the next employee in the file

*/

public Employee next() {

if (nextOne == null)

throw new NoSuchElementException("No more staff members");

Employee temp = nextOne;

nextOne = getNext();

return temp;

}

/**

* returns a String representation of EmployeeIO

*/

public String toString() {

return "[" + fileName + "]";

}

Employee getNext() {

if (infile == null)

return null;

try {

String typeString = infile.readLine().trim();

char type = typeString.charAt(0);

String name = infile.readLine().trim();

String address = infile.readLine();

String phone = infile.readLine().trim();

String socialSecurity = infile.readLine().trim();

double pay = Double.valueOf(infile.readLine().trim()).doubleValue();

switch (type) {

case 'e':

case 'E':

return new Employee(name, address, phone, socialSecurity, pay);

case 'x':

case 'X':

return new Executive(name, address, phone, socialSecurity, pay);

case 'h':

case 'H':

return new Hourly(name, address, phone, socialSecurity, pay);

}

} catch (Exception e) { }

closeFile();

return null;

}

private void closeFile() {

if (infile == null)

return;

try {

infile.close();

} catch (IOException e) {}

}

private void openFile() {

infile = null;

try {

FileReader fr = new FileReader(fileName);

infile = new BufferedReader(fr);

} catch (IOException e) {System.err.println("Didn't open " + fileName);

}

}

}

I'm trying to run it but it's not working main is departmentstore,, JUST UPDATES IT AND INCLUDED ALL THE CLASSES!!

0 0
Add a comment Improve this question Transcribed image text
Answer #1

I have remove the errors in your code :

DepartmentStore.java

import java.util.ArrayList;

public class DepartmentStore {

  

private static final int DEFAULT_SIZE = 10;

private StaffMember[] myEmployees;

private int myNumberEmployees;

private String myFileName;

private StaffMember[] employee;

public DepartmentStore (String filename){

myFileName = filename;

myEmployees = employee;

  

}

public String toString(){

return this.getClass().toString() + ": " + myFileName;

}

public void addEmployee(Employee emp){

}

/**

* prints out all the employees in the array list held in this class

*/

public void print(){

for(int i = 0; i<myNumberEmployees;i++){

System.out.println(this.myEmployees[i]);

System.out.println("");

}

}

/**

*

* prints only instances of Employee objects

*

*/

public void printEmployees(){

//instanceof (think of it as an operator) comparing what kind of obj you are

//finish the work on your own!!

for (int i = 0; i < myNumberEmployees; i ++){

StaffMember sm = myEmployees[i];

if(sm instanceof Hourly ){

}

else if (sm instanceof Executive){

}

else{

System.out.println(sm.toString());

}

}

}

/**

* prints only instances of Executive objects

*

*/

public void printExecutives(){

//instanceof (think of it as an operator) comparing what kind of obj you are

//finish the work on your own!!

for(int i = 0; i< myNumberEmployees;i++){

StaffMember sm = myEmployees[i];

if(sm instanceof Executive ){

System.out.println(sm.toString());

}

}

}

/**

*

* prints only instances of Hourly objects

*/

public void printHourly(){

//instanceof (think of it as an operator) comparing what kind of obj you are

//finish the work on your own!!

for (int i = 0; i < myNumberEmployees; i ++){

StaffMember sm = myEmployees[i];

if(sm instanceof Hourly){

System.out.println(sm.toString());

}

}

}

public Employee findEmployee(String ssn){

for (int i = 0; i < myNumberEmployees; i ++){

Employee sm = (Employee)myEmployees[i];

if(sm.getSocialSecurityNumber().equals(ssn)){

return sm ;

}

}

return null;

}

public void removeEmployee(String ssn){

for(int i = 0; i< myNumberEmployees;i++){

Employee sm = (Employee) myEmployees[i];

if(sm.getSocialSecurityNumber().equals(ssn)){

}

}

}

public void removeEmployee(Employee emp){

for(int i = 0; i< myNumberEmployees;i++){

Employee sm = (Employee) myEmployees[i];

if(sm.equals(emp)){

  

}

}

}

public boolean updateHours(String ssn, int hours){

boolean r = false;

if(findEmployee(ssn) instanceof Hourly)

{

((Hourly)findEmployee(ssn) ).addHours(hours);

r = true;

}

if (r){

return true;

}

else{

return false;

}

}

}

DepartmentStoreTest.java

public class DepartmentStoreTest {

public static void main(String[] args) {

System.out.println();

DepartmentStore store = new DepartmentStore("Allied Service Department Store");

System.out.println();

StaffMemberIO empIn = new StaffMemberIO("employees.txt");
StaffMember sm = empIn.getNext();

//while another employee to read

while (sm!=null) {

//System.out.println(sm);

if(sm instanceof Executive)

{

System.out.println("Executive");

System.out.println(sm);

}

else if(sm instanceof Hourly)

{

System.out.println("Hourly");

System.out.println(sm);

}

else if(sm instanceof Employee)

{

System.out.println("Employee");

System.out.println(sm);

}   

System.out.println();   

sm = empIn.getNext();

}


System.out.println("My store: " + store.toString());

System.out.println("Here are the people in the store: ");

System.out.println("Testing print method in department store class");

store.print();

System.out.println();

System.out.println("Testing printEmployees method in departmentStore class");

store.printEmployees();

System.out.println();

System.out.println("Testing printExecutives method in departmentStore class");

store.printExecutives();

System.out.println();

System.out.println("Testing printHourly method in departmentStore class");

store.printHourly();

System.out.println();

System.out.println("Testing findEmployee method in departmentStore class");

System.out.println(store.findEmployee("222-22-2222"));

System.out.println(store.findEmployee("123-45-6789"));

System.out.println();

System.out.println("Testing removeEmployee method in departmentStore class");

System.out.println("using both removeEmployee(String ssn) and removeEmployee(Employee emp)");

Employee temp1 = store.findEmployee("123-45-6789");

store.removeEmployee("123-45-6789");

System.out.println(store.findEmployee("123-45-6789"));

// using removeEmployee(Employee emp)

Employee temp2 = store.findEmployee("323-23-5666");

store.removeEmployee(store.findEmployee("323-23-5666"));

System.out.println(store.findEmployee("323-23-5666"));

System.out.println("adding employees back in");

store.addEmployee(temp1);

store.addEmployee(temp2);

System.out.println(store.findEmployee("123-45-6789"));

System.out.println(store.findEmployee("323-23-5666"));

System.out.println();

System.out.println("Testing return output for updateHours method in departmentStore class");

System.out.println(store.updateHours("212-33-6978", 0));

System.out.println(store.updateHours("222-22-2222", 20));

System.out.println();

System.out.println("Testing hourly hours update for updateHours method in departmentStore class");

System.out.println(store.updateHours("212-33-6978", 20));

System.out.println(store.updateHours("658-45-9234", 40));

store.printHourly();

System.out.println();

System.out.println("Testing awardBonus method in Executive class");

((Executive)store.findEmployee("123-45-6789")).awardBonus(1000.50);

((Executive)store.findEmployee("623-34-2399")).awardBonus(1240.50);

((Executive)store.findEmployee("345-67-8934")).awardBonus(1220.50);

store.printExecutives();

}

}

StaffMemberIO.java

import java.io.*;

import java.util.*;

public class StaffMemberIO

{

private String myFileName;

private BufferedReader myInfile;

private Scanner scan;

public StaffMemberIO(String filename)

{

myFileName = filename;

openFile();

scan = new Scanner (myInfile);

}

public String toString( )

{

return "[" + myFileName + "]";

}

public StaffMember getNext()

{

if (scan == null)

return null;

try

{

String typeStr = scan.nextLine();

char type = typeStr.charAt(0);

String name = scan.nextLine();

String address = scan.nextLine();

String phone = scan.nextLine();

String socialSecurity = scan.nextLine();

double pay = scan.nextDouble();

scan.nextLine();

switch (type)

{

case 'e': case 'E':

return new Employee(name, address, phone, socialSecurity, pay);

case 'x': case 'X':

return new Executive(name, address, phone, socialSecurity, pay);

case 'h': case 'H':

return new Hourly(name, address, phone, socialSecurity, pay);

}

return null;

}

catch (Exception e){

closeFile( );

return null;

}

}

private void closeFile()

{

if (myInfile == null)

return;

try

{

myInfile.close();

}

catch (IOException e) { }

}

private void openFile()

{

myInfile = null;

try

{

FileReader fr = new FileReader(myFileName);

myInfile = new BufferedReader(fr);

}

catch (IOException e) {System.err.println("Didn't open " + myFileName);}

}

}

StaffMember.java

abstract class StaffMember

{

private String name;

private String address;

private String phone;

//-----------------------------------------------------------------

// Sets up a staff member using the specified information.

//-----------------------------------------------------------------

public StaffMember (String name, String address, String phone)

{

this.name = name;

this.address = address;

this.phone = phone;

}

//-----------------------------------------------------------------

// Returns a string including the basic employee information.

//-----------------------------------------------------------------

public String toString ()

{

String result = "Name: " + name + "\n";

result += "Address: " + address + "\n";

result += "Phone: " + phone;

return result;

}

//-----------------------------------------------------------------

// Derived classes must define the pay method for each employee

// type.

//-----------------------------------------------------------------

public abstract double pay();

// getters and setters (mutators) for the private data members of this abstract class

public String getName() {

return name;

}

public void setName(String name) {

this.name = name;

}

public String getAddress() {

return address;

}

public void setAddress(String address) {

this.address = address;

}

public String getPhone() {

return phone;

}

public void setPhone(String phone) {

this.phone = phone;

}

}

Employee.java

class Employee extends StaffMember

{

protected String socialSecurityNumber;

protected double payRate;

//-----------------------------------------------------------------

// Sets up an employee with the specified information.

//-----------------------------------------------------------------

public Employee (String name, String address, String phone,

String socialSecurityNumber, double payRate)

{

super (name, address, phone);

this.socialSecurityNumber = socialSecurityNumber;

this.payRate = payRate;

}

//-----------------------------------------------------------------

// Returns information about an employee as a string.

//-----------------------------------------------------------------

public String toString ()

{

String result = super.toString();

result += "\nSocial Security Number: " + socialSecurityNumber;

return result;

}

//-----------------------------------------------------------------

// Returns the pay rate for this employee.

//-----------------------------------------------------------------

public double pay ()

{

return payRate;

}

// getter and setter for local private data member

public String getSocialSecurityNumber() {

return socialSecurityNumber;

}

public void setSocialSecurityNumber(String socialSecurityNumber) {

this.socialSecurityNumber = socialSecurityNumber;

}

}

Hourly.java

class Hourly extends Employee

{

private int hoursWorked;

//-----------------------------------------------------------------

// Sets up this hourly employee using the specified information.

//-----------------------------------------------------------------

public Hourly (String name, String address, String phone,

String socialSecurityNumber, double payRate)

{

super (name, address, phone, socialSecurityNumber, payRate);

hoursWorked = 0;

}

//-----------------------------------------------------------------

// Adds the specified number of hours to this employee's

// accumulated hours.

//-----------------------------------------------------------------

public void addHours (int moreHours)

{

hoursWorked += moreHours;

}

//-----------------------------------------------------------------

// Computes and returns the pay for this hourly employee.

//-----------------------------------------------------------------

public double pay ()

{

double payment = payRate * hoursWorked;

hoursWorked = 0;

return payment;

}

//-----------------------------------------------------------------

// Returns information about this hourly employee as a string.

//-----------------------------------------------------------------

public String toString ()

{

String result = super.toString();

result += "\nCurrent hours: " + hoursWorked;

return result;

}

}

Executive.java

class Executive extends Employee

{

private double bonus;

//-----------------------------------------------------------------

// Sets up an executive with the specified information.

//-----------------------------------------------------------------

public Executive (String name, String address, String phone,

String socialSecurityNumber, double payRate)

{

super (name, address, phone, socialSecurityNumber, payRate);

bonus = 0; // bonus has yet to be awarded

}

//-----------------------------------------------------------------

// Awards the specified bonus to this executive.

//-----------------------------------------------------------------

public void awardBonus (double execBonus)

{

bonus = execBonus;

}

//-----------------------------------------------------------------

// Computes and returns the pay for an executive, which is the

// regular employee payment plus a one-time bonus.

//-----------------------------------------------------------------

public double pay ()

{

double payment = super.pay() + bonus;

bonus = 0;

return payment;

}

}

You have not provided employees.txt. You should provide the same for better result.

Add a comment
Know the answer?
Add Answer to:
departmentstore: package departmentstorepkg; import java.util.ArrayList; public class DepartmentStore {    private static final int DEFAULT_SIZE =...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • import java.util.Scanner; public class StudentClient {       public static void main(String[] args)    {   ...

    import java.util.Scanner; public class StudentClient {       public static void main(String[] args)    {        Student s1 = new Student();         Student s2 = new Student("Smith", "123-45-6789", 3.2);         Student s3 = new Student("Jones", "987-65-4321", 3.7);         System.out.println("The name of student #1 is ");         System.out.println("The social security number of student #1 is " + s1.toString());         System.out.println("Student #2 is " + s2);         System.out.println("the name of student #3 is " + s3.getName());         System.out.println("The social security number...

  • package cards; import java.util.ArrayList; import java.util.Scanner; public class GamePlay { static int counter = 0; private...

    package cards; import java.util.ArrayList; import java.util.Scanner; public class GamePlay { static int counter = 0; private static int cardNumber[] = {1,2,3,4,5,6,7,8,9,10,11,12,13}; private static char suitName[] = { 'c', 'd', 'h', 's' }; public static void main(String[] args) throws CardException, DeckException, HandException { Scanner kb = new Scanner(System.in); System.out.println("How many Players? "); int numHands = kb.nextInt(); int cards = 0; if (numHands > 0) { cards = 52 / numHands; System.out.println("Each player gets " + cards + " cards\n"); } else...

  • public class Test { private static int i =0; private static int j =0; public static...

    public class Test { private static int i =0; private static int j =0; public static void main(String[] args) { int i = 2; int k = 3; { int j =3; System.out.println("i + j is : " + i + j); } k = i + j; System.out.println("K is " + k ); System.out.println("K is " + j); } } why is the output i + j = 23 K =2 K =0 Please explain a step by step...

  • public class Animal {    private String name; //line 1    private int weight; //line 2...

    public class Animal {    private String name; //line 1    private int weight; //line 2    private String getName(){       return name;    } //line 3    public int fetchWeight(){       return weight; } //line 4 } public class Dog extends Animal {    private String food; //line 5    public void mystery(){       //System.out.println("Name = " + name); //line 6            System.out.println("Food = " + food); //line 7    } } I want to know the super...

  • import java.io.FileNotFoundException; import java.util.ArrayList; import java.util.Collections; import java.util.HashSet; public class FindWordInMaze { private char grid[][]; private...

    import java.io.FileNotFoundException; import java.util.ArrayList; import java.util.Collections; import java.util.HashSet; public class FindWordInMaze { private char grid[][]; private ArrayList<String> words; private HashSet<String> foundWords = new HashSet<String>(); public FindWordInMaze(char[][] grid) { this.grid = grid; this.words = new ArrayList<>();    // add dictionary words words.add("START"); words.add("NOTE"); words.add("SAND"); words.add("STONED");    Collections.sort(words); } public void findWords() { for(int i=0; i<grid.length; i++) { for(int j=0; j<grid[i].length; j++) { findWordsFromLocation(i, j); } }    for(String w: foundWords) { System.out.println(w); } } private boolean isValidIndex(int i, int j, boolean visited[][]) { return...

  • class Upper { private int i; private String name; public Upper(int i){ name = "Upper"; this.i...

    class Upper { private int i; private String name; public Upper(int i){ name = "Upper"; this.i = i;} public void set(Upper n){ i = n.show();} public int show(){return i;} } class Middle extends Upper { private int j; private String name; public Middle(int i){ super(i+1); name = "Middle"; this.j = i;} public void set(Upper n){ j = n.show();} public int show(){return j;} } class Lower extends Middle { private int i; private String name; public Lower(int i){ super(i+1); name =...

  • GIVEN CODES *****Boat.java***** import java.util.HashSet; import java.util.Set; public class Boat { private String name; //private instance...

    GIVEN CODES *****Boat.java***** import java.util.HashSet; import java.util.Set; public class Boat { private String name; //private instance variable name of type String private String boatClass; //private instance variable boatClass of type String private int regNum; //private instance variable regNum of type int private Set<String> crew = new HashSet<String>(); public void setName(String name) { this.name = name; } public void setBoastClass(String boatClass) { this.boatClass = boatClass; } public void setRegNum(int regNum) { this.regNum = regNum; } public String getName() { return name;...

  • Rewrite following code down below using Factory Pattern. -------------------------Staff.java--------------------------- import java.util.*; public class Staff extends Employee...

    Rewrite following code down below using Factory Pattern. -------------------------Staff.java--------------------------- import java.util.*; public class Staff extends Employee {    private int HourlyRate;    /**Constructor Staff which initiates the values*/    public Staff() {    super();    HourlyRate=0;    }    /**Overloaded constructor method    * @param ln last name    * @param fn first name    * @param ID Employee ID    * @param sex Sex    * @param hireDate Hired Date    * @param hourlyRate Hourly rate for the work...

  • Create a class called MazeSolver: public class MazeSolver {    private char[][] maze;    private int startx,                    &

    Create a class called MazeSolver: public class MazeSolver {    private char[][] maze;    private int startx,                     starty;   Public MazeSolver(String fileName) throws IOException   {      // create an object to read information from “fileName”      // read the maze dimension (row col) from the file      // Allocate the space for maze      // initialize array maze with contents of the file      // find startx and starty      printMaze(); // a method that prints the maze      // solveMaze() is a recursive method to solve the maze      if(solveMaze(maze,startx,starty))...

  • 4. Command pattern //class Stock public class Stock { private String name; private double price; public...

    4. Command pattern //class Stock public class Stock { private String name; private double price; public Product(String name, double price) { this.name = name; this.price = price; } public void buy(int quantity){ System.out.println(“BOUGHT: “ + quantity + “x “ + this); } public void sell(int quantity){ System.out.println(“SOLD: “ + quantity + “x “ + this); } public String toString() { return “Product [name=” + name + “, price=” + price + “]”; } } a. Create two command classes that...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT