This commit is contained in:
k0rrluna 2025-01-13 03:59:28 +03:00
parent a5b35aabb3
commit aea61f2076
14 changed files with 194 additions and 0 deletions

BIN
labs/lab5/Salary.class Normal file

Binary file not shown.

36
labs/lab5/Salary.java Normal file
View File

@ -0,0 +1,36 @@
// ***************************************************************
// Salary.java
// Computes the raise and new salary for an employee
// ***************************************************************
import java.util.Scanner;
public class Salary
{
public static void main (String[] args)
{
double currentSalary; // current annual salary
double rating; // performance rating
double raise = 0; // dollar amount of the raise
Scanner scan = new Scanner(System.in);
// Get the current salary and performance rating
System.out.print ("Enter the current salary: ");
currentSalary = scan.nextDouble();
System.out.print ("Enter the performance rating: ");
rating = scan.nextDouble();
// Compute the raise -- Use if ... else ...
if (rating == 1) {
raise = currentSalary * 0.06;
} else if (rating == 2) {
raise = currentSalary * 0.04;
} else if (rating == 3) {
raise = currentSalary * 0.015;
} else {
System.out.println("Rating not correctly entered!");
return;
}
// Print the results
System.out.println ("Amount of your raise: $" + raise);
System.out.println ("Your new salary: $" + (currentSalary + raise));
}
}

BIN
labs/lab7/Dog.class Normal file

Binary file not shown.

33
labs/lab7/Dog.java Normal file
View File

@ -0,0 +1,33 @@
// ****************************************************************
// Dog.java
//
// A class that holds a dog's name and can make it speak.
//
// ****************************************************************
public abstract class Dog
{
protected String name;
// ------------------------------------------------------------
// Constructor -- store name
// ------------------------------------------------------------
public Dog(String name)
{
this.name = name;
}
// ------------------------------------------------------------
// Returns the dog's name
// ------------------------------------------------------------
public String getName()
{
return name;
}
// ------------------------------------------------------------
// Returns a string with the dog's comments
// ------------------------------------------------------------
public String speak()
{
return "Woof";
}
public abstract int avgBreedWeight();
}

20
labs/lab7/DogTest.java Normal file
View File

@ -0,0 +1,20 @@
// ****************************************************************
// DogTest.java
//
// A simple test class that creates a Dog and makes it speak.
//
// ****************************************************************
public class DogTest
{
public static void main(String[] args)
{
Dog dog = new Yorkshire("Spike");
System.out.println(dog.getName() + " says " + dog.speak());
Dog Ydog = new Yorkshire("NotSpike");
System.out.println(Ydog.getName() + " says " + Ydog.speak());
Dog Ldog = new Labrador("NotSpike","Black");
System.out.println(Ldog.getName() + " says " + Ldog.speak() + " and weights: " + Ldog.avgBreedWeight());
}
}

BIN
labs/lab7/Labrador.class Normal file

Binary file not shown.

33
labs/lab7/Labrador.java Normal file
View File

@ -0,0 +1,33 @@
// ****************************************************************
// Labrador.java
//
// A class derived from Dog that holds information about
// a labrador retriever. Overrides Dog speak method and includes
// information about avg weight for this breed.
//
// ****************************************************************
public class Labrador extends Dog
{
private String color; //black, yellow, or chocolate?
private int breedWeight = 75;
public Labrador(String name, String color)
{
super(name);
this.color = color;
}
// ------------------------------------------------------------
// Big bark -- overrides speak method in Dog
// ------------------------------------------------------------
public String speak()
{
return "WOOF";
}
// ------------------------------------------------------------
// Returns weight
// ------------------------------------------------------------
public int avgBreedWeight()
{
return breedWeight;
}
}

BIN
labs/lab7/Yorkshire.class Normal file

Binary file not shown.

26
labs/lab7/Yorkshire.java Normal file
View File

@ -0,0 +1,26 @@
// ****************************************************************
// Yorkshire.java
//
// A class derived from Dog that holds information about
// a Yorkshire terrier. Overrides Dog speak method.
//
// ****************************************************************
public class Yorkshire extends Dog
{
private final int breedweight = 15;
public Yorkshire(String name)
{
super(name);
}
// ------------------------------------------------------------
// Small bark -- overrides speak method in Dog
// ------------------------------------------------------------
public String speak()
{
return "woof";
}
public int avgBreedWeight() {
return breedweight;
}
}

BIN
test/Cat.class Normal file

Binary file not shown.

27
test/Cat.java Normal file
View File

@ -0,0 +1,27 @@
public class Cat {
protected String name;
protected String color;
public Cat (String name, String color) {
this.name = name;
this.color = color;
}
public String getColor() {
return color;
}
public String getName() {
return name;
}
public void setName(String catName) {
name = catName;
}
public String catSays() {
return "Meow";
}
}

6
test/CatTest.java Normal file
View File

@ -0,0 +1,6 @@
public class CatTest {
public static void main(String[] args) {
Cat orangesmall = new Orange("Turuncu");
System.out.println(orangesmall.getColor()+" rengi ismi de: "+orangesmall.getName()+" ve kilosu: "+orangesmall.Weight());
}
}

BIN
test/Orange.class Normal file

Binary file not shown.

13
test/Orange.java Normal file
View File

@ -0,0 +1,13 @@
public class Orange extends Cat
{
private int weight = 5;
public Orange (String name) {
super(name, "Orange");
}
public int Weight() {
return weight;
}
}