Question

In: Computer Science

For this exercise, you are going to write your code in the FormFill class instead of...

For this exercise, you are going to write your code in the FormFill class instead of the main method. The code is the same as if you were writing in the main method, but now you will be helping to write the class. It has a few instance variables that stores personal information that you often need to fill in various forms, such as online shopping forms.

Read the method comments for more information.

As you implement these methods, notice that you have to store the result of concatenating multiple Strings or Strings and other primitive types. Concatenation produces a new String object and does not change any of the Strings being concatenated.

Pay close attention to where spaces should go in theString, too.


FormFillTester has already been filled out with some test code. Feel free to change the parameters to print your own information. If you don’t live in an apartment, just pass an empty String for the apartment number in setAddress.
Don’t put your real credit card information in your program!

When you run the program as written, it should output

Dog, Karel
123 Cherry Lane
Apt 4B
Card Number: 123456789
Expires: 10/2025

public class FormFill
{
  
private String fName;
private String lName;
private int streetNumber;
private String streetName;
private String aptNumber;
  
// Constructor that sets the first and last name
// streetNumber defaults to 0
// the others default to an empty String
public FormFill(String firstName, String lastName)
{
  
}
  
// Sets streetNumber, streetName, and aptNumber to the given
// values
public void setAddress(int number, String street, String apt)
{
  
}
  
// Returns a string with the name formatted like
// a doctor would write the name on a file
//
// Return string should be formatted
// with the last name, then a comma and space, then the first name.
// For example: LastName, FirstName
public String fullName()
{
  
}
  
// Returns the formatted address
// Formatted like this
//
// StreetNumber StreetName
// Apt AptNumber
//
// You will need to use the escape character \n
// To create a new line in the String
public String streetAddress()
{
  
}
  
// Returns a string with the credit card information
// Formatted like this:
//
// Card Number: Card#
// Expires: expMonth/expYear
//
// Take information as parameters so we don't store sensitive information!
// You will need to use the escape character \n
public String creditCardInfo(int creditCardNumber, int expMonth, int expYear)
{
  
}
  
}

public class FormFillTester
{
public static void main(String[] args)
{
FormFill filler = new FormFill("Karel", "Dog");
filler.setAddress(123, "Cherry Lane", "4B");
  
System.out.println(filler.fullName());
System.out.println(filler.streetAddress());
  
System.out.println(filler.creditCardInfo(123456789, 10, 2025));
  
}
}

Solutions

Expert Solution

class FormFill
{
  
private String fName;
private String lName;
private int streetNumber;
private String streetName;
private String aptNumber;


// Constructor that sets the first and last name
// streetNumber defaults to 0
// the others default to an empty String

public FormFill(String firstName, String lastName)
{
fName = firstName;
lName = lastName;
streetNumber = 0;
streetName = "";
aptNumber = "";
}


  
// Sets streetNumber, streetName, and aptNumber to the given
// values

public void setAddress(int number, String street, String apt)
{
streetNumber = number;
streetName = street;
aptNumber = apt;
}
  


// Returns a string with the name formatted like
// a doctor would write the name on a file
//
// Return string should be formatted
// with the last name, then a comma and space, then the first name.
// For example: LastName, FirstName

public String fullName()
{
return(lName+", "+fName);
}


  
// Returns the formatted address
// Formatted like this
//
// StreetNumber StreetName
// Apt AptNumber
//
// You will need to use the escape character \n
// To create a new line in the String

public String streetAddress()
{
return(streetNumber+" "+streetName+"\n"+aptNumber);
}


  
// Returns a string with the credit card information
// Formatted like this:
//
// Card Number: Card#
// Expires: expMonth/expYear
//
// Take information as parameters so we don't store sensitive information!
// You will need to use the escape character \n

public String creditCardInfo(int creditCardNumber, int expMonth, int expYear)
{
return("Card number: "+creditCardNumber+"\nExpires: "+expMonth+"/"+expYear);
}
  
}

Output on running FormFillTester:

NOTE: I've kept the original comments for ease of use.

In case of any doubt, drop a coment and I'll surely get back to you.

Please give a like if you're satisfied with the answer. Thank you.


Related Solutions

