Skip to content

Commit e9840fa

Browse files
committed
updated
1 parent db3d4a8 commit e9840fa

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+957
-52
lines changed

README.md

+8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
11
# Application Programming in Java
22

33
Rustam Zokirov, 9.10.2020
4+
5+
## References:
6+
- Java full tutorial:
7+
- https://www.javatpoint.com/java-tutorial
8+
- Java OOPs:
9+
- https://www.javatpoint.com/java-oops-concepts
10+
- Java exceptions:
11+
- https://www.javatpoint.com/exception-handling-in-java

lab-00/ComputeArea.java

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
public class ComputeArea {
2+
public static void main(String[] args) {
3+
double radius; // Declare radius
4+
double area; // Declare area
5+
6+
// Assign a radius
7+
radius = 20; // New value is radius
8+
9+
// Compute area
10+
area = radius * radius * 3.14159;
11+
12+
// Display results
13+
System.out.println("The area for the circle of radius " +
14+
radius + " is " + area);
15+
}
16+
}
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import java.util.Scanner; // Scanner is in the java.util package
2+
3+
public class ComputeAreaWithConsoleInput
4+
{
5+
public static void main(String[] args)
6+
{
7+
// Create a Scanner object
8+
Scanner input = new Scanner(System.in);
9+
10+
// Prompt the user to enter a radius
11+
System.out.print("Enter a number for radius: ");
12+
double radius = input.nextDouble();
13+
14+
// Compute area
15+
double area = radius * radius * 3.14159;
16+
17+
// Display result
18+
System.out.println("The area for the circle of radius " +
19+
radius + " is " + area);
20+
}
21+
}

lab-00/DisplayUnicode.java

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import javax.swing.JOptionPane;
2+
3+
public class DisplayUnicode {
4+
public static void main(String[] args) {
5+
JOptionPane.showMessageDialog(null,
6+
"\u6B22\u8FCE \u03b1 \u03b2 \u03b3",
7+
"\u6B22\u8FCE Welcome",
8+
JOptionPane.INFORMATION_MESSAGE);
9+
}
10+
}

lab-00/FahrenheitToCelsius.java

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import java.util.Scanner;
2+
3+
public class FahrenheitToCelsius {
4+
public static void main(String[] args) {
5+
Scanner input = new Scanner(System.in);
6+
7+
System.out.print("Enter a degree in Fahrenheit: ");
8+
double fahrenheit = input.nextDouble();
9+
10+
// Convert Fahrenheit to Celsius
11+
double celsius = (5.0 / 9) * (fahrenheit - 32);
12+
System.out.println("Fahrenheit " + fahrenheit + " is " +
13+
celsius + " in Celsius");
14+
}
15+
}

lab-00/ShowCurrentTime.java

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
public class ShowCurrentTime
2+
{
3+
public static void main(String[] args) {
4+
// Obtain the total milliseconds since midnight, Jan 1, 1970
5+
long totalMilliseconds = System.currentTimeMillis();
6+
7+
// Obtain the total seconds since midnight, Jan 1, 1970
8+
long totalSeconds = totalMilliseconds / 1000;
9+
10+
// Compute the current second in the minute in the hour
11+
long currentSecond = (int)(totalSeconds % 60);
12+
13+
// Obtain the total minutes
14+
long totalMinutes = totalSeconds / 60;
15+
16+
// Compute the current minute in the hour
17+
long currentMinute = (int)(totalMinutes % 60);
18+
19+
// Obtain the total hours
20+
long totalHours = totalMinutes / 60;
21+
22+
// Compute the current hour
23+
long currentHour = (int)(totalHours % 24);
24+
25+
// Display results
26+
System.out.println("Current time is " + currentHour + ":"
27+
+ currentMinute + ":" + currentSecond + " GMT");
28+
}
29+
}

lab-00/UserInput.java

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// First Program
2+
import java.util.Scanner;
3+
4+
class UserInput{
5+
public static void main(String[] args) {
6+
Scanner id = new Scanner(System.in);
7+
System.out.print("Hello Rustam! Enter a word: ");
8+
System.out.println(id.nextLine());
9+
}
10+
}

