-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathSolutions.java
More file actions
145 lines (120 loc) · 3.63 KB
/
Solutions.java
File metadata and controls
145 lines (120 loc) · 3.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
package Example5;
import java.util.Arrays;
import java.util.Scanner;
class Car{
private String carName;
private String carColor;
private int carPrice;
private double carMilage;
public void setCarName(String carName){
this.carName = carName;
}
public String getCarName(){
return carName;
}
public String getCarColor() {
return carColor;
}
public void setCarColor(String carColor) {
this.carColor = carColor;
}
public int getCarPrice() {
return carPrice;
}
public void setCarPrice(int carPrice) {
this.carPrice = carPrice;
}
public double getCarMilage() {
return carMilage;
}
public void setCarMilage(double carMilage) {
this.carMilage = carMilage;
}
public void carInformation(){
System.out.println("Car Name : "+carName);
System.out.println("Car Price : "+carPrice);
System.out.println("Car Color : "+carColor);
System.out.println("Car Milege : "+carMilage);
}
}
class Student{
private String studentName;
private String studentDob;
private int age;
private String course;
private int marks;
public Student(){};
public Student (String name,String dob,int age,String course,int mark){
studentName = name;
studentDob = dob;
this.age = age;
this.course = course;
marks = mark;
}
public void displaySlip(){
System.out.println(studentName+"\n"+studentDob+"\n"+age+"\n"+course+"\n"+marks);
}
}
class Calculator{
public int addition(int num1,int num2){
return num1+num2;
}
public int subtract(int num1,int num2){
return num1-num2;
}
public int multiplay(int num1,int num2){
return num1 * num2;
}
public int div(int num1,int num2){
int res = -1;
if(num1>num2){
res = num1/num2;
}
return res;
}
}
public class Solutions {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
//Car Deatails
System.out.println("Enter the Car Details !");
Car car = new Car();
System.out.println("Enter the Car Name");
car.setCarName(scan.nextLine());
System.out.println("Enter the Car Price");
car.setCarPrice(scan.nextInt());
System.out.println("Enter the Car Milege");
car.setCarMilage(scan.nextDouble());
scan.nextLine();
System.out.println("Enter the Car Color");
car.setCarColor(scan.nextLine());
car.carInformation();
//Student Rejistration
Student student = new Student("ABCD","01/04/2003",12,"B.tech",85);
student.displaySlip();
// Calculator
Calculator calculator = new Calculator();
System.out.println("Enter the first Num:");
int num1 = scan.nextInt();
System.out.println("Enter the second NUmber");
int num2 = scan.nextInt();
System.out.println("Enter the sign Of Operation(Hint : +,-,*,/)");
char sign = scan.next().charAt(0);
switch (sign){
case '+':
System.out.println(calculator.addition(num1,num2));
break;
case '-':
System.out.println(calculator.subtract(num1,num2));
break;
case '*':
System.out.println(calculator.multiplay(num1,num2));
break;
case '/':
System.out.println(calculator.div(num1,num2));
break;
default:
System.out.println("Enter the valid Sign");
}
}
}