Assignment 1
Assignment 1
Assignment 1
B.E–II
Instructor: IRFAN LATIF MEMON
Marks: 10 STUDENT NAME
Q[1]. (The Account class) Design a class named Account that contains:
A private int data field named id for the account (default 0).
A private double data field named balance for the account (default 0).
A private double data field named annualInterestRate that stores the current interest
rate (default 0). Assume all accounts have the same interest rate.
A private Date data field named dateCreated that stores the date when the account
was created.
A no-arg constructor that creates a default account.
A constructor that creates an account with the specified id and initial balance.
The accessor and mutator methods for id, balance, and annualInterestRate.
The accessor method for dateCreated.
A method named getMonthlyInterestRate() that returns the monthly interest rate.
A method named getMonthlyInterest() that returns the monthly interest.
A method named withdraw that withdraws a specified amount from the account.
A method named deposit that deposits a specified amount to the account.
Draw the UML diagram for the class and then implement the class.
(Hint: The method getMonthlyInterest() is to return monthly interest, not the interest
rate.
Monthly interest is balance * monthlyInterestRate. monthlyInterestRate is
annualInterestRate / 12. Note that annualInterestRate is a percentage, e.g., like
4.5%. You need to divide it by 100.)
Write a test program that creates an Account object with an account ID of 1122,
a balance of $20,000, and an annual interest rate of 4.5%. Use the withdraw method to
withdraw $2,500, use the deposit method to deposit $3,000, and print the balance, the
monthly interest, and the date when this account was created.
first day of the year and displays the calendar table for the year on the console. For
example, if the user entered the year 2013, and 2 for Tuesday, January 1, 2013,
your program should display the calendar for each month in the year, as follows:
CODE:
package calender;
import java.util.Scanner;
// Create Scanner
System.out.println("WELCOME TO MY CALENDER");
// Prompt the user to enter the year and first day of the year
String header;
System.out.println();
header = "";
System.out.print(" ");
System.out.println(
day %= 7;
for (int b = 0; b <= day * 7; b++) {
System.out.print(" ");
int lastDay = 0;
switch (month) {
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
lastDay += 31;
break;
case 4:
case 6:
case 9:
case 11:
lastDay += 30;
break;
default:
lastDay += 29;
else
lastDay += 28;
break;
}
if (d < 10)
System.out.print(" ");
if (day % 7 == 6)
else {
if (d == lastDay)
System.out.println();
System.out.println();
}
Q[2]. Case Study: Class GradeBook Using a Two- Dimensional
Array
In most semesters, students take several exams. Professors are likely to want to
analyze grades across the entire semester, both for a single student and for the class as
a whole.
GradeBookclass that uses a two-dimensional array grades to store the grades of a number
of students on multiple exams.
Each row of the array represents a single student’s grades for the entire course, and
each column represents the grades of all the students who took a particular exam.
Class GradeBookTest passes the array as an argument to the GradeBook constructor. In this
example, we use a ten-by-three array for ten students’ grades on three exams.
Five methods perform array manipulations to process the grades. Each method is
similar to its counterpart in the earlier one-dimensional array version of GradeBook.
Method getMinimum determines the lowest grade of any student for the semester.
Method getMaximum determines the highest grade of any student for the semester.
Method getAverage determines a particular student’s semester average.
Method outputBarChart outputs a grade bar chart for the entire semester’s student grades.
Method outputGrades outputs the array in a tabular format, along with each student’s
semester average.
return courseName;
System.out.println("");
outputBarChart();
lowGrade = grade;
highGrade = grade;
total += grade;
}
// return average of grades
++frequency[grade / 10];
// output bar label ( "00-09: ", ..., "90-99: ", "100: " )
if (count == 10) {
} else {
System.out.print("*");
}
System.out.println("");
System.out.printf("%8d", test);
System.out.printf("%9.2f", average);
/**
*/
return newline;
/**
*/
this.newline = newline;
myGradeBook.displayMessage();
myGradeBook.processGrades();
} // end main
(Cricket Match)To demonstrate the use of "loops" and "switch case", write a code of a crickte match.
Step 1: Do the toss between both teams and ask the toss winning team whether
they want to bat or bowl(use Switch Case).
Step 2: After toss the user should enter the number of overs.
Step 3: Use loop Structure to run the code over by over and make the code to seem like real time
match.
Step 4: Display the score board and results of the match.
Note: Use random function to take values like "Toss", "Runs", "extras" and "Wickets".
Sample Output