lisan
lisan
JCHJava Community | Help. Code. Learn.
Created by Milk Packet on 10/13/2024 in #java-help
How do I reduce Spring Boot's docker image size?
8 replies
JCHJava Community | Help. Code. Learn.
Created by Milk Packet on 10/13/2024 in #java-help
How do I reduce Spring Boot's docker image size?
8 replies
JCHJava Community | Help. Code. Learn.
Created by rachel_mccullough on 9/30/2024 in #java-help
/help ping
you have problem with bracelets
{}
{}
7 replies
JCHJava Community | Help. Code. Learn.
Created by rachel_mccullough on 9/30/2024 in #java-help
/help ping
public abstract class Pet {

private String name;
private int age;

public Pet(String name, int age) {
this.name = name;
this.age = age;
}

public abstract String speak();

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public int getAge() {
return age;
}

public void setAge(int age) {
this.age = age;
}

}


public class Cat extends Pet {

private CatBreed breed;

public Cat(String name, int age, CatBreed breed) {
super(name, age);
this.breed = breed;
}

@Override
public String speak() {
return "Meow! I am " + getName() + ", a " + getAge() + " year old " + breed;
}

public CatBreed getBreed() {
return breed;
}

public void setBreed(CatBreed breed) {
this.breed = breed;
}

}

public enum CatBreed {

PERSIAN,
TABBY

}

public class Dog extends Pet {

private DogBreed breed;

public Dog(String name, int age, DogBreed breed) {
super(name, age);
this.breed = breed;
}

@Override
public String speak() {
return "Woof! I am " + getName() + ", a " + getAge() + " year old " + breed;
}

public DogBreed getBreed() {
return breed;
}

public void setBreed(DogBreed breed) {
this.breed = breed;
}

}

public enum DogBreed {

SPANIEL,
TERRIER

}

public class Main {
public static void main(String[] args) {
Pet cat = new Cat("Pixel", 4, CatBreed.TABBY);
Pet dog = new Dog("Rex", 9, DogBreed.TERRIER);

System.out.println(cat.speak());
System.out.println(dog.speak());
}
}
public abstract class Pet {

private String name;
private int age;

public Pet(String name, int age) {
this.name = name;
this.age = age;
}

public abstract String speak();

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public int getAge() {
return age;
}

public void setAge(int age) {
this.age = age;
}

}


public class Cat extends Pet {

private CatBreed breed;

public Cat(String name, int age, CatBreed breed) {
super(name, age);
this.breed = breed;
}

@Override
public String speak() {
return "Meow! I am " + getName() + ", a " + getAge() + " year old " + breed;
}

public CatBreed getBreed() {
return breed;
}

public void setBreed(CatBreed breed) {
this.breed = breed;
}

}

public enum CatBreed {

PERSIAN,
TABBY

}

public class Dog extends Pet {

private DogBreed breed;

public Dog(String name, int age, DogBreed breed) {
super(name, age);
this.breed = breed;
}

@Override
public String speak() {
return "Woof! I am " + getName() + ", a " + getAge() + " year old " + breed;
}

public DogBreed getBreed() {
return breed;
}

public void setBreed(DogBreed breed) {
this.breed = breed;
}

}

public enum DogBreed {

SPANIEL,
TERRIER

}

public class Main {
public static void main(String[] args) {
Pet cat = new Cat("Pixel", 4, CatBreed.TABBY);
Pet dog = new Dog("Rex", 9, DogBreed.TERRIER);

System.out.println(cat.speak());
System.out.println(dog.speak());
}
}
7 replies
JCHJava Community | Help. Code. Learn.
Created by rainymc_ on 9/15/2024 in #java-help
No response.
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);

ArrayList<String> itemNames = new ArrayList<>();
ArrayList<Double> itemPrices = new ArrayList<>();

while (true) {
System.out.println("Please type in the name of the item you would like to purchase or finish: ");
String item = scanner.nextLine();
if (item.equals("finish")) {
break;
} else {
itemNames.add(item);
System.out.println("Please type in the price of the item: ");
Double price = scanner.nextDouble();
scanner.nextLine();
itemPrices.add(price);
}
}
System.out.println(itemNames);
System.out.println(itemPrices);

}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);

ArrayList<String> itemNames = new ArrayList<>();
ArrayList<Double> itemPrices = new ArrayList<>();

while (true) {
System.out.println("Please type in the name of the item you would like to purchase or finish: ");
String item = scanner.nextLine();
if (item.equals("finish")) {
break;
} else {
itemNames.add(item);
System.out.println("Please type in the price of the item: ");
Double price = scanner.nextDouble();
scanner.nextLine();
itemPrices.add(price);
}
}
System.out.println(itemNames);
System.out.println(itemPrices);

}
21 replies
JCHJava Community | Help. Code. Learn.
Created by rainymc_ on 9/15/2024 in #java-help
No response.
write this code here, on chat
21 replies
JCHJava Community | Help. Code. Learn.
Created by rainymc_ on 9/15/2024 in #java-help
No response.
u can even do while true, and if user wants to finish shopping he should write for example finish.
if (item.equals("finish")) break;
if (item.equals("finish")) break;
21 replies
JCHJava Community | Help. Code. Learn.
Created by rainymc_ on 9/15/2024 in #java-help
No response.
how do you want to take item if your itemNames has 0 elements so size is 0
21 replies