Java Exercise 1


1).Problem Statement:

  Develop an application for a university course offering.  There are to be classes for textbook, instructor, and course.  This application should also have a driver class to test the other classes constructed.


Classes:

1.  Textbook:  this class is to have variables (fields) for isbn, title, and author(s).

   And, it should include a constructor, accessor and mutator methods for the fields,  as well as toString and equals methods.

2.  Instructor:  variables to include are firstName, lastName, department, and email. Define a constructor and methods as done for Textbook.

3.  Course:  this class is an aggregation of data which includes a primitive variable for courseTitle, and variables for textbook and instructor classes.  The Course constructor would initialize the primitive courseTitle and reference the textbook and instructor constructors to initialize fields for those classes.  Includ accessors and mutators and a toString method.


Driver or test program:

   The driver should offer the user choices to a) produce a course report or b) make comparisons of textbook title or instructor name between two courses.  For the report choice, the program should be capable of retrieving values associated with
 course objects then printing those details.  For comparisons, the program should allow the user to compare an instructor name or textbook title with those of another course.  Data for several textbook, instructor and course objects are to be obtained from a file.  For console input, include user prompts.  Include descriptive headings or labels to identify output data.


Solution:-  (program By Arun Prasath)


import java.io.*;

public class course {
public int Isbn;
 public String Title;
 public String Author;
 course()
 {
 
 }
 public course(int no,String tit,String Auth)
{
 this.Isbn=no;
 this.Title=tit;
 this.Author=Auth;
}

 public int getIsbn() {
return Isbn;
}
public void setIsbn(int isbn) {
Isbn = isbn;
}
public String getTitle() {
return Title;
}
public void setTitle(String title) {
Title = title;
}
public String getAuthor() {
return Author;
}
public void setAuthor(String author) {
Author = author;
}
}

public class instructor extends course{
String firstName;
String lastName;
String department;
String email;
instructor()
{
}
 public instructor(String fName,String lName,String depart,String emil)
{
this.firstName=fName;
this.lastName=lName;
this.department=depart;
this.email=emil;
}

public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public String getDepartment() {
return department;
}
public void setDepartment(String department) {
this.department = department;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}

}
import java.io.*;
public class textbook extends instructor {
public static void main(String args[])
{
course c = new course();
c.Isbn=123;
c.Title="java";
c.Author="bala";
System.out.println(c.getIsbn());
System.out.println(c.getTitle());
System.out.println(c.getAuthor());
instructor i = new instructor();
i.firstName="bala";
i.lastName="GURUSAMY";
i.department="java";
i.email="b@gmail.com";
System.out.println(i.getFirstName());
System.out.println(i.getLastName());
System.out.println(i.getDepartment());
System.out.println(i.getEmail());
System.out.println("--------------------------------------------------------------------------------------------");
System.out.println("Select which operation to be performed");
System.out.println("1)To get the Book title");
System.out.println("2)To get the Author Name");
InputStreamReader is = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(is);
try
{
String number = br.readLine();
int n= Integer.parseInt(number);
switch(n)
{
case 1: try
{
System.out.println("Enter the book name to get author name=");
String numbe = br.readLine();
if(numbe.equals(c.Title))
{
System.out.println(c.Author);
}
else
{
System.out.println("No Record Found");
}
}catch(Exception e)
{
System.out.println("Error");
}
break;
case 2:try
{
System.out.println("Enter the author name to get book name=");
String numb = br.readLine();
if(numb.equals(c.Author))
{
System.out.println(c.Title);
}
else
{
System.out.println("No Record Found");
}
}catch(Exception e)
{
System.out.println("Error");
}
}
}catch(Exception err)
{
System.out.println("Error");
}
}
}


*********************************************************************************************************************************
OUTPUT:
-------------
123
java
bala
bala
GURUSAMY
java
--------------------------------------------------------------------------------------------
Select which operation to be performed
1)To get the Book title
2)To get the Author Name
1
Enter the book name to get author name=
java
bala
2
Enter the author name to get book name=
bala
java

5 comments :

  1. Ѕіmply ԁesіrе to say your article iѕ as аmаzing.
    The clarіty on your ѕubmit is just ѕpectаculaг and i coulԁ assume you're an expert on this subject. Well along with your permission allow me to seize your feed to keep up to date with imminent post. Thanks one million and please keep up the rewarding work.
    Have a look at my blog - loans for bad credit

    ReplyDelete
  2. Do you minԁ if I quotе a cοuрle of your aгticlеs
    аѕ long as I prοѵidе credit and ѕouгсes bаck to your website?
    My ωebѕitе is in the ѵerу
    ѕаme area οf intеrest aѕ yours and mу visitorѕ wоuld certainly
    benеfit from a lot of the іnformation you рresеnt heгe.
    Please let me κnoω if thіs ok with yоu.
    Thank you!

    my blog рοst - bad credit loans

    ReplyDelete
  3. ӏ get pleasurе from, гesult
    in I discοvеred just what I used tο be taκing a looκ for.
    Үou've ended my four day lengthy hunt! God Bless you man. Have a nice day. Bye

    Feel free to surf to my webpage: bad credit payday loans
    My website: bad credit payday loans

    ReplyDelete
  4. Nice post. I was cheсking constantly this blog and Ι am imprеssed!

    Extremely helpful infοrmation spеcіfically the lаst pаrt :
    ) I care for such infο much. I was looking for thіѕ paгtiсulaг іnfo for a veгy long time.
    Thank уou and beѕt of luck.

    Here іs mу blog post short term loan
    my web page :: short term loan

    ReplyDelete
  5. wonderful for developing this app. about isbn, i have a little project called: retrieve data using isbn java. hope it will be helpful

    ReplyDelete

Copyright © Rough Record. Designed by OddThemes