Untitled
unknown
java
a year ago
11 kB
13
Indexable
public class Course{
public String cName;
public String code;
public int credit;
public void createCourse(String a, String b, int c) {
cName = a;
code = b;
credit = c;
}
public void displayCourse() {
System.out.println("Course Name: " + cName + "\n" +
"Course Code: " + code + "\n" +
"Course Credit: " + credit);
}
public void updateCourse(String a, String b, int c) {
cName = a;
code = b;
credit = c;
}
}
public class Dog {
String name = "A dog";
String color;
public void changeName(String a) {
name = a;
}
public String bark() {
if (color == null || name.equals("White dog"))
{return name + " is barking";}
else {
return name + " the " + color + " dog is barking";
}
}
public void changeColor(String a) {
color = a;
if(name.equals("A dog")) {
name = a + " dog";
System.out.println("This dog is " + a);
}
else {
System.out.println(name + " is " + a);
}
}
}
public class Employee {
String name;
double salary = 30000.0;
String designation = "junior";
double tax = 0.0;
public void newEmployee(String a) {
name = a;
}
public void displayInfo() {
System.out.println("Employee Name: " + name + "\n" +
"Employee Salary: " + salary + "Tk" + "\n" +
"Employee Designation: " + designation);
}
public void calculateTax() {
if (salary > 50000.0) {
tax = salary * 0.30;
System.out.println(name + " Tax Amount: " + tax + " Tk");
} else if (salary > 30000) {
tax = salary * 0.10;
System.out.println(name + " Tax Amount: " + tax + " Tk");
}
else {
System.out.println("No need to pay tax");
}
}
public void promoteEmployee(String a) {
if(a.equals("senior")) {
salary+= 25000;
designation = a;
System.out.println(name + " has been promoted to " + designation);
System.out.println("New Salary: " + salary);
}
else if(a.equals("lead")) {
salary += 50000;
designation = a;
System.out.println(name + " has been promoted to " + designation);
System.out.println("New Salary: " + salary);
} else if(a.equals("manager")) {
salary += 75000;
designation = a;
System.out.println(name + " has been promoted to " + designation);
System.out.println("New Salary: " + salary);
}
}
}
public class Employee {
String name;
double salary = 30000.0;
String designation = "junior";
double tax = 0.0;
public void newEmployee(String a) {
name = a;
}
public void displayInfo() {
System.out.println("Employee Name: " + name + "\n" +
"Employee Salary: " + salary + "Tk" + "\n" +
"Employee Designation: " + designation);
}
public void calculateTax() {
if (salary > 50000.0) {
tax = salary * 0.30;
System.out.println(name + " Tax Amount: " + tax + " Tk");
} else if (salary > 30000) {
tax = salary * 0.10;
System.out.println(name + " Tax Amount: " + tax + " Tk");
}
else {
System.out.println("No need to pay tax");
}
}
public void promoteEmployee(String a) {
if(a.equals("senior")) {
salary+= 25000;
designation = a;
System.out.println(name + " has been promoted to " + designation);
System.out.println("New Salary: " + salary);
}
else if(a.equals("lead")) {
salary += 50000;
designation = a;
System.out.println(name + " has been promoted to " + designation);
System.out.println("New Salary: " + salary);
} else if(a.equals("manager")) {
salary += 75000;
designation = a;
System.out.println(name + " has been promoted to " + designation);
System.out.println("New Salary: " + salary);
}
}
}
public class MagicItem {
String name;
int level;
String[] magicitem = new String[3];
int count;
public void newCharacter(String a) {
name = a;
}
public void displayInfo() {
System.out.println("Character Name: " + name + "\n" +
"Energy Level: " + level + "\n" +
"Item 1: " + magicitem[0] + "\n" +
"Item 2: " + magicitem[1] + "\n" +
"Item 3: " + magicitem[2]);
}
public void findItem(String a) {
if(count < magicitem.length) {
magicitem[count++] = a;
System.out.println(name + " found a " + a);
} else {
System.out.println("All item slots occupied");
}
}
public void useItem(String a) {
boolean found = false;
for (int i = 0; i < magicitem.length; i++) {
if (magicitem[i] != null && magicitem[i].equals(a)) {
found = true;
if (a.equals("Potion")) {
level += 50;
} else if (a.equals("Elixir")) {
level += 100;
} else if (a.equals("Amulet")) {
level += 200;
}
System.out.println(name + " used a " + a);
System.out.println("Energy Level after using item: " + level);
magicitem[i] = null;
break;
}
}
if (!found) {
System.out.println("Item not in inventory.");
} else {
count = 0;
}
}
}
public class Cart {
int cartNum;
int count;
String[] item = new String[3];
double[] price = new double[3];
double sum;
double discount;
double subMoney;
public void create_cart(int a) {
cartNum = a;
}
public void addItem(String a, double b) {
if (count < 3) {
item[count] = a;
price[count] = b;
count++;
System.out.println(a + " added to cart " + cartNum);
System.out.println("You have " + count + " item(s) in your cart now.");
} else {
System.out.println("You already have 3 item(s) in your cart.");
}
}
public void cartDetails () {
System.out.println("Your cart " + "(c" + cartNum + "):");
for (int i = 0; i < 3; i++) {
if (item[i] != null) {System.out.println(item[i] + " - " + price[i]);}
sum += price[i];
} System.out.println("Discount Applied: " + discount + "%");
System.out.println("Total price: " + subMoney); }
public void giveDiscount(int a) {
discount = a;
subMoney = sum - (sum * a/100.0);
}
}
public class Reader {
String name;
int capacity;
String[] books;
int count;
public void createReader(String a, int b) {
name = a;
capacity = b;
books = new String[capacity];
}
public void readerInfo() {
System.out.println("Name: " + name);
System.out.println("Capacity: " + capacity);
System.out.println("Books: ");
if (count > 0) {
for (int i = 0; i < books.length; i++) {
if(books[i] != null) {
System.out.println("Book " + (i+1) + ": " + books[i]);}
}
} else {
System.out.println("No books added yet");
}
}
public void addBook (String a) {
if (count < books.length) {
books[count++] = a;
} else {
System.out.println("No more space for new book");
}
}
public void increaseCapacity(int a) {
String[] newBooks = new String[a];
for (int i = 0; i < count; i++) {
newBooks[i] = books[i];
}
books = newBooks;
capacity = a;
System.out.println(name + "'s capacity increased to " + capacity);
}
}
public class UberApp {
String name;
String phone;
int age;
int rides = 3;
double fare;
double newfare;
String[] visited = new String[3];
int count = 0;
public void createProfile(String a, int b, String c) {
name = a;
age = b;
phone = c;
}
public void showProfile() {
System.out.println("Hello! This is your Profile:");
System.out.println("Name: " + name + "\n" +
"Age: " + age + "\n" +
"Phone number: " + phone);
}
public int remainingRides() {
return rides;
}
public void bookRide(String a, double b) {
if (rides > 0) {
visited[count++] = a;
fare = 30 * b;
System.out.println(name + " has booked a ride!");
System.out.println("Destination: " + a);
System.out.println("Fare: " + fare + " Taka");
rides--;
} else {
System.out.println(name + " ,please update your plan to premium " +
"or wait till next month!");
}
}
public void changeLocation(String a, double b) {
visited[--count] = a;
fare = 30 * b;
newfare = fare + (0.2 * fare);
System.out.println(name + " has changed the destination of the current ride" +
" to " + a);
System.out.println("New fare after adding 20% charge");
System.out.println("Fare: " + newfare + " Taka");
}
public void ridingHistory() {
if (rides == 3) {
System.out.println(name + " , you haven't visited anywhere this month");
}
else {
System.out.print(name + " , you have visited ");
for(int i = 0; i < visited.length; i++) {
if(visited[i] != null) {
System.out.print(visited[i] + ", ");
}
}
System.out.println(" this month.");
}
}
public void resetMonth() {
rides = 3;
count = 0;
for (int i = 0; i < visited.length; i++) {
visited[i] = null;
}
}
}
Editor is loading...
Leave a Comment