lab-00/Welcome.java

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Java program to print text "Welcome to java!"
2+
3+
/*
4+
Student : Rustam
5+
Student Id : U1910000
6+
*/
7+
8+
public class Welcome
9+
{
10+
public static void main(String args[])
11+
{
12+
System.out.println("Welcome to Java!");
13+
}
14+
}

lab-01/01_-_Lab_Assignment_-_APJ.docx

12.6 KB
Binary file not shown.

week-02/BMI_U1910049.java lab-01/BMI.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import java.util.Scanner; // Import the Scanner class
1010

11-
class Main { // Create a class Main
11+
class BMI { // Create a class Main
1212
public static void main(String[] args) { // Create main() method
1313
Scanner input = new Scanner(System.in); // Create a Scanner object
1414

Binary file not shown.
File renamed without changes.
File renamed without changes.
Binary file not shown.

lab-03/MobileTest.java

+245
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,245 @@
1+
/*
2+
Rustam Zokirov, U1910049
3+
Lab Assignment #3
4+
*/
5+
6+
import java.util.Scanner; // import Scanner class
7+
8+
class Mobile { // Mobile class
9+
// attributes of class
10+
private String company, model; // model and company of phone
11+
private boolean isOn, hasCamera; // booleans isOn and hasCamera
12+
private int memory, volume; // volume from 0 to 10
13+
14+
public Mobile(){ // default constructor
15+
company = "Samsung";
16+
model = "Z Fold 2";
17+
isOn = true;
18+
hasCamera = true;
19+
memory = 512;
20+
volume = 10;
21+
} // End
22+
23+
public Mobile(String company,String model, boolean isOn, boolean hasCamera, int memory, int volume){ // parametrized constructor
24+
this.company = company;
25+
this.model = model;
26+
this.isOn = isOn;
27+
this.hasCamera = hasCamera;
28+
this.memory = memory;
29+
this.volume = volume;
30+
} // End
31+
32+
public void setCompany(String company){ // Setter for company
33+
this.company = company;
34+
}
35+
36+
public String getCompany(){ // Getter for company
37+
return company;
38+
}
39+
40+
public void setModel(String model){ // Setter for model
41+
this.model = model;
42+
}
43+
44+
public String getModel(){ // Getter for model
45+
return model;
46+
}
47+
48+
public void setIsOn(boolean isOn){ // Setter for isOn
49+
this.isOn = isOn;
50+
}
51+
52+
public boolean getIsOn(){ // Getter for isOn
53+
return isOn;
54+
}
55+
56+
public void setHasCamera(boolean hasCamera){ // Setter for hasCamera
57+
this.hasCamera = hasCamera;
58+
}
59+
60+
public boolean getHasCamera(){ // Getter for hasCamera
61+
return hasCamera;
62+
}
63+
64+
public void setMemory(int memory){ // Setter for volume
65+
this.memory = memory;
66+
}
67+
68+
public int getMemory(){ // Getter for volume
69+
return memory;
70+
}
71+
72+
public void setVolume(int volume){ // Setter for volume
73+
this.volume = volume;
74+
}
75+
76+
public int getVolume(){ // Getter for volume
77+
return volume;
78+
}
79+
80+
public void switchOn(){
81+
if (!isOn) // Validating for on, off
82+
setIsOn(true);
83+
else
84+
System.out.println("\nMobile phone is already switched on!");
85+
} // End
86+
87+
public void switchOff() {
88+
if (isOn) // Validating for on, off
89+
setIsOn(false);
90+
else
91+
System.out.println("\nMobile phone is already switched off");
92+
} // End
93+
94+
public void increaseVolume() {
95+
if (isOn && volume < 10) {// validating volume (0, 10) and on, off
96+
volume++; // increasing volume
97+
System.out.println("Volume is " + getVolume()); // outputting the volume
98+
}
99+
else if (!isOn)
100+
System.out.println("\nMobile phone is switched off!");
101+
else
102+
System.out.println("\nVolume is 10!");
103+
}// End
104+
105+
public void decreaseVolume() {
106+
if (isOn && volume >= 0) { // validating volume (0, 10) and on, off
107+
volume--; // decreasing volume
108+
System.out.println("Volume is " + getVolume()); // outputting the volume
109+
}
110+
else if (!isOn)
111+
System.out.println("\nMobile phone is switched off!");
112+
else
113+
System.out.println("\nVolume is 0!");
114+
} // End
115+
116+
public void setDetail() { // this function will set all the needed info for object
117+
Scanner input = new Scanner(System.in); // Create a Scanner object
118+
119+
System.out.println("\n***** Mobile phone details *****");
120+
121+
System.out.println("Company: ");
122+
String inputCompany = input.next();
123+
setCompany(inputCompany); // setting the company to inputCompany
124+
125+
System.out.println("\nModel: ");
126+
String inputModel = input.next();
127+
setModel(inputModel); // setting the model to inputModel
128+
129+
setIsOn(true); // phone is On
130+
131+
while(true){ // validating the input
132+
System.out.println("\nHas Camera? (1.Yes 2.No) ");
133+
int inputHasCamera= input.nextInt(); // taking the input
134+
if (inputHasCamera == 1) {
135+
setHasCamera(true); // setting the hasCamera
136+
break;
137+
}
138+
else if (inputHasCamera == 2) {
139+
setHasCamera(false); // setting the hasCamera
140+
break;
141+
}
142+
else{
143+
System.out.println("\nPlease enter values 1 or 2!");
144+
}
145+
}
146+
147+
while (true){ // validation the memory input
148+
System.out.println("\nMemory: ");
149+
int inputMemory = input.nextInt();
150+
151+
if(inputMemory > 0){
152+
setMemory(inputMemory);
153+
break;
154+
}
155+
else
156+
System.out.println("\nPlease enter correct values!");
157+
}
158+
159+
while (true) { // validating the volume
160+
System.out.println("\nVolume (0, 10): ");
161+
int inputVolume = input.nextInt();
162+
163+
if(inputVolume >= 0 && inputVolume <= 10){
164+
setVolume(inputVolume);
165+
break;
166+
}
167+
else
168+
System.out.println("\nPlease enter correct values!");
169+
} // End
170+
}
171+
172+
public void getDetail(){
173+
System.out.println("\n***** Mobile phone details *****");
174+
System.out.println("Company: " + getCompany());
175+
System.out.println("Model: " + getModel());
176+
System.out.println("On: " + getIsOn());
177+
System.out.println("Has Camera: " + getHasCamera());
178+
System.out.println("Memory: " + getMemory());
179+
System.out.println("Volume: " + getVolume());
180+
}
181+
} // End
182+
183+
public class MobileTest { // MobileTest class
184+
public static Scanner input = new Scanner(System.in); // Create a Scanner object
185+
186+
public static void main(String[] args){ // main method
187+
int option, isExit; // initializing some variables
188+
Mobile mobile = new Mobile(); // creating object of Mobile
189+
190+
do {
191+
option = showMenu(); // the option for switch
192+
switch (option){
193+
case 1:
194+
mobile.setDetail();
195+
break;
196+
case 2:
197+
mobile.getDetail();
198+
break;
199+
case 3:
200+
mobile.increaseVolume();
201+
break;
202+
case 4:
203+
mobile.decreaseVolume();
204+
break;
205+
case 5:
206+
mobile.switchOn();
207+
break;
208+
case 6:
209+
mobile.switchOff();
210+
break;
211+
case 0:
212+
System.out.println("Quitting Program...");
213+
System.exit(0); // program ends
214+
break;
215+
default:
216+
System.out.println("\nSorry, please enter valid option!");
217+
} // End of switch
218+
219+
System.out.println("\n----------------------------------------------------------------------------");
220+
System.out.println("Do you want to continue? (1.Yes 2.No)");
221+
isExit = input.nextInt(); // valid-on
222+
223+
} while(isExit == 1);
224+
225+
} // End of main
226+
227+
public static int showMenu() {
228+
int option = 0;
229+
// Printing menu to screen
230+
System.out.println("\n***** MAIN MENU *****");
231+
System.out.println("1. Set details");
232+
System.out.println("2. Get details");
233+
System.out.println("3. Increase volume");
234+
System.out.println("4. Decrease volume");
235+
System.out.println("5. Switch on");
236+
System.out.println("6. Switch off");
237+
System.out.println("0. Exit");
238+
239+
// Getting user option from above menu
240+
System.out.println("Your choice: ");
241+
option = input.nextInt();
242+
// re
243+
return option;
244+
} // End of showMenu
245+
} // End of class MobileTest
Binary file not shown.

0 commit comments

Comments
 (0)