Loading...

Messages

Proposals

Stuck in your homework and missing deadline? Get urgent help in $10/Page with 24 hours deadline

Get Urgent Writing Help In Your Essays, Assignments, Homeworks, Dissertation, Thesis Or Coursework & Achieve A+ Grades.

Privacy Guaranteed - 100% Plagiarism Free Writing - Free Turnitin Report - Professional And Experienced Writers - 24/7 Online Support

Band booster class java

06/01/2021 Client: saad24vbs Deadline: 3 days

IFT 102]


Introduction to Java Technologies


Lab 3: Objects & Classes


Score: 50 pts


I. Prelab Exercises


1. Constructors are special methods included in class definitions.


a. What is a constructor used for?


b. How do constructors differ from other methods in a class?


2. Both methods and variables in a class are declared as either private or public. Describe the difference between private and public and indicate how a programmer decides which parts of a class should be private and which public.


3. Consider a class that represents a bank account.


a. Such a class might store information about the account balance, the name of the account holder, and an account number. What instance variables would you declare to hold this information? Give a type and name for each.


b. There are a number of operations that would make sense for a bank account—withdraw money, deposit money, check the balance, and so on. Write a method header with return type, name, and parameter list, for each such operation described below. Don’t write the whole method—just the header. They will all be public methods. The first one is done for you as an example.


i. Withdraw a given amount from the account. This changes the account balance, but does not return a value.


public void withdraw(double amount)


ii. Deposit a given amount into the account. This changes the account balance, but does not return a value.


iii. Get the balance from the account. This does not change anything in the account; it simply returns the balance.


iv. Return a string containing the account information (name, account number, balance). This does not change anything in the account.


v. Charge a $ 10 fee. This changes the account balance but does not return a value.


vi. Create a new account given an initial balance, the name of the owner, and the account number. Note that this will be a constructor, and that a constructor does not have a return type.


II. A Bank Account Class


1. File Account.java contains a partial definition for a class representing a bank account. Save it to your directory and study it to see what methods it contains. Then complete the Account class as described below. Note that you won’t be able to test your methods until you write ManageAccounts in question #2.


a. Fill in the code for method toString, which should return a string containing the name, account number, and balance for the account.


b. Fill in the code for method chargeFee, which should deduct a service fee from the account.


c. Modify chargeFee so that instead of returning void, it returns the new balance. Note that you will have to make changes in two places.


d. Fill in the code for method changeName which takes a string as a parameter and changes the name on the account to be that string.


2. File ManageAccounts.java contains a shell program that uses the Account class above. Save it to your directory, and complete it as indicated by the comments.


3. Modify ManageAccounts so that it prints the balance after the calls to chargeFees. Instead of using the getBalance method like you did after the deposit and withdrawal, use the balance that is returned from the chargeFees method. You can either store it in a variable and then print the value of the variable, or embed the method call in a println statement.


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


// Account.java


//


// A bank account class with methods to deposit to, withdraw from,


// change the name on, charge a fee to, and print a summary of the account.


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


public class Account


{


private double balance;


private String name;


private long acctNum;


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


//Constructor -- initializes balance, owner, and account number


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


public Account(double initBal, String owner, long number)


{


balance = initBal;


name = owner;


acctNum = number;


}


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


// Checks to see if balance is sufficient for withdrawal.


// If so, decrements balance by amount; if not, prints message.


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


public void withdraw(double amount)


{


if (balance >= amount)


balance -= amount;


else


System.out.println("Insufficient funds");


}


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


// Adds deposit amount to balance.


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


public void deposit(double amount)


{


balance += amount;


}


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


// Returns balance.


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


public double getBalance()


{


return balance;


}


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


// Returns a string containing the name, account number, and balance.


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


public String toString()


{


}


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


// Deducts $10 service fee //


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


public void chargeFee()


{


}


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


// Changes the name on the account


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


public void changeName(String newName)


{


}


}


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


// ManageAccounts.java


//


// Use Account class to create and manage Sally and Joe's


// bank accounts


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


public class ManageAccounts


