Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

using Java language. this is my coding for class Person and class Customer: 1) import java.util.Scanner; public class Person { private String name = none;

using Java language. this is my coding for class Person and class Customer:

1)

import java.util.Scanner; public class Person { private String name = "none"; private int id = 0;

public Person() { } public static void person(String[] args) { Person p = new Person(); } public Person(String name, int id) { this.name = name; this.id = id; }

public String getName() { return name; } public int getID() { return id; } // setters here public void setName(String newName) { this.name = newName; } public void setId (int newId) { this.id = newId; } public String toString() { return("name: " + name + ", id: " + id); } }

2)

import java.util.Scanner; public class Customer extends Person { private int cID = 0; public Customer() { super(); } public Customer(String name, int id, int cID){ super(name, id); this.cID = cID; } public int getID() { return cID; } @Override public String toString(){ return(super.toString() +", Customer ID: " + cID); } }

NOTE (These are additional notes I got from my teacher):

1. All LE1-LE5 codes must be done with inputs from the terminal to the Test driver (with the main method) class and not using the BlueJ object bench.

2. Input can be read using Scanner class.

I HAVE DONE FOR QUESTION 1 AND 2.

#1.

Write a test class called Test1 which will do the following which will read data from the terminal

a. Create a Person object called p with a given name and id from input

b. Create a Customer object called cust with a given name, id and customer id from input

c. print both objects

import java.util.Scanner; public class Test1 { public static void main(String[]args){ Scanner sc = new Scanner(System.in); String name =sc.nextLine(); int id= sc.nextInt(); int custID = sc.nextInt(); Person p = new Person(name, id); Customer cust = new Customer(name, id, custID); System.out.println("NAME: " + name +", ID:" + id +",Customer ID:"+ custID); } }

#2.

Write a test class called Test2 which will do the following which will read data from the terminal

a. Create a Person object called p with a given name and id from input

b. Assign that Person object p to a Customer object cust.

c. print both objects

import java.util.Scanner; public class Test2 { public static void main(String[]args){ Scanner sc = new Scanner(System.in); String name =sc.nextLine(); int id= sc.nextInt(); int custID = sc.nextInt(); Person p = new Customer(name, id,custID); System.out.println("NAME: " + name +", ID:" + id +",Customer ID:"+ custID); } }

MY QUESTIONS ARE:

#3.

Write a test class called Test3 which will do the following which will read data from the terminal

a. Create a Customer object called cust with a given name, id and customer id from input

b. Assign that Customer object cust to a Person object p.

c. update the ID of that Person object.

d. print that ID

e. update the customer ID of that Person object.

f. print that customer ID

g. print both objects

#4.

A. Add a char attribute called gender to the Person class and add / modify relevant methods in this class.

B. Add a Boolean attribute called member to the Customer class. Then add / modify relevant methods in this class.

C. Write a test class called Test4 which will do the following and will read data from the terminal

a. Create and read 3 Person objects

b. Create and read 3 Customer objects

c. update the IDs of the Person objects.

d. Tally and print all male persons.

e. Tally and print all member customers

#5.

This question code is based on the updated versions of Person and Customer classes in question #4.

Write a test class called Test5 which will do the following and will read data from the terminal

a. Read n - the data size

b. Create an array of n Customer objects called cust.

c. Read n Customer objects into the array cust.

d. update a few customer IDs of these objects.

e. Tally and print all male customers.

f. Tally and print all member customers

g. Tally and print all female member customers

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

Object Oriented Databases Prentice Hall International Series In Computer Science

Authors: John G. Hughes

1st Edition

0136298745, 978-0136298748

Students also viewed these Databases questions