lab 3

profilekhan08

TITLE: data type class, driver class – Rectangle and Calculator_SavingMoney

COURSE OBJECTIVES LEARNING OUTCOME

After finish the lab1 students should know:
[LO1]
-Declare variables, initialize values of primitive data types
-Apply math operators on numeric variables
-Write a java program with basic with comments and documentation

[LO5]
Analyze problems and design algorithms using pseudo-code, flowcharts, and structured charts, UML

[LO11]
-Can read input from the keyboard and from input files -Can write output to the screen and to the output files -display messages by using dialog box

LAB OBJECTIVES

  • Complete the lab on time (Time Management)
  • Write the pseudo-code
  • Create a new project, add source file to the project, compile and run the program without errors and
    qualified to the requirement
  • Display strings and numbers on the screen
  • Declare variables, assign values to int or string variables
  • Write the comment
  • Calculate the correct average of two numbers


HOW TO DO EACH PART
From now and on yourLastName will be changed to your last name

*Step1: Read the requirement of each part; write the pseudo-code in a word document by listing the step by step what you suppose to do in main() and then save it with the name as Lab1_pseudoCode_yourLastName

*Step2:
-start editor (for example eClipse) create the project→project name:

FA2019_LAB3PART1_yourLastName (part 1)

FA2019_LAB3PART2_yourLastName (part 2) -add a data type class

Class: Rectangle_yourLastName (part1)
Class: CDSavingAccount_yourLastName(Part2)

-add a driver class (file with extension .java) that contain main() Class: FA2019_DriverClassDemo_yourLastName (part1) Class: Calculator_SavingMoney_yourLastName (part2)

*Step3: read instruction in part 1 or part 2, create the UML of data type class and write the pseudo-code then follow UML to write the code of data type class and follow step by step in the pseudo-code to write the code of main() in the driver class

*Step:4 compile and run the program
*Step5: debug if there is any errors to complete the program –

LAB1 PART 1

FOR THE DATA TYPE CLASS:
In a word document, insert a table 1 column and 3 rows to create the UML of class Rectangle. Then copy the UML of class Rectangle given below (change Smith to your last name)

Note: UML is Unified Modeling Language, therefore, it has the syntax that you have to apply correctly
-in row 1: the name of the class will be set at CENTER with the first letter in uppercase: Rectangle_yourLastname -in row 2: list variables that describe an object of Rectangle: length (float) and width (float) and set them to private
-in row 3: list the heading of constructors, mutator methods, accessor methods, method area() to calculate the area of the rectangle obejct and method toString(). Set all of these to public.

Rectangle_Smith

page3image449981776

-length: double -width: double

page3image449987008

+Rectangle()
+Rectangle(len: float, w: float) +setLength(len: float): void +setWidth(w: float): void +getLength(): float +getWidth(): float
+area(): float
+toString(): String


Then write the code of data type class: Create the project, add the data type class to the projject, then add the code to the following data type class Rectangle_Smith (Change Smith to your last name)

public class Rectangle_Smith {

//add the code here }

-Type the following lines into the file Rectangle_yourLastName then answer 6 questions listed on each of the following parts below the UML in the above word document or as the comment line at each part in the class

//Question1: What is the name that we call the following lines in the data type class Rectangle_Smith? private float length;
private float width;

//Question2: What is the name that we call the following lines in the data type class Rectangle_Smith? public Rectangle()
{

length = 0.0f;

width = 0.0f; }

//Question3: What is the name that we call the following lines in the data type class Rectangle_Smith? public Rectangle(float len, float w)
{

length = len;

width = w; }

//Question4: What is the name that we call the following lines in the data type class Rectangle_Smith? public void setLength( float len)
{

length = len; }

//Question5: What is the name that we call the following lines in the data type class Rectangle_Smith? public float getLength()
{

return length; }

//Question6: What is the name that we call the following lines in the data type class Rectangle_Smith? public String toString()
{

return “RECTANGLE in FA2019_DriverClassDemo_Smith\n” + “Length = “ + length + “\n” +

“Width = “ + width ;

}

FOR THE DRIVER CLASS
Add to the project of part 1 the class with the name as FA2019_DriverClassDemo_yourLastName In the main() type the following lines of code (change Smith to your last name)


import java.util.Scanner;
public class FA2019_DriverClassDemo_Smith {

float length;
float width;
Scanner keyboard = new Scanner (System.in);

//read input
System.out.println(“Enter the length of a Rectangle: “; length = keyboard.nextFloat(); System.out.println(“Enter the width of a Rectangle: “; width = keyboard.nextFloat();

//create the obejct by call the constructor from the data type class Rectangle_Smith Rectangle_Smith object = new Rectangle_Smith( length, width );

//Display the output by calling method toString

System.out.println(object.toString()); }

REQUIREMENT
-You have to change Smith to your last name

-Add the file name as the first comment line at the top of each class
-Get the output of the part 1 then paste it in the word document of UML -write the comment on each part in both classes

COMPILE AND RUN THE PART1 TO GET THE OUTPUT

LAB2 - PART2

FOR THE DATA TYPE CLASS
The data type class CDSavingAccount_yourLastName contains customer name (String), amount of money to open CD saving account (float) and saving interest rate (float for example 0.49 for 0.49%), no-argument constructor, parameter constructor, metho to calculate the money get back after a year and the method toString to display the following output.
For example: if the name of the investor is Jame Smith, the money he put to his saving account is $12000.00 with the interest rate is 0.49% per year

Calculator_SavingMoney_SMITH.java – JAMES SMITH -------------------------------------------------------------------------- ----------------

Name of Bank Customer:
Amount of Money:
Interest Rate:
---------------------------------------------------------------------- -------------------- Total money at the end of year: 12058.80

The formula to calculate the money after a year is:
Total money after a year = amount of money + amount of money * interest rate

Mary Lane 12000.00

0.49%


FOR THE DRIVER CLASS:
-You should create the object of data type class CDSavingAccount_yourLastName to access the method toString()

to display the required output

Requrement:
*Change Smith to your last name
*Change JAMES SMITH to your full name
*Change Mary Lane to customer name entered from the keyboard
*write the file name as the first comment line at the top of program
*After running your program, get the picture of the output window from your program with your name on to paste at the bottom of the pseudo-code to turn in

HOW TO TURN IN THE LAB
You should turn in the following files:

Pseudo-code and the output pictures of both parts

(yourLastName should be your last name) Rectangle_yourLastName.java Rectangle_yourLastName.class FA2019_DriverClassDemo_yourLastName.java FA2019_DriverClassDemo_yourLastName.class

CDSavingAccount_yourLastName.java CDSavingAccount_yourLastName.class Calculator_SavingMoney_yourLastName.java Calculator_SavingMoney_yourLastName.class

IF YOU GET ANY PROBLEM TO SUBMIT FILEs .class YOU CAN COMPRESS ALL PROJECT INTO ONE FILE .zip or .rar TO UPLOAD TO eCampus


    • 5 years ago
    • 15
    Answer(0)