{


public static void main(String[] args)


{


Account acct1, acct2;


//create account1 for Sally with $1000


acct1 = new Account(1000, "Sally", 1111);


//create account2 for Joe with $500


//deposit $100 to Joe's account


//print Joe's new balance (use getBalance())


//withdraw $50 from Sally's account


//print Sally's new balance (use getBalance())


//charge fees to both accounts


//change the name on Joe's account to Joseph


//print summary for both accounts


}


}


III. Tracking Grades


A teacher wants a program to keep track of grades for students and decides to create a student class for his program as follows:


· Each student will be described by three pieces of data: his/her name, his/her score on test #1, and his/her score on test#2.


· There will be one constructor, which will have one argument—the name of the student.


· There will be three methods: getName, which will return the student’s name; inputGrades, which will prompt for and read in the student’s test grades; and getAverage, which will compute and return the student’s average.


1. File Student.java contains an incomplete definition for the Student class. Save it to your directory and complete the class definition as follows:


a. Declare the instance data (name, score for test1, and score for test2).


b. Create a Scanner object for reading in the scores.


c. Add the missing method headers.


d. Add the missing method bodies.


2. File Grades.java contains a shell program that declares two Student objects. Save it to your directory and use the inputGrades method to read in each student’s test scores, then use the getAverage method to find their average. Print the average with the student’s name, e.g., “The average for Joe is 87.” You can use the getName method to print the student’s name.


3. Add statements to your Grades program that print the values of your Student variables directly, e.g.:


System.out.println("Student 1: " + student1);


This should compile, but notice what it does when you run it—nothing very useful! When an object is printed, Java looks for a toString method for that object. This method must have no parameters and must return a String. If such a method has been defined for this object, it is called and the string it returns is printed. Otherwise the default toString method, which is inherited from the Object class, is called; it simply returns a unique hexadecimal identifier for the object such as the ones you saw above.


Add a toString method to your Student class that returns a string containing the student’s name and test scores, e.g.:


Name: Joe Test1: 85 Test2: 91


Note that the toString method does not call System.out.println—it just returns a string.


Recompile your Student class and the Grades program (you shouldn’t have to change the Grades program—you don’t have to call toString explicitly). Now see what happens when you print a student object—much nicer!


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


// Student.java


//


// Define a student class that stores name, score on test 1, and


// score on test 2. Methods prompt for and read in grades,


// compute the average, and return a string containing student's info.


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


import java.util.Scanner;


public class Student


{


//declare instance data


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


//constructor


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


public Student(String studentName)


{


//add body of constructor


}


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


//inputGrades: prompt for and read in student's grades for test1 & test2.


//Use name in prompts, e.g., "Enter's Joe's score for test1".


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


public void inputGrades()


{


//add body of inputGrades


}


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


//getAverage: compute and return the student's test average


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


//add header for getAverage


{


//add body of getAverage


}


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


//getName: print the student's name


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


//add header for printName


{


//add body of printName


}


}


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


// Grades.java


//


// Use Student class to get test grades for two students


// and compute averages


//


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


public class Grades


{


public static void main(String[] args)


{


Student student1 = new Student("Mary");


//create student2, "Mike"


//input grades for Mary


//print average for Mary


System.out.println();


//input grades for Mike


//print average for Mike


}


}


IV. Band Booster Class


In this exercise, you will write a class that models a band booster and use your class to update sales of band candy.


1. Write the BandBooster class assuming a band booster object is described by two pieces of instance data: name (a String) and boxesSold (an integer that represents the number of boxes of band candy the booster has sold in the band fundraiser).


The class should have the following methods:


· A constructor that has one parameter—a String containing the name of the band booster. The constructor should set boxesSold to 0.


· A method getName that returns the name of the band booster (it has no parameters).


· A method updateSales that takes a single integer parameter representing the number of additional boxes of candy sold. The method should add this number to boxesSold.


· A toString method that returns a string containing the name of the band booster and the number of boxes of candy sold in a format similar to the following:


Joe: 16 boxes


2. Write a program that uses BandBooster objects to track the sales of 2 band boosters over 3 weeks. Your program should do the following:


· Read in the names of the two band boosters and construct an object for each.


