Assignment2

This commit is contained in:
k0rrluna 2024-11-07 02:46:19 +03:00
parent cb2460ee46
commit 95ebce05ed
4 changed files with 50 additions and 28 deletions

Binary file not shown.

View File

@ -53,4 +53,26 @@ public class Dog {
return 24 + (humanYears - 2) * 5;
}
}
public static void main(String args[]) {
Dog dog1 = new Dog("Luna");
Dog dog2 = new Dog("Max");
Dog dog3 = new Dog("Ashley");
dog1.setAge(3);
dog1.setGender("F");
dog1.setBones(202);
dog2.setAge(4);
dog2.setGender("M");
dog2.setBones(204);
dog3.setAge(5);
dog3.setGender("F");
dog3.setBones(101);
System.out.println("Dog 1 is called " + dog1.getName());
System.out.println("Dog 2 has caught " + dog2.getBones() + " bones so far.");
System.out.println("Dog 3 is " + dog3.dogAgeAsPeopleYears(dog3.getAge()) + " years old in human years.");
System.out.println("Dog 1 gender: "+ dog1.getGender());
}
}

View File

@ -1,4 +1,4 @@
import java.util.*;
import java.util.Scanner;
public class histogram {

View File

@ -2,37 +2,37 @@ import java.util.*;
public class numbers {
public static void main(String args[]) {
ArrayList<Integer> ints = new ArrayList<Integer>();
Scanner scan = new Scanner(System.in);
System.out.println("Enter positive integer! (Enter -1 to stop!)");
ArrayList<Integer> ints = new ArrayList<Integer>();
Scanner scan = new Scanner(System.in);
System.out.println("Enter positive integer! (Enter -1 to stop!)");
int counter = 0;
double sum = 0;
double median = 0;
int counter = 0;
double sum = 0;
double median = 0;
while (true) {
int input1 = scan.nextInt();
if (input1 == -1) {
break;
} else if (input1 > 0) {
ints.add(input1);
sum += input1;
counter++;
} else {
System.out.println("Not Positive!");
}
}
//Collections.sort(ints);
for (int i = 0; i < counter - 1; i++) {
int minValue = i;
for (int j = i + 1; j < counter; j++) {
if (ints.get(j) < ints.get(minValue)) {
minValue = j;
while (true) {
int input1 = scan.nextInt();
if (input1 == -1) {
break;
} else if (input1 > 0) {
ints.add(input1);
sum += input1;
counter++;
} else {
System.out.println("Not Positive!");
}
}
int t = ints.get(i);
ints.set(i, ints.get(minValue));
ints.set(minValue, t);
//Collections.sort(ints);
for (int i = 0; i < counter - 1; i++) {
int minValue = i;
for (int j = i + 1; j < counter; j++) {
if (ints.get(j) < ints.get(minValue)) {
minValue = j;
}
}
int t = ints.get(i);
ints.set(i, ints.get(minValue));
ints.set(minValue, t);
}