gpt-3.5-turbo-0613· OpenAI
WildChat-4.8M (AI2)
Hi there give me codes I want to make a Reward earning app in java
- User
Hi there give me codes I want to make a Reward earning app in java
- Assistant
Hi there give me codes I want to make a Reward earning app in java
Sure! Here's an example code for a simple Reward earning app in Java:
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
public class RewardApp {
private static Scanner scanner = new Scanner(System.in);
private static Map<String, Integer> rewardsMap = new HashMap<>();
public static void main(String[] args) {
boolean running = true;
while (running) {
System.out.println("Reward Earning App Menu:");
System.out.println("1. Check Rewards");
System.out.println("2. Earn Rewards");
System.out.println("3. Redeem Rewards");
System.out.println("4. Exit");
int choice = getIntInput("Enter your choice:");
switch (choice) {
case 1:
checkRewards();
break;
case 2:
earnRewards();
break;
case 3:
redeemRewards();
break;
case 4:
running = false;
break;
default:
System.out.println("Invalid choice. Please try again.");
}
}
}
private static void checkRewards() {
String customerId = getStringInput("Enter Customer ID:");
if (rewardsMap.containsKey(customerId)) {
System.out.println("Rewards: " + rewardsMap.get(customerId));
} else {
System.out.println("No rewards found for the customer.");
}
}
private static void earnRewards() {
String customerId = getStringInput("Enter Customer ID:");
int rewardPoints = getIntInput("Enter Reward points:");
if (rewardsMap.containsKey(customerId)) {
rewardsMap.put(customerId, rewardsMap.get(customerId) + rewardPoints);
} else {
rewardsMap.put(customerId, rewardPoints);
}
System.out.println("Successfully earned " + rewardPoints + " rewards.");
}
private static void redeemRewards() {
String customerId = getStringInput("Enter Customer ID:");
int rewardPoints = getIntInput("Enter Reward points to redeem:");
if (rewardsMap.containsKey(customerId)) {
int currentRewards = rewardsMap.get(customerId);
if (currentRewards >= rewardPoints) {
rewardsMap.put(customerId, currentRewards - rewardPoints);
System.out.println(rewardPoints + " rewards redeemed successfully.");
} else {
System.out.println("Insufficient rewards.");
}
} else {
System.out.println("No rewards found for the customer.");
}
}
private static int getIntInput(String message) {
System.out.print(message);
int input = scanner.nextInt();
scanner.nextLine(); // Consume the newline character
return input;
}
private static String getStringInput(String message) {
System.out.print(message);
return scanner.nextLine();
}
}
The code above provides a simple menu-driven Reward Earning App. Users can choose options to check their rewards, earn rewards, redeem rewards, or exit the app. Customer rewards are stored in a Map with each customer having an associated reward point.
Not yet included in a published release.