· Prompt for and read in the number of boxes sold by each booster for each of the three weeks. Your prompts should include the booster’s name as stored in the BandBooster object. For example,


Enter the number of boxes sold by Joe this week:


For each member, after reading in the weekly sales, invoke the updateSales method to update the total sales by that member.


· After reading the data, print the name and total sales for each member (you will implicitly use the toString method here).


V. Representing Names


1. Write a class Name that stores a person’s first, middle, and last names and provides the following methods:


· public Name(String first, String middle, String last)—constructor. The name should be stored in the case given; don’t convert to all upper or lower case.


· public String getFirst()—returns the first name


· public String getMiddle()—returns the middle name


· public String getLast()—returns the last name


· public String firstMiddleLast()—returns a string containing the person’s full name in order, e.g., “Mary Jane Smith”.


· public String lastFirstMiddle()—returns a string containing the person’s full name with the last name first followed by a comma, e.g., “Smith, Mary Jane”.


· public boolean equals(Name otherName)—returns true if this name is the same as otherName. Comparisons should not be case sensitive. (Hint: There is a String method equalsIgnoreCase that is just like the String method equals except it does not consider case in doing its comparison.)


· public String initials()—returns the person’s initials (a 3-character string). The initials should be all in upper case, regardless of what case the name was entered in. (Hint: Instead of using charAt, use the substring method of String to get a string containing only the first letter—then you can upcase this one-letter string. See Figure 3.1 in the text for a description of the substring method.)


· public int length()—returns the total number of characters in the full name, not including spaces.


2. Now write a program TestNames.java that prompts for and reads in two names from the user (you’ll need first, middle, and last for each), creates a Name object for each, and uses the methods of the Name class to do the following:


a. For each name, print


· first-middle-last version


· last-first-middle version


· initials


· length


b. Tell whether or not the names are the same.


Deliverables


1. Complete all the activities in sections II thru V in this lab; then zip all your Java SOURCE CODE FILES for submission.


2. Write a lab report in Word or PDF document. The report should be named lab3.docx or lab3.pdf and must contain the following:


a. The first page should be a cover page that includes the Class Number, Lab Activity Number, Date, and Instructor’s name.


b. Answer of all the questions in section I: Prelab Exercises. No code file is required here. All the code involved, if any, must be copied and pasted in this report.


c. Provide a 1-paragraph conclusion about your experience; how long you spent completing the lab, the challenges you faced, and what you learned.


3. Upload your lab report and the zip file of your source code to Blackboard. DO NOT SUBMIT separate source files. If you do, they will be ignored.

Homework is Completed By:

Writer Writer Name Amount Client Comments & Rating
Instant Homework Helper

ONLINE

Instant Homework Helper

$36

She helped me in last minute in a very reasonable price. She is a lifesaver, I got A+ grade in my homework, I will surely hire her again for my next assignments, Thumbs Up!

Order & Get This Solution Within 3 Hours in $25/Page

Custom Original Solution And Get A+ Grades

  • 100% Plagiarism Free
  • Proper APA/MLA/Harvard Referencing
  • Delivery in 3 Hours After Placing Order
  • Free Turnitin Report
  • Unlimited Revisions
  • Privacy Guaranteed

Order & Get This Solution Within 6 Hours in $20/Page

Custom Original Solution And Get A+ Grades

  • 100% Plagiarism Free
  • Proper APA/MLA/Harvard Referencing
  • Delivery in 6 Hours After Placing Order
  • Free Turnitin Report
  • Unlimited Revisions
  • Privacy Guaranteed

Order & Get This Solution Within 12 Hours in $15/Page

Custom Original Solution And Get A+ Grades

  • 100% Plagiarism Free
  • Proper APA/MLA/Harvard Referencing
  • Delivery in 12 Hours After Placing Order
  • Free Turnitin Report
  • Unlimited Revisions
  • Privacy Guaranteed

6 writers have sent their proposals to do this homework:

Helping Hand
University Coursework Help
Top Essay Tutor
Writer Writer Name Offer Chat
Helping Hand

ONLINE

Helping Hand

I am an Academic writer with 10 years of experience. As an Academic writer, my aim is to generate unique content without Plagiarism as per the client’s requirements.

$60 Chat With Writer
University Coursework Help

ONLINE

University Coursework Help

Hi dear, I am ready to do your homework in a reasonable price.

$62 Chat With Writer
Top Essay Tutor

ONLINE

Top Essay Tutor

I have more than 12 years of experience in managing online classes, exams, and quizzes on different websites like; Connect, McGraw-Hill, and Blackboard. I always provide a guarantee to my clients for their grades.

$65 Chat With Writer

Let our expert academic writers to help you in achieving a+ grades in your homework, assignment, quiz or exam.

Similar Homework Questions

Agrifarm utto mp specifications - Nojo original baby sling recall - Camping in bunyip state park - Kinetic depth effect demo - Respond to all 4 discussion boards - Unit 3 discussion board - Reaction of potassium iodide with silver nitrate - Psych k belief statements pdf - Cryptography - Books of prime entry in accounting pdf - You manage the intranet servers for eastsim corporation - Case study 3 - Methods of Neuroscience Investigation - Apple inc management information system - Marshall rosenberg book nonviolent communication - Safework sa codes of practice - Energy stored in magnetic field of inductor - Pounds per cubic feet to kilograms per cubic meter - Maya angelou i belong nowhere - The Role of risk factors in the outcome measures i patient diagnosed with Covid-19 - 3/67 elizabeth street malvern - C program to find inverse of a matrix - The armada portrait symbolism - Post mortem care documentation - Http faculty washington edu herronjc softwarefolder allelea1 html - Include but are not limited to - How using edi facilitates electronic transactions - Assume Texas has a long-arm statute permitting the exercise of jurisdiction over all parties to contracts negotiated and/or executed in Texas. How should the court rule? - Now we are seven - Ethics and Globalization - Studio mercantile himalayan salt crystal lamp instructions - Draw a lewis structure for co2 - Label each of the arrows in the following slide image - Mays and mccovey are beer brewing companies - Hi, is it possible to keep heat in the house thanks to window film ? - Petroleum engineering faculty position - Bus from mount gambier to adelaide - 300 words - One way anova apa style - Padi 5 point ascent - Discussion - Onomatopoeia worksheet 3 answers - Statistics for excel - Communication and cooperation skills - Discussion 1 ,250 words,add references and citations by 08/11/2020 at 6: 00 pm - Subatomic particle that flows through an electrical circuit - Microbiology power point - Ammonium biurate crystals dog - Philosophy - Working at heights swms template - Week 8 Assignment - What lie did captain beatty tell montag - Week 2 HR - Formal recommendation report template - Making action plans - Discussion: Working With Children and Adolescents Versus Adults week 2 - Myitlab access grader project - Rtl and gate level simulation - Gcu apa template - Global supply chain management simulation v2 - Archetypes in literature powerpoint - The scarborough corporation manufactures and sells two products - Adelaide's aria it's my wedding - Consultant's analysis report - Willington hall riding school - Which type of variance causes operating income to be greater than the budgeted operating income? - Guru Olivia Only - Baby animals and their mothers worksheet - Plum pudding atomic model - Help with web post and responses - Laura starrett attorney jacksonville - Reflect on the need to improve outcomes in healthcare - Procter and gamble sds - Let the carnival begin every pleasure every sin - The cruelest journey analyzing the text - Kraft peanut butter ingredients - Discussion - Ttps openstax org details books college physics - What other types of firewalls work best in conjunction with that type? Are there types that it does not work well with? - 3.2 1.9 packet tracer answers - Fed up video questions answers - Emf of dry cell battery - The reaction inside a chemical heat pack - Switching characteristics of power diode - 10 sub branches of science - Adobe analytics keyword unavailable - BE - Dis 3 - Packaging laws and regulations slideshare - Hana cloud integration pdf - Part of group work - Tangible user interface definition - Brandon van der kolk net worth - Concentration of acetic acid in vinegar titration - Termination phase of nurse client relationship - CCIS - Becoming Educated Part 2 - Linear regression - Blade cutting force calculation - Arguments for cell phones in school - Ion movements at resting potential mastering biology answers - Counter narrative essay examples