Exercise 2: Try-Catch Exercise Write a Java code that does the following: Create a class MyClass...
Exercise 2: Try-Catch Exercise Write a Java code that does the following: Create a class MyClass and create three methods myMethod1(), Method2() and Method3(). Invoke Method2() from Method1() and Method3() from Method2(). Write a code that can throw an exception inside myMethod3() and compile: File file=new File("filename.txt"); Scanner sc=new Scanner(file); You will get compilation errors now, as you are not handling a checked exception FileNotFoundException. Declare throws over myMethod3() and myMethod2(). You will need to add throws FileNotFoundException on myMethod()...
Using the class Date that you defined in Exercise O3, write the definition of the class...
Using the class Date that you defined in Exercise O3, write the definition of the class named Employee with the following private instance variables: first name               -           class string last name                -           class string ID number             -           integer (the default ID number is 999999) birth day                -           class Date date hired               -           class Date base pay                 -           double precision (the default base pay is $0.00) The default constructor initializes the first name to “john”, the last name to “Doe”, and...
Note- can you rewrite the code in C++. Circle Class c++ code Write a circle class...
Note- can you rewrite the code in C++. Circle Class c++ code Write a circle class that has the following member variables: • radius: a double • pi: a double initialized with the value 3.14159 The class should have the following member functions: • Default Constructor. A default constructor that sets radius to 0.0. • Constructor. Accepts the radius of the circle as an argument . • setRadius. A mutator function for the radius variable. • getRadius. An acccssor function...
Code in C++ please You are going to write a program for Computer test which will...
Code in C++ please You are going to write a program for Computer test which will read 10 multiple choice questions from a file, order them randomly and provide the test to the user. When the user done the program must give the user his final score
C++ How to make this code take a class object instead of int for the vector...
C++ How to make this code take a class object instead of int for the vector queue and be able to enqueue and dequeue the object? #include <iostream> #include <float.h> #include <bits/stdc++.h> using namespace std; void print_queue(queue<int> Q) //This function is used to print queue { while (!Q.empty()) { cout<< Q.front() << " "; Q.pop(); } } int main() { int n = 10; vector< queue<int> > array_queues(n); //Create vector of queues of size 10, each entry has a queue...
public class Sum2 { // TODO - write your code below this comment. } Download the...
public class Sum2 { // TODO - write your code below this comment. } Download the Sum2.java file, and open it in jGrasp (or a text editor of your choice). This program takes two values as command-line arguments, converts them to ints via Integer.parseInt, and adds them together. Example output of this program is shown below, with the command-line arguments 3 4: Sum: 7
public class FirstChar { // TODO - write your code below this comment. } Download the...
public class FirstChar { // TODO - write your code below this comment. } Download the FirstChar.java file, and open it in jGrasp (or a text editor of your choice). This program takes a single command-line argument and prints out the first character of this argument, using String's charAt() method. If you're unsure how to pass command-line arguments to a program with jGrasp, see this tutorial. Example output of this program with the command-line argument foo is shown below: First...
In this exercise you will return to your SpecialityCoffee class which you created for the last...
In this exercise you will return to your SpecialityCoffee class which you created for the last coding activity (a sample solution to this exercise will be shown below the entire question if you do not have yours). This time you will override the Coffee method getPrice which returns the price in cents for a given coffee. The SpecialityCoffee method getPrice should return the price given by the Coffee method for that object, plus an extra charge for the flavored syrup....
CODE IN C++ PLEASE Write a program to implement the algorithm that you designed in Exercise...
CODE IN C++ PLEASE Write a program to implement the algorithm that you designed in Exercise 19 of Chapter 1. Your program should allow the user to buy as many items as the user desires. Instructions for Exercise 19 of Chapter 1 have been posted below for your convenience. Exercise 19 Jason typically uses the Internet to buy various items. If the total cost of the items ordered, at one time, is $200 or more, then the shipping and handling...
Write a c++ code: 2.2.1 Vehicle Class The vehicle class is the parent class of a...
Write a c++ code: 2.2.1 Vehicle Class The vehicle class is the parent class of a derived class: locomotive. Their inheritance will be public inheritance so react that appropriately in their .h les. The description of the vehicle class is given in the simple UML diagram below: vehicle -map: char** -name: string -size:int -------------------------- +vehicle() +setName(s:string):void +getName():string +getMap():char** +getSize():int +setMap(s: string):void +getMapAt(x:int, y:int):char +vehicle() +operator--():void +determineRouteStatistics()=0:void The class variables are as follows: map: A 2D array of chars, it will...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT