Java Lab3
Java Lab3
Java Lab3
*;
class Main
{
public static void main(String[] args) {
Scanner s=new Scanner(System.in);
int row=s.nextInt();
int col=s.nextInt();
int [][]a=new int[row][col];
for(int i=0;i<row;i++)
{
for(int j=0;j<col;j++)
{
a[i][j]=s.nextInt();
}
}
int n=s.nextInt();
Clock cl=new Clock();
Clock cc=new Clockwise();
Clock ac=new Anticlockwise();
int [][]b=new int[row][col];
for(int i=0;i<row;i++)
{
for(int j=0;j<col;j++)
{
b[i][j]=a[i][j];
}
}
Anticlockwise acw=new Anticlockwise();
for(int k=0;k<n;k++)
cc.rotate(row,col,a,n);
System.out.println("Clockwise ");
for (int i = 0; i < row; i++)
{
for (int j = 0; j < col; j++)
System.out.print( a[i][j] + " ");
System.out.print("\n");
}
System.out.println("Anti clockwise ");
int r=row;
int c=col;
int k=n;
int f,K;
int l = 0;
int m = 0;
int Row = r-1;
int Col = c-1;
while(l < Row && m < Col)
{
int rot = 2*(Row-l)+2*(Col-m);
f = n%rot;
for(int i=1;i<=f;i++)
{
ac.rotate(row,col,b,n);
acw.rotation(l,m,Row,Col,b);
}
l++;
m++;
Row--;
Col--;
}
for (int i = 0; i < row; i++)
{
for (int j = 0; j < col; j++)
System.out.print( b[i][j] + " ");
System.out.print("\n");
}
}
}
class Clock
{
public Clock()
{
}
void rotate(int row,int col,int a[][],int num)
{
}
}
class Clockwise extends Clock
{
static int R;
static int C;
}
}
class Anticlockwise extends Clock
{
void rotate(int m,int n,int mat[][],int num)
{}
void rotation(int l, int m, int Row, int Col,int mat[][])
{
int si,sj,i,j,t,f;
si = l;
sj = m;
t = mat[l][m];
for(i=l+1;i<=Row;i++)
{
f = mat[i][m];
mat[i][m] = t;
t = f;
}
l++;
for(i=m+1;i<=Col;i++)
{
f = mat[Row][i];
mat[Row][i] = t;
t = f;
}
m++;
if(l-1 < Row)
{
for(i=Row-1;i>=l-1;i--)
{
f = mat[i][Col];
mat[i][Col] = t;
t = f;
}
}
Col--;
if(m-1 < Col)
{
for(i=Col;i>=m;i--)
{
f = mat[l-1][i];
mat[l-1][i] = t;
t = f;
}
}
Row--;
mat[si][sj] = t;
return;
}
}
—------------------------------------------------
2.import java.io.*;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
class Event {
public String name;
public String detail;
public String type;
public String ownerName;
public Double costPerDay;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDetail() {
return detail;
}
public void setDetail(String detail) {
this.detail = detail;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getOwnerName() {
return ownerName;
}
public void setOwnerName(String ownerName) {
this.ownerName = ownerName;
}
public Double getCostPerDay() {
return costPerDay;
}
public void setCostPerDay(Double costPerDay) {
this.costPerDay = costPerDay;
}
}
public Exhibition() {
this.name = null;
this.detail = null;
this.type = null;
this.ownerName = null;
this.costPerDay = (double) 0;
this.noOfStall = 0;
}
public StageEvent() {
this.name = null;
this.detail = null;
this.type = null;
this.ownerName = null;
this.costPerDay = 0.0;
this.noOfSeats = 0;
}
double interest;
interest = (balance * 5 * (monthsDifference(startDate, dueDate)/12))/100;
return interest;
}
double interest;
interest = (balance * 12 * (monthsDifference(startDate, dueDate)/12))/100;
return interest;
}
class AccountsMain{
public static void main(String args[]) throws ParseException {
Scanner myObj = new Scanner(System.in);
int type=Integer.parseInt(myObj.nextLine());
String name = myObj.nextLine();
int number=Integer.parseInt(myObj.nextLine());
int balance= Integer.parseInt(myObj.nextLine());
if(type==1) {
SavingsAccount sObj = new SavingsAccount(name, number, balance,
startDate);
System.out.println(sObj.calculateInterest(dueDate));
}
else {
CurrentAccount cObj = new CurrentAccount(name, number, balance,
startDate);
System.out.println(cObj.calculateInterest(dueDate));
}
myObj.close();
}
}
—------------------------------------------
4.import java.io.*;
import java.util.*;
class Event {
protected String name;
protected String detail;
protected String type;
protected String organiserName;
public Event(String name, String detail, String type, String organiserName) {
this.name = name;
this.detail = detail;
this.type = type;
this.organiserName = organiserName;
}
public Event() {
this.name = null;
this.detail = null;
this.type = null;
this.organiserName = null;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDetail() {
return detail;
}
public void setDetail(String detail) {
this.detail = detail;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getOrganiserName() {
return organiserName;
}
public void setOrganiserName(String organiserName) {
this.organiserName = organiserName;
}
}
class Exhibition extends Event {
private int noOfStalls;
}
public Exhibition() {
super();
this.noOfStalls = 0;
}
public int getNoOfStalls() {
return noOfStalls;
}
—-----------------------------------------------------------
6.import java.util.Scanner;
class Person{
private String name;
private int birthYear;
double salCalc() {
return salary+(salary*(result/1000));
double ntsalCalc() {
return salary+(salary*(exp/100));
class PersonTester{
public static void main(String[] args){
if(choice ==1) {
String dept = myObj.nextLine();
double att =myObj.nextDouble();
Student b = new Student(name, byear, dept,att);
System.out.println(b);
}
else if(choice==2) {
String sub = myObj.nextLine();
double result =myObj.nextDouble();
double sal =myObj.nextDouble();
TeachingStaff ts = new TeachingStaff(name, byear, sal,sub,result);
System.out.println(ts);
}
else if(choice ==3) {
String lab = myObj.nextLine();
double exp =myObj.nextDouble();
double sal =myObj.nextDouble();
NonTeachingStaff nts = new NonTeachingStaff(name, byear, sal,lab,exp);
System.out.println(nts);
}
}
}
—--------------------------------------------
7.import java.io.*;
import java.util.*;
class Account {
protected String accountNumber;
protected double balance;
protected String accountHoldername;
public String getAccountNumber() {
return accountNumber;
}
public void setAccountNumber(String accountNumber) {
this.accountNumber = accountNumber;
}
public double getBalance() {
return balance;
}
public void setBalance(double balance) {
this.balance = balance;
}
public String getAccountHoldername() {
return accountHoldername;
}
public void setAccountHoldername(String accountHoldername) {
this.accountHoldername = accountHoldername;
}
}
class SavingAccount extends Account {
protected double minimumBalance;
}
}
—-----------------------------------------
8.import java.io.*;
import java.util.*;
import java.text.DecimalFormat;
class VISACard {
private String holderName;
private String ccv;
public Double computeRewardPoints(String purchaseType, Double amount) {
double dis = 0.01*amount;
return dis;
}
public String getHolderName() {
return holderName;
}
public void setHolderName(String holderName) {
this.holderName = holderName;
}
public String getCcv() {
return ccv;
}
public void setCcv(String ccv) {
this.ccv = ccv;
}
}
class HPVISACard extends VISACard {
public Double computeRewardPoints(String purchaseType, Double amount) {
double dis = super.computeRewardPoints(purchaseType, amount);
if(purchaseType.compareTo("fuel") == 0) {
return dis+10;
}
else {
return dis;
}
}
}
class Main {
public static void main(String [] args) {
VISACard v = new VISACard();
HPVISACard h = new HPVISACard();
DecimalFormat d = new DecimalFormat("0.0");
Scanner sc = new Scanner(System.in);
v.setHolderName(sc.nextLine());
v.setCcv(sc.nextLine());
Double amount = Double.parseDouble(sc.nextLine());
String type = sc.nextLine();
int n = Integer.parseInt(sc.nextLine());
if(n == 1) {
double res = v.computeRewardPoints(type, amount);
System.out.println(d.format(res));
}
if(n == 2) {
double res = h.computeRewardPoints(type, amount);
System.out.println(d.format(res));
}
if(n>2) {
System.out.println("Invalid Choice");
}
}
}
—--------------------------------------------------
9.public static void main(String s){
System.out.println("Overloaded: "+s);
}
void Print()
{
System.out.println("Dog");
}
}
void Print()
{
System.out.println("Cat");